-
Notifications
You must be signed in to change notification settings - Fork 15
/
cssreloader.content.js
67 lines (52 loc) · 1.76 KB
/
cssreloader.content.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
(function() {
var allSettings;
function initialize() {
document.addEventListener("keydown", onWindowKeyDown, false);
browser.runtime.onMessage.addListener(onExtensionMessage);
browser.runtime.sendMessage({'action' : 'getSettings'}, onGetSettings);
}
function reload() {
var elements = document.querySelectorAll('link[rel=stylesheet][href]');
for (var i = 0, element; element = elements[i]; i++) {
var href = element.href;
if (!domainIsBlacklisted(getDomain(href))) {
var href = href.replace(/[?&]cssReloader=([^&$]*)/,'');
element.href = href + (href.indexOf('?')>=0?'&':'?') + 'cssReloader=' + (new Date().valueOf());
}
}
}
function getDomain(url) {
return url.replace('http://','').replace('https://','').split('/')[0];
}
function domainIsBlacklisted(domain) {
for (var i=0;i<allSettings["blacklist"].length;i++) {
if (allSettings["blacklist"][i] == domain) {
return true;
}
}
return false;
}
function onGetSettings(settings) {
allSettings = settings;
}
function onWindowKeyDown(e) {
if (!allSettings) return;
if(e.key == allSettings["keyIdentifier"] &&
e.shiftKey === allSettings["shiftKeySelected"] &&
e.altKey === allSettings["altKeySelected"] &&
e.ctrlKey === allSettings["controlKeySelected"])
{
reload();
}
}
function onExtensionMessage(request, sender) {
if (request.action == "reload") {
reload();
}
}
CSSreloader = {
reload : reload,
initialize: initialize
};
CSSreloader.initialize();
})();