-
Notifications
You must be signed in to change notification settings - Fork 0
/
min-overlay-socrollbars.js
75 lines (68 loc) · 1.97 KB
/
min-overlay-socrollbars.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
64
65
66
67
68
69
70
71
72
73
74
75
// ==UserScript==
// @name Overlay Scrollbars
// @match *
// @run-at document-start
// ==/UserScript==
// hide unditl Overlay Scrollbars is loaded
var style = document.createElement('style')
style.textContent = `
/* width */
::-webkit-scrollbar {
width: 0px;
height: 0px;
}
`
document.head.appendChild(style)
// include js
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = 'https://cdnjs.cloudflare.com/ajax/libs/overlayscrollbars/1.13.0/js/OverlayScrollbars.js';
document.head.appendChild(script);
// include css
document.head.insertAdjacentHTML('beforeend','<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/overlayscrollbars/1.13.0/css/OverlayScrollbars.css">');
// load OverlayScrollbars
// for some reason document.addEventListener("DOMContentLoaded", function() {}); does not work
// using setTimeout instead
// On error CSS scrollbars are applied
setTimeout(function(){
try {
var foo = function(){
console.log ("==> Loading OverlayScrollbars.", new Date() );
OverlayScrollbars(document.querySelectorAll("body"), { });
}();
}
catch(err) {
console.log ("Error, probaly due to Content Security Policy directive", new Date() );
console.log ("Using CSS scrollbars instead", new Date() );
var style = document.createElement('style')
style.textContent = `
html, body {
margin: 0;
padding: 0;
}
body {
overflow: overlay;
}
/* width */
::-webkit-scrollbar {
width: 10px;
height: 10px;
}
/* Track */
::-webkit-scrollbar-track {
background: transparent;
}
/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
visibility: hidden;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
visibility: visible;
}
`
document.head.appendChild(style)
}
}, 1000);