Checking .css table name with javascript / jquery

I am trying to make a small chrome extension for a forum, but I want it to work in a specific area of ​​the forum.

The problem is that I can’t just "match": ["subforum"], because the threads in this forum do not distinguish which subforum they are at the URL.

The sub-forum has its own CSS stylesheet, so I think that if I can quickly check if the current subforum.css stylesheet matches, it will work fine.

Basically, I just need to check the name of the stylesheet, and if this is not possible, then how can I accurately check whether the current stylesheet contains some word or element or something like that.

+3
source share
2

:

if ($('link[href*="myStylesheet.css"]').length) {
    //stylesheet containing "myStylesheet.css" in the href attribute was found
} else {
    //not found
}

Fiddle

, , .

if ($('link[href="path/To/myStylesheet.css"]').length) {
    //stylesheet with link="myStylesheet.css" found, do stuff
}

Fiddle

0

@import

function sheetExists(name){
    var s = document.styleSheets, i = s.length, j = 0;
    while(i-->0){
        if(s[i].href !== null){
            if(s[i].href.indexOf(name) !== -1) return true;
        }
        while(j < s[i].cssRules.length && s[i].cssRules[j].type === 3){
            if(s[i].cssRules[j].href !== null){
                if(s[i].cssRules[j].href.indexOf(name) !== -1) return true;
            }
            j++;
        }
        j = 0;
    }
    return false;
}
sheetExists('subforum.css');
+1

All Articles