Skip to content

Commit cf4dc7c

Browse files
committed
bedre settings
1 parent 1ae0b8c commit cf4dc7c

File tree

6 files changed

+121
-92
lines changed

6 files changed

+121
-92
lines changed

js/alle.js

Lines changed: 58 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,69 @@
33

44
pages.alle = (async () => {
55

6-
chrome.storage.local.get(["light"], (result) => {
7-
if (result.light) document.body.classList.add("light-theme")
8-
})
9-
chrome.storage.local.get(["fri"], async (result) => {
10-
if (result.fri) {
11-
const fGetXML = async (skoleId, elevId) => {
12-
const response = await getBackend("skemaEnd", async () => {
13-
return new Promise(async res2 => {
14-
var xhttpUrl = "https://www.lectio.dk/lectio/" + skoleId + "/SkemaNy.aspx?type=elev&elevid=" + elevId;
15-
var xhttp = new XMLHttpRequest();
16-
xhttp.onreadystatechange = function () {
17-
if (this.readyState == 4 && this.status == 200) {
18-
const skema = xhttp.responseXML.querySelector(".s2skema tbody tr:nth-child(4)");
19-
20-
const currentDate = new Date()
21-
const currentWeekday = new Date().getDay();
22-
const skemaDay = skema.querySelector(`td:nth-child(${currentWeekday + 1})`);
23-
const skemaBlock = skemaDay.querySelector("div");
24-
let theEnd = new Date();
25-
26-
const lectures = skemaBlock.querySelectorAll(".s2skemabrik:not(.s2cancelled)");
27-
for (const lecture of lectures) {
28-
if (parseInt(xhttp.responseXML.querySelector(`.s2dayHeader td:nth-child(` + (currentWeekday + 1) + `)`).innerText.split("/")[0].match(/\d+/g)[0]) !== new Date().getDate()) continue;
29-
// const start = lecture.getAttribute("data-additionalinfo").match(/\d+:\d+/)[0]
30-
const end = lecture.getAttribute("data-additionalinfo").match(/\d+:\d+/g).pop()
31-
const endTime = new Date(
32-
currentDate.getFullYear(),
33-
currentDate.getMonth(),
34-
currentDate.getDate(),
35-
end.split(":")[0],
36-
end.split(":")[1]
37-
).getTime();
38-
theEnd = endTime
39-
}
40-
res2(theEnd)
6+
// chrome.storage.local.get(["light"], (result) => {
7+
// if (result.light) document.body.classList.add("light-theme")
8+
// })
9+
getSetting("Fri Counter").then(async isEnabled => {
10+
if (!isEnabled) return
11+
const fGetXML = async (skoleId, elevId) => {
12+
const response = await getBackend("skemaEnd", async () => {
13+
return new Promise(async res2 => {
14+
var xhttpUrl = "https://www.lectio.dk/lectio/" + skoleId + "/SkemaNy.aspx?type=elev&elevid=" + elevId;
15+
var xhttp = new XMLHttpRequest();
16+
xhttp.onreadystatechange = function () {
17+
if (this.readyState == 4 && this.status == 200) {
18+
const skema = xhttp.responseXML.querySelector(".s2skema tbody tr:nth-child(4)");
19+
20+
const currentDate = new Date()
21+
const currentWeekday = new Date().getDay();
22+
const skemaDay = skema.querySelector(`td:nth-child(${currentWeekday + 1})`);
23+
const skemaBlock = skemaDay.querySelector("div");
24+
let theEnd = new Date();
25+
26+
const lectures = skemaBlock.querySelectorAll(".s2skemabrik:not(.s2cancelled)");
27+
for (const lecture of lectures) {
28+
if (parseInt(xhttp.responseXML.querySelector(`.s2dayHeader td:nth-child(` + (currentWeekday + 1) + `)`).innerText.split("/")[0].match(/\d+/g)[0]) !== new Date().getDate()) continue;
29+
// const start = lecture.getAttribute("data-additionalinfo").match(/\d+:\d+/)[0]
30+
const end = lecture.getAttribute("data-additionalinfo").match(/\d+:\d+/g).pop()
31+
const endTime = new Date(
32+
currentDate.getFullYear(),
33+
currentDate.getMonth(),
34+
currentDate.getDate(),
35+
end.split(":")[0],
36+
end.split(":")[1]
37+
).getTime();
38+
theEnd = endTime
4139
}
40+
res2(theEnd)
4241
}
43-
xhttp.open("GET", xhttpUrl, true);
44-
xhttp.responseType = "document";
45-
xhttp.send();
46-
})
47-
}, 1000 * 60 * 60)
48-
const headerNav = await first("header[role='banner'] nav .floatLeft");
49-
headerNav.innerHTML += `<p class="fricount">Du har fri om <strong id="fritid"></strong> <p>`;
50-
setInterval(() => {
51-
const timeUntilDate = response - (new Date())
52-
let htmlToApply = formatTime(timeUntilDate);
53-
document.getElementById("fritid").innerText = htmlToApply;
54-
}, 1000)
55-
}
56-
57-
const location = window.location.href;
58-
fGetXML(location?.split("/")?.[4], location?.split("?elevid=")?.[1]?.split("&")[0] ?? location?.split("&elevid=")?.[1]?.split("&")?.[0]);
42+
}
43+
xhttp.open("GET", xhttpUrl, true);
44+
xhttp.responseType = "document";
45+
xhttp.send();
46+
})
47+
}, 1000 * 60 * 60)
48+
const headerNav = await first("header[role='banner'] nav .floatLeft");
49+
headerNav.innerHTML += `<p class="fricount">Du har fri om <strong id="fritid"></strong> <p>`;
50+
setInterval(() => {
51+
const timeUntilDate = response - (new Date())
52+
let htmlToApply = formatTime(timeUntilDate);
53+
document.getElementById("fritid").innerText = htmlToApply;
54+
}, 1000)
5955
}
56+
57+
const location = window.location.href;
58+
fGetXML(location?.split("/")?.[4], location?.split("?elevid=")?.[1]?.split("&")[0] ?? location?.split("&elevid=")?.[1]?.split("&")?.[0]);
6059
})
6160

62-
chrome.storage.local.get(["antiAFK"], (result) => {
63-
if (result.antiAFK) {
64-
setInterval(() => {
65-
const afkAlert = document.querySelector("div.ui-dialog.ui-corner-all.ui-widget")
66-
if (afkAlert != null){
67-
window.location.reload()
68-
}
69-
}, 5000)
70-
}
61+
getSetting("Anti AFK").then(isEnabled => {
62+
if (!isEnabled) return
63+
setInterval(() => {
64+
const afkAlert = document.querySelector("div.ui-dialog.ui-corner-all.ui-widget")
65+
if (afkAlert != null){
66+
window.location.reload()
67+
}
68+
}, 5000)
7169
})
7270
first(".lectioToolbar .floatLeft", e => {
7371
const btn = document.createElement("div")

js/opgaver.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ const sleep = (ms) => {
4141
}
4242
pages.opgaver = (async () => {
4343
// Sort the elements in the opgaver table by date with newest first
44+
const isEnabled = await getSetting("Opgave Funktioner");
45+
if (!isEnabled) return;
4446
await sleep(1000)
4547
sortTable(await first("table"), 3, true);
4648
const opgaver = document.querySelectorAll("tr");

js/util.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,20 @@ const defaultSettings = {
107107
"Dark Mode": {
108108
default: false,
109109
},
110+
},
111+
"General": {
112+
"Fri Counter": {
113+
default: false,
114+
},
115+
"Anti AFK": {
116+
default: false,
117+
},
118+
"Auto Login": {
119+
default: false,
120+
},
121+
"Opgave Funktioner": {
122+
default: false,
123+
},
110124
}
111125
}
112126
const getSetting = async (setting) => {

popup/popup.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
:root {
2+
--primary-color: #ffffff;
3+
--background-color: #393b3d;
4+
--seperator-color: rgb(172, 172, 172);
5+
}
6+
body {
7+
margin: 5px;
8+
min-width: 257px;
9+
min-height: 250px;
10+
overflow-x: hidden;
11+
color: var(--primary-color);
12+
background-color: var(--background-color);
13+
font-family: HCo Gotham SSm, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;
14+
display: flex;
15+
justify-content: center;
16+
align-items: center;
17+
flex-direction: column;
18+
font-size: large;
19+
}
20+
ul {
21+
padding: 0;
22+
}
23+
li {
24+
list-style-type: none;
25+
}

popup/popup.html

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,15 @@
66
<meta http-equiv="X-UA-Compatible" content="IE=edge">
77
<meta name="viewport" content="width=device-width, initial-scale=1.0">
88
<title>Settings</title>
9+
<link rel="stylesheet" href="./popup.css">
910
</head>
1011

1112
<body>
1213
<h1>Settings</h1>
13-
<input type="checkbox" name="autologin" id="autologin" checked="checked">
14-
<label for="autologin">Auto Login</label>
15-
<input type="checkbox" name="fri" id="fri" checked="checked">
16-
<label for="fri">Fri Counter</label>
17-
<input type="checkbox" name="light" id="light" checked="">
18-
<label for="light">Light Theme</label>
19-
<input type="checkbox" name="antiAFK" id="antiAFK" checked="">
20-
<label for="antiAFK">Anti AFK</label>
14+
<ul>
15+
</ul>
2116
</body>
17+
<script src="../js/util.js"></script>
2218
<script src="popup.js"></script>
2319

2420
</html>

popup/popup.js

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
chrome.storage.local.get(["checked"], (result) => {
2-
document.getElementById("autologin").checked = result.checked;
3-
})
4-
chrome.storage.local.get(["light"], (result) => {
5-
document.getElementById("light").checked = result.light;
6-
})
7-
chrome.storage.local.get(["fri"], (result) => {
8-
document.getElementById("fri").checked = result.fri;
9-
})
10-
chrome.storage.local.get(["antiAFK"], (result) => {
11-
document.getElementById("antiAFK").checked = result.antiAFK;
12-
})
13-
document.getElementById("autologin").addEventListener("change", (e) => {
14-
chrome.storage.local.set({ checked: e.target.checked });
15-
})
16-
document.getElementById("light").addEventListener("change", (e) => {
17-
chrome.storage.local.set({ light: e.target.checked });
18-
})
19-
document.getElementById("fri").addEventListener("change", (e) => {
20-
chrome.storage.local.set({ fri: e.target.checked });
21-
})
22-
document.getElementById("antiAFK").addEventListener("change", (e) => {
23-
chrome.storage.local.set({ antiAFK: e.target.checked });
24-
})
1+
2+
for (const category of Object.values(defaultSettings)) {
3+
for (const setting in category) {
4+
const nameWithNoSpace = setting.replace(/\s/g, "");
5+
const settingElement = document.createElement("li");
6+
settingElement.innerHTML = `
7+
<input type="checkbox" name="${nameWithNoSpace}" id="${nameWithNoSpace}" checked="checked">
8+
<label for="${nameWithNoSpace}">${setting}</label>
9+
`;
10+
document.querySelector("ul").appendChild(settingElement);
11+
getSetting(setting).then((result) => {
12+
document.getElementById(nameWithNoSpace).checked = result;
13+
})
14+
document.getElementById(nameWithNoSpace).addEventListener("change", (e) => {
15+
setSetting(setting, e.target.checked);
16+
})
17+
}
18+
}

0 commit comments

Comments
 (0)