-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSSreloader.user.js
40 lines (31 loc) · 1.03 KB
/
CSSreloader.user.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
// ==UserScript==
// @name CSSreloader
// @namespace DuKaT
// @version 0.6
// @description That allows you to reload all the CSS files of any site or local HTML file without you have to reload the page itself. Just press F8.
// @author DuKaT
// @include file:///*
// @include http://*/*
// @include https://*/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/keyCode
const reloadKeyCode = 119; // F8
const CSSReloader = function() {
function reload() {
const reloader = 'cssreloader=' + Date.now();
[].forEach.call(document.querySelectorAll('link[rel="stylesheet"][href]'), function(element) {
const href = element.href.replace(/[\?\&]cssreloader=\d+$/, '');
element.href = href + (href.indexOf('?') === -1 ? '?' : '&') + reloader;
});
}
return { reload };
}();
document.addEventListener('keyup', (e) => {
if (e.keyCode === reloadKeyCode) {
CSSReloader.reload();
}
});
})();