-
Notifications
You must be signed in to change notification settings - Fork 2
/
picoman.php
285 lines (253 loc) · 10.4 KB
/
picoman.php
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
<script>
/*!
* PicoMan v1.1.2 (https://picoman-theme.blogspot.com)
* email: [email protected] telegram: @mamans86
* feel free to modify but please keep link to my blog always visible and reachable, and also please don't remove this comment block
* contact me if you want to make donation
* TCExam Mobile First Design Theme based on Pico.css (https://picocss.com), built with love by Maman Sulaeman - @mamans86
* eye & flag icon generated by icomoon.io
*/
function setDataTheme(a){localStorage.setItem('dataTheme',a)}
var dataTheme = localStorage.getItem('dataTheme');
if(!dataTheme){
localStorage.setItem('dataTheme','light');
document.querySelector("html").setAttribute("data-theme","light");
}else{
document.querySelector("html").setAttribute("data-theme",dataTheme);
}
var $inputTimer = document.getElementById("timer");
$inputTimer.insertAdjacentHTML("afterend", "<span id='header_button'>☰</span>");
var $toggle = document.getElementById("header_button")
var $slider = document.getElementById("scrollayer");
$toggle.addEventListener("click", function() {
var isOpen = $slider.classList.contains("slide-in");
$slider.setAttribute("class", isOpen ? "slide-out" : "slide-in");
$toggle.setAttribute("class", isOpen ? "hb_slideout" : "hb_slidein");
if(isOpen){
$toggle.textContent="☰";
}else{
$toggle.innerHTML="×";
}
});
var fTestForm = document.getElementById("testform");
if(fTestForm){
var olQlist = document.querySelector('ol.qlist');
if(olQlist){
olQlist.addEventListener('click', e => {
var inputButton = document.getElementById(e.target.firstElementChild.id);
inputButton.click();
});
}
}
function isInPage(node) {
return (node === document.body) ? false : document.body.contains(node);
}
function togglePassField(id){
if(document.getElementById(id)){
document.getElementById(id).insertAdjacentHTML("afterend", "<span id='"+id+"_eye' class='icon-eye'></span>");
var a = document.getElementById(id+"_eye");
a.addEventListener("click", function() {
var b = a.classList.contains("icon-eye");
a.setAttribute("class", b ? "icon-eye-unblocked" : "icon-eye");
document.getElementById(id).setAttribute("type", b ? "input" : "password");
});
}
}
togglePassField("currentpassword");
togglePassField("newpassword");
togglePassField("newpassword_repeat");
togglePassField("xuser_password");
if(document.querySelectorAll(".okbox")){
var okBox = document.querySelectorAll(".okbox");
for (var i = 0; i < okBox.length; i++) {
var str = okBox[i].innerHTML = "✓";
okBox[i].innerHTML = str;
}
}
var adaForm = document.forms.length;
if(adaForm===1){
var tceFormBox = document.querySelector(".tceformbox");
var tceContentBox = document.querySelector(".tcecontentbox");
var tceTestList = document.querySelector(".testlist");
if(tceFormBox){
tceFormBox.className += " anyFormBox";
}
if(tceContentBox && !tceTestList){
tceContentBox.className += " anyFormBox";
}
if(!tceFormBox && !tceContentBox){
document.querySelector(".container").className += " anyFormBox";
}
if(tceTestList){
var buttonGreen = document.querySelector(".buttongreen");
var buttonBlue = document.querySelector(".buttonblue");
if(buttonGreen){
buttonGreen.setAttribute("onclick","clearUnsure()");
}
if(buttonBlue){
buttonBlue.setAttribute("onclick","clearUnsure()");
}
}
}
var qNum = document.getElementById("confirmanswer");
if(fTestForm){
var qNum = qNum.value;
var qNumber = qNum.replace(/\D/g,'');
fTestForm.insertAdjacentHTML("beforebegin", "<div id='qTopBar'><span id='qNum'>"+qNumber+"</span><span id='fontResizer'><span id='fontplus' onclick='zoomintext(\".tcecontentbox\")'>+</span><span id='fontminus' onclick='zoomouttext(\".tcecontentbox\")'>−</span><span id='unsure' onclick='addUnsure()' class='icon-flag'></span></span></div>");
}
if(fTestForm){
var lsFontSize = localStorage.getItem("fontSize");
if(lsFontSize){
document.querySelector(".tcecontentbox").style.fontSize =lsFontSize+'px';
if(document.querySelector(".answer")){
document.querySelector(".answer").style.fontSize =lsFontSize+'px';
}
}
}
function zoomintext(idText){
if(fTestForm){
var fs=parseFloat(window.getComputedStyle(document.querySelector(".tcecontentbox")).fontSize);
newfontSize=fs*(1.1);
document.querySelector(idText).style.fontSize =newfontSize+'px';
if(document.querySelector(".answer")){
document.querySelector(".answer").style.fontSize =newfontSize+'px';
}
fontSize=newfontSize;
localStorage.setItem("fontSize", fontSize);
}
}
function zoomouttext(idText){
if(fTestForm){
var fs=parseFloat(window.getComputedStyle(document.querySelector(".tcecontentbox")).fontSize);
newfontSize=fs/(1.1);
document.querySelector(idText).style.fontSize =newfontSize+'px';
if(document.querySelector(".answer")){
document.querySelector(".answer").style.fontSize =newfontSize+'px';
}
fontSize=newfontSize;
localStorage.setItem("fontSize", fontSize);
}
}
function clearUnsure(){
localStorage.setItem('unsure', '[]');
}
function setUnsureLiBg(a){
var direction = window.getComputedStyle(document.querySelector("html")).direction;
if(direction==='ltr'){
document.querySelectorAll("ol.qlist li")[a].style.backgroundImage = "linear-gradient(90deg, transparent 50%, rgb(255, 241, 118) 100%), var(--icon-flag)";
document.querySelectorAll("ol.qlist li")[a].style.backgroundPosition = "center right";
}else{
document.querySelectorAll("ol.qlist li")[a].style.backgroundImage = "linear-gradient(270deg, transparent 50%, rgb(255, 241, 118) 100%), var(--icon-flag)";
document.querySelectorAll("ol.qlist li")[a].style.backgroundPosition = "center left";
}
document.querySelectorAll("ol.qlist li")[a].style.backgroundRepeat = "no-repeat";
document.querySelectorAll("ol.qlist li")[a].style.backgroundSize = "auto";
}
var qNumSpan = document.getElementById("qNum");
var unsureBtn = document.getElementById("unsure");
function unsureStyle(){
unsureBtn.setAttribute("onclick","removeUnsure()");
unsureBtn.style.backgroundColor = "#fff176";
unsureBtn.style.color = "#575757";
unsureBtn.style.borderColor = "#fff176";
qNumSpan.style.backgroundColor = "#fff176";
qNumSpan.style.color = "#575757";
qNumSpan.style.borderColor = "transparent";
}
if(localStorage.getItem('unsure') && fTestForm){
const unsures = JSON.parse(localStorage.getItem('unsure'));
unsures.forEach(el => {
var currNo = document.getElementById("qNum").textContent-1;
if(currNo===el){
unsureStyle();
}
setUnsureLiBg(el);
});
}
function addUnsure(){
if(fTestForm){
var index = document.getElementById("qNum").textContent-1;
unsureStyle();
setUnsureLiBg(index);
let unsure;
if(localStorage.getItem('unsure') === null){
unsure = [];
}else{
unsure = JSON.parse(localStorage.getItem('unsure'));
}
unsure.push(index);
localStorage.setItem('unsure', JSON.stringify(unsure));
}
}
function removeUnsure(){
if(fTestForm){
var index = document.getElementById("qNum").textContent-1;
var unsureBtn = document.getElementById("unsure");
unsureBtn.setAttribute("onclick","addUnsure()");
unsureBtn.removeAttribute("style");
qNumSpan.removeAttribute("style");
document.querySelectorAll("ol.qlist li")[index].removeAttribute("style");
let unsure;
if(localStorage.getItem('unsure') === null){
unsure = [];
}else{
unsure = JSON.parse(localStorage.getItem('unsure'));
}
for(var i = 0; i < unsure.length;){
if(unsure[i] === index){
unsure.splice(i, 1);
}else{
i++;
}
}
localStorage.setItem('unsure', JSON.stringify(unsure));
}
}
function closeToast(a){
document.querySelector(a).style.display = "none";
document.getElementById("close_button").style.display = "none";
}
var toastWar = document.querySelector(".warning");
var toastErr = document.querySelector(".error");
var toastMsg = document.querySelector(".message");
if(toastWar){var toast = ".warning"}
if(toastErr){var toast = ".error"}
if(toastMsg){var toast = ".message"}
if(toast){
document.querySelector(toast).insertAdjacentHTML("beforeend", "<span onclick='closeToast(\""+toast+"\")' id='close_button'>×</span>");
}
var ulMenu = document.querySelector("ul.menu");
if(ulMenu){
if(dataTheme==='light' || !dataTheme){
var dataThemeLbl = 'Turn on dark mode';
var className = 'toDarkMode';
}else{
var dataThemeLbl = 'Turn off dark mode';
var className = 'toLightMode';
}
ulMenu.insertAdjacentHTML("beforeend", "<div style='margin-top:2rem'><button id='toDarkMode' class='"+className+"' style='border-radius:2rem;background:var(--contrast);border:none;color:var(--contrast-inverse);display:flex;align-items:center'>"+dataThemeLbl+"</button></div>");
}
var darkModeBtn = document.getElementById("toDarkMode");
if(darkModeBtn){
darkModeBtn.addEventListener("click", function() {
var isMode = darkModeBtn.classList.contains("toDarkMode");
darkModeBtn.setAttribute("class", isMode ? "toLightMode" : "toDarkMode");
document.querySelector("html").setAttribute("data-theme", isMode ? "dark" : "light");
if(isMode){
darkModeBtn.textContent="Turn off dark mode";
setDataTheme("dark");
}else{
darkModeBtn.textContent="Turn on dark mode";
setDataTheme("light");
}
});
}
/*
* Please don't remove or alter this credit, keep visible and reachable, contact me if you want to make donation. email: [email protected] telegram: @mamans86
*/
document.querySelector("body").insertAdjacentHTML("beforeend", "<div style='padding:0 1rem 1rem 1rem;text-align:center;background:var(--always-dark);color:var(--secondary-inverse)'><span style='font-size:0.85rem'><a style='color:var(--color-warning)' href='https://picoman-theme.blogspot.com' target='blank'>PicoMan Theme</a> created with love by <a style='color:var(--color-warning)' href='https://mamans86.blogspot.com' target='blank'>mamans86</a></span></div>");
if(document.getElementById("scrollayer")){document.getElementById("scrollayer").insertAdjacentHTML("beforeend", "<div style='position:fixed;bottom:1rem;right:1rem'><span style='font-size:0.75rem'><a href='https://picoman-theme.blogspot.com' target='blank'>TCExam PicoMan Theme</a></span></div>")}
/*
* Please don't remove or alter this credit, keep visible and reachable, contact me if you want to make donation. email: [email protected] telegram: @mamans86
*/
</script>