-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
110 lines (90 loc) · 4.14 KB
/
main.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
let bgColor = window.getComputedStyle(document.body, null)
.getPropertyValue('background-color').replace(/\s/g, '')
let rgbColor = bgColor.split("(")[1].split(")")[0]
rgbColor = rgbColor.split(",")
let numbertoHex = rgbColor.map((x) => {
x = parseInt(x).toString(16)
return (x.length==1) ? "0"+x : x
})
numbertoHex = "#"+numbertoHex.join("")
let nib = numbertoHex.split('')
let r = parseInt(nib[1]+nib[2],16)
let g = parseInt(nib[3]+nib[4],16)
let b = parseInt(nib[5]+nib[6],16)
let brightness = ( r * 299 + g * 587 + b * 114) / 1000
console.log(brightness)
const html = document.getElementsByTagName('html')[0]
const getAtributes = html.attributes
let hasDarkAttribute;
for (i = 0; i < getAtributes.length; i++) {
if (getAtributes[i].nodeName.match('dark')
|| getAtributes[i].value.match('dark')) {
hasDarkAttribute = true
}
}
const classException = document.body
const classExceptionList = ['error-body']
let hasClassException
for (i = 0; i < classException.classList.length; i++) {
if (classException.classList[i].includes(classExceptionList)) {
hasClassException = true
}
}
const exceptionsList = ["ephy-about:", "ephy-reader:", "www.reddit.com/", "app.element.io", "www.twitch.tv", "twitter.com", "geeksforgeeks.org"]
const noExceptionsList = ["www.phoronix.com"]
function isException(site) {return window.location.href.includes(site)}
if ((brightness > 128 || brightness === 0) || noExceptionsList.find(isException) !== undefined) {
if (hasClassException == undefined) {
if (hasDarkAttribute == undefined) {
if (exceptionsList.find(isException) === undefined) {
// emojis
// document.getElementsByTagName('*').forEach((i)=>{
// if ((/\p{Emoji}/u.test(i.innerText))) {
// i.style.filter = 'invert(1) contrast(0.95) saturate(0.5) hue-rotate(180deg)'
// }
// })
html.style.filter = 'invert(1) hue-rotate(180deg)'
// Select all elements with css background image
var tags = document.getElementsByTagName('*'),
el;
for (var i = 0, len = tags.length; i < len; i++) {
el = tags[i];
if (el.currentStyle) {
if( el.currentStyle['backgroundImage'] !== 'none' )
el.style = 'filter: invert(1) hue-rotate(180deg)'
console.log('é o if')
}
else if (window.getComputedStyle) {
if( document.defaultView.getComputedStyle(el, null).getPropertyValue('background-image') !== 'none' )
el.style = 'filter: invert(1) hue-rotate(180deg)'
console.log('é o else if')
}
}
const style = document.createElement('style');
document.head.appendChild(style);
// insert CSS Rule
style.sheet.insertRule(`
img, video, iframe, [role=img]:not(svg) {
filter: invert(1) hue-rotate(180deg) !important;
svg {
filter: invert(1) hue-rotate(180deg) !important;
}
header {
filter: invert(1) hue-rotate(180deg) !important;
}
header > img {
filter: invert(1) hue-rotate(180deg) !important;
}
[role=article] {
filter: invert(1) hue-rotate(180deg) !important;
}
// specifics websites
// w3 schools
w3-code {
filter: invert(1) hue-rotate(180deg);
}
`);
}
}
}
}