-
Notifications
You must be signed in to change notification settings - Fork 0
/
style.js
102 lines (90 loc) · 2.82 KB
/
style.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
/*
Constants
*/
const OCTOCORN_LOGO_URL = "https://raw.githubusercontent.com/Alex-Octocorn/logo/main/octocorn_logo.svg"
const STYLESHEET_URL = "https://raw.githubusercontent.com/Alex-Octocorn/logo/main/style.css"
const LINUX_BUTTONS_URL = "https://raw.githubusercontent.com/Alex-Octocorn/logo/main/linuxButtons.svg"
/*
HTML elements
*/
const head = document.querySelector('head');
const octocornLogo = document.createElement('div');
const linuxButtons = document.createElement('div');
/**
* Adds CSS to the page and add classes to the elements
*/
function injectCss() {
const customCss = document.createElement('style');
customCss.type = 'text/css';
fetch(STYLESHEET_URL)
.then(css => css.text())
.then((css) => {
customCss.appendChild(document.createTextNode(css));
head.appendChild(customCss);
}
)
octocornLogo.classList.add('bottom-left-logo');
linuxButtons.classList.add('linux-buttons');
}
/**
* Fetches the Linux buttons SVG and adds it to the page
*/
function addLinuxButtons() {
fetch(LINUX_BUTTONS_URL)
.then(linuxButtonsSvg => linuxButtonsSvg.text())
.then((linuxButtonsSvg) => {
linuxButtons.innerHTML = linuxButtonsSvg;
}
)
}
/**
* Adds favicon to the page
*/
function addFavIcon() {
const favIcon = document.createElement('link');
favIcon.type = 'image/x-icon';
favIcon.rel = 'shortcut icon';
favIcon.href = OCTOCORN_LOGO_URL;
head.appendChild(favIcon);
}
/**
* Adds background-image class to the each slide
*/
function appendBackgroundClassToSlides() {
const backgrounds = document.getElementsByClassName('slide-background-content');
for (let i = 0; i < backgrounds.length; i++) {
backgrounds[i].classList.add('background-image');
}
}
/**
* Changes the default PDF background color to match the style
*/
function appendStyleAndLogosToPdfSlides() {
const backgrounds = document.getElementsByClassName('pdf-page');
for (let i = 0; i < backgrounds.length; i++) {
backgrounds[i].style.backgroundColor = 'var(--r-background-color)';
backgrounds[i].appendChild(octocornLogo.cloneNode(true));
backgrounds[i].appendChild(linuxButtons.cloneNode(true));
}
}
/**
* Adds icons to the page
*/
function appendLogos() {
const application = document.querySelector('[role="application"]');
application.appendChild(octocornLogo);
application.appendChild(linuxButtons);
}
addLinuxButtons();
/**
* Main function
* We need to wait for the page to load before we can interact with it
* The LinuxButton needs to be added to the page before we can append it to the PDF slides
*/
setTimeout(() => {
injectCss();
addFavIcon();
appendBackgroundClassToSlides();
appendStyleAndLogosToPdfSlides();
appendLogos();
}, 1000)