Skip to content

Commit 53a42d5

Browse files
committed
no innerHTML but rules in <style>
1 parent 792d54f commit 53a42d5

4 files changed

Lines changed: 19 additions & 9 deletions

File tree

dest/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "CSS Used",
3-
"version": "2.3.2",
3+
"version": "2.3.3",
44
"permissions": ["<all_urls>","tabs"],
55
"author": "Bob",
66
"icons": {

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "css-used-chrome-ext",
3-
"version": "2.2.11",
3+
"version": "2.3.3",
44
"description": "A chrome extension to get all css rules used by the selected DOM and its children.",
55
"main": "./src/main.js",
66
"scripts": {

src/generateRulesAll.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,20 @@ function generateRulesAll(doc, externalCssCache) {
2828
})
2929
} else {
3030
// style tag
31+
let html=doc.styleSheets[x].ownerNode.innerHTML;
32+
if(html===''){
33+
// style may be in style-tag's cssRules but not show in innerHTML
34+
for (let index = 0; index < doc.styleSheets[x].cssRules.length; index++) {
35+
const rule = doc.styleSheets[x].cssRules[index];
36+
html+=rule.cssText;
37+
}
38+
}
3139
// convert urls in style tag to abs
32-
let html = doc.styleSheets[x].ownerNode.innerHTML.replace(/url\((['"]?)(.*?)\1\)/g, function (a, p1, p2) {
40+
html = html.replace(/url\((['"]?)(.*?)\1\)/g, function (a, p1, p2) {
3341
return 'url(' + convUrlToAbs(doc.location.href, p2) + ')';
3442
});
43+
// the next operation is asynchronous
44+
// store the current x value
3545
let _x = x;
3646
convTextToRules(html, doc.location.href).then(function (cssNodeArr) {
3747
cssNodeArr.media = doc.styleSheets[_x].media;

0 commit comments

Comments
 (0)