-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss_images.html
49 lines (48 loc) · 2.21 KB
/
css_images.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<h1> Drag the following bookmarklet to your bookmarks bar </h1>
<h2>
<a id="bookmarklet" href="#">CSS Images</a>
- displays images referenced in CSS files
</h2>
Note: Does not work if CSS files are loaded from another domain.
Note: jQuery must be available.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
function o() {
// 2013 byterider
$("body").html("<table/>");
var count = 1, i = 0, j = 0, urls = [], url, sheet, rule, img, cell1, cell2, $table = $("table");
$table.css({"font-size": "13px", "background": "#999", "color":"#eee"});
while (sheet = document.styleSheets[i]) {
if (window.console) console.log(sheet.href);
while (sheet.cssRules && (rule = sheet.cssRules[j])) {
// when trying to read a stylesheet loaded from a different domain, you get no cssRules
if (rule.style && rule.style.cssText) {
var m = rule.style.cssText.match(/url\((.*?)\)/);
if (m) {
url = m[1].replace(location.origin, ""); // make server relative
if (!urls[url]) {
if (window.console) console.log(url);
urls[url] = 1;
img = $("<img/>")
.attr("src", url)
.attr("title", url)
.css({"border": "1px dotted #333", "max-width": "80%", "display": "block", "margin": "5px"});
cell1 = $("<td/>").append(count);
cell2 = $("<td/>").append(img);
row = $("<tr/>").append(cell1).append(cell2);
$table.append(row);
count += 1;
}
}
}
j += 1;
}
i += 1;
}
}
var f = "" + window.o;
document.getElementById("bookmarklet").href =
"javascript:" + f.slice(f.indexOf("{") + 1, f.lastIndexOf("}"))
.replace(/\/\/.*/g, "") // remove comments
.replace(/\s+/g, " "); // remove line breaks
</script>