This repository has been archived by the owner on Jan 19, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.js
56 lines (50 loc) · 2.87 KB
/
build.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
const fs = require('fs')
const styles = fs.readFileSync('./styles/styles.css', { encoding: 'utf8' })
const release = `// The entrance of the extension, will run when \`document\` is ready
// The anonymous function: \`( (params) => {} )(params)\`
((darkModeIsOn) => {
if (darkModeIsOn) {
// The local variables, only available in this anonymous function, so that it won't affect the operation of other scripts.
var body = document.body;
var style = document.createElement('style');
// Set \`style.innerHTML\` to the compressed [CSS](../styles/styles.css).
style.innerHTML = \`${styles}\`;
// Append to <body>
body.appendChild(style);
// If at Explore page
if (window.location.href.match('https://github.com/explore*') || window.location.href.match('https://github.com/topics*')) {
// Select the white background and replace it
document.querySelector(".border-bottom.border-gray-light").setAttribute("style", "");
// Set \`explorePageTopicsGradientMaskSelector\` to the selector of the recommandation list
var explorePageTopicsGradientMaskSelector = '[style="background: linear-gradient(to top, rgba(255,255,255,1), rgba(255,255,255,0));"]';
// Edit its mask then
for (
let ele = document.querySelector(explorePageTopicsGradientMaskSelector);
document.querySelector(explorePageTopicsGradientMaskSelector);
ele = document.querySelector(explorePageTopicsGradientMaskSelector)
) {
ele.style.background = "linear-gradient(to top, rgb(31 35 39), rgb(31 35 39 / 0))"
}
// If on topic page
if (window.location.href.match('https://github.com/topics*')) {
document.querySelector('[style="background-color: #fcfdfd;"]').style.backgroundColor = '#1F2327';
}
}
// If at Sponsors page
if (window.location.href.match('https://github.com/sponsors*')) {
// Select the gradient cover and replace it
document.querySelector('[style="height: 100%; background: linear-gradient(to bottom, rgba(246,248,250,0.5) 0%,rgba(246,248,250,1) 100%);"]').setAttribute("style", "height: 100%; background: linear-gradient(to bottom, rgba(31, 35, 39, 0.5) 0%,rgba(31, 35, 39, 1) 100%);");
}
console.log('GitHub Dark Mode initialized')
} else {
console.log("GitHub Dark Mode is off because your browser isn't in dark mode")
}
})((() => {
if (window.matchMedia('(prefers-color-scheme)').media == 'not all') {
console.log("GitHub Dark Mode didn't launch because your browser doesn't support dark mode");
return false
} else {
return window.matchMedia('(prefers-color-scheme: dark)').matches
}
})());`
fs.writeFileSync('./js/index.js', release, { encoding: 'utf8' })