-
Notifications
You must be signed in to change notification settings - Fork 34
/
styleswitcher.js
214 lines (197 loc) · 6 KB
/
styleswitcher.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
function scroller(id) {
document.getElementById(id).scrollIntoView();
}
function setActiveStyleSheet(title) {
var i, a, main;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
a.disabled = true;
if(a.getAttribute("title") == title) a.disabled = false;
}
}
}
function getActiveStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
}
return null;
}
function getPreferredStyleSheet() {
var i, a;
for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
if(a.getAttribute("rel").indexOf("style") != -1
&& a.getAttribute("rel").indexOf("alt") == -1
&& a.getAttribute("title")
) return a.getAttribute("title");
}
return null;
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return null;
}
function includeHTML() {
var z, i, elmnt, file, xhttp;
/* Loop through a collection of all HTML elements: */
z = document.getElementsByTagName("*");
for (i = 0; i < z.length; i++) {
elmnt = z[i];
/*search for elements with a certain atrribute:*/
file = elmnt.getAttribute("w3-include-html");
if (file) {
/* Make an HTTP request using the attribute value as the file name: */
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4) {
if (this.status == 200) {elmnt.innerHTML = this.responseText;}
if (this.status == 404) {elmnt.innerHTML = "Page not found.";}
/* Remove the attribute, and call this function once more: */
elmnt.removeAttribute("w3-include-html");
includeHTML();
}
}
xhttp.open("GET", file, true);
xhttp.send();
if (typeof this.activeLink == 'undefined' || !this.activeLink) {
this.activeLink = setActiveNavLink(window.location.pathname);
}
/* Exit the function: */
return;
}
}
}
function backToTop() {
if (window.pageYOffset > 0) {
window.scrollBy(0, -80);
setTimeout(backToTop, 0);
}
}
function trackScroll() {
if (typeof this.topBtn == 'undefined') {
this.topBtn = document.querySelector('.scroll-to-top');
this.topBtn.addEventListener('click', backToTop);
}
if (this.topBtn != null) {
var scrolled = window.pageYOffset;
var coords = document.documentElement.clientHeight;
if (scrolled > coords) {
this.topBtn.classList.add('scroll-to-top-show');
} else {
this.topBtn.classList.remove('scroll-to-top-show');
}
}
}
function setActiveNavLink(url) {
var linkContainer = document.querySelectorAll('.navbar-link');
let i = linkContainer.length;
if (i == 0) return false;
while (--i > 0) {
var h = linkContainer[i].getAttribute("href");
if (h == null || !h.match(".html")) continue;
if (url.match(h.split(".")[0])) break;
}
linkContainer[i].firstChild.classList.add('active');
return true;
}
function loadScript(url, callback) {
var script = document.createElement("script");
script.src = url;
script.async = true;
if (callback && typeof callback == "function") {
if (script.readyState) { // IE
script.onreadystatechange = function() {
if (script.readyState == "loaded" || script.readyState == "complete") {
script.onreadystatechange = null;
callback();
}
};
} else { // Others
script.onload = callback;
}
}
document.head.appendChild(script);
}
loadScript("https://www.googletagmanager.com/gtag/js?id=UA-10249025-10");
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-10249025-10');
function refreshTag(id, refresh_time, interval, callback) {
var timeout;
var tag = document.getElementById(id);
if (tag == null) {
timeout = 500;
} else {
timeout = interval * 1000;
callback(tag);
}
if (--refresh_time > 0) {
setTimeout(function() {
refreshTag(id, refresh_time, interval, callback);
}, timeout);
}
}
function showRunative(id) {
loadScript("https://cdn.runative-syndicate.com/sdk/v1/n.js", function() {
refreshTag(id, 5, 35, function(unused) {
NativeAd({
element_id: id,
spot: "72719163e1c349e3afd19fa5260783ff",
type: "label-under",
cols: 4,
rows: 1,
title: "",
titlePosition: "left",
adsByPosition: "right",
breakpoints: [{
"cols": 2,
"width": 770
}],
styles: {
"headlineLink": {
"color": "#333",
":hover": {
"color": "#2e81d5"
},
"font-size": "14px",
"font-weight": "bold"
},
"brandnameLink": {
"font-size": "10px"
}
}
});
});
});
}
window.onload = function(e) {
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);
window.addEventListener('scroll', trackScroll);
if (window.location.pathname != "" && window.location.pathname != "/" && window.location.pathname != "/index.html")
loadScript("https://powerad.ai/script.js");
}
window.onunload = function(e) {
var title = getActiveStyleSheet();
createCookie("style", title, 365);
}
var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
setActiveStyleSheet(title);