From f254bacc99d8800e4ad0ffe2afdf2ea632a0d1f6 Mon Sep 17 00:00:00 2001 From: les Date: Fri, 18 Oct 2024 15:30:45 +0200 Subject: [PATCH] refactor/moved files to folders --- autologin.js | 111 ------------------------- color.js | 37 --------- constants.js | 45 ---------- content.js | 35 -------- highlighting.js | 65 --------------- init.js | 42 ---------- popup.css | 206 ---------------------------------------------- popup.html | 65 --------------- popup.js | 105 ----------------------- timer.js | 51 ------------ toggleDarkMode.js | 74 ----------------- utils.js | 11 --- 12 files changed, 847 deletions(-) delete mode 100644 autologin.js delete mode 100644 color.js delete mode 100644 constants.js delete mode 100644 content.js delete mode 100644 highlighting.js delete mode 100644 init.js delete mode 100644 popup.css delete mode 100644 popup.html delete mode 100644 popup.js delete mode 100644 timer.js delete mode 100644 toggleDarkMode.js delete mode 100644 utils.js diff --git a/autologin.js b/autologin.js deleted file mode 100644 index 74d34a4..0000000 --- a/autologin.js +++ /dev/null @@ -1,111 +0,0 @@ -function encrypt(password, encryptionKey) { - if (!password || !encryptionKey) { - throw new Error('Password and encryption key cannot be null or undefined'); - } - let encryptedPassword = ''; - for (let i = 0; i < password.length; i++) { - const passwordCharCode = password.charCodeAt(i); - const keyCharCode = encryptionKey.charCodeAt(i % encryptionKey.length); - const encryptedCharCode = passwordCharCode ^ keyCharCode; - if (isNaN(encryptedCharCode)) { - throw new Error('Error during XOR operation'); - } - encryptedPassword += String.fromCharCode(encryptedCharCode); - } - return encryptedPassword; -} - - -function processCredentials(username, password, enabled, encryptEn, key) { - //Check if input is valid → if only pw or us or (XOR(key, encEn)) with different cominations - if (!(!(((username === "" || password === "" || (key === "" && encryptEn)) && (username !== "" != password !== "")) || (key === "" && encryptEn) || (key !== "" && !encryptEn)) || (password === "" && username === "" && key === ""))) { - return "failedInputValidation"; - } - if (encryptEn) { - let password_ = encrypt(password, key); - let username_ = encrypt(username, key); - set_stored_credentials(username_, password_, enabled, encryptEn); - } - else { - set_stored_credentials(username, password, enabled, encryptEn); - } -} - -function set_stored_credentials(en_usr, en_pw, enabled, encrypt) { - if (en_usr !== null && en_usr !== undefined && en_usr !== "" && en_pw !== null && en_pw !== undefined && en_pw !== "") { - localStorage.setItem("username", en_usr); - localStorage.setItem("password", en_pw); - localStorage.setItem("encrypt", encrypt); - } - localStorage.setItem("enabled", enabled); -} - -function get_stored_credentials() { - const username = localStorage.getItem("username"); - const password = localStorage.getItem("password"); - if (username !== null && password !== null) { - return [username, password]; - } - else { - - return [null, null]; - } -} - -function get_credentials_enabled() { - return localStorage.getItem("enabled"); -} - -function getEnrcyptEnabled() { - let enc = localStorage.getItem("encrypt"); - if (enc == undefined) { - enc = false; - } - return enc; -} - -function loginEncrypted(key) { - [username_, password_] = get_stored_credentials(); - if (username_ == null || password_ == null) { - return; - } else if(key == null || key == undefined || key == "") { - return "failedInputValidation"; - } - document.getElementById("UserName").value = encrypt(username_, key); - document.getElementById("Password").value = encrypt(password_, key); - sleep(300); - document.querySelector(".btn.btn-primary").click(); - sleep(1000); -} - - -function delete_credentials() { - localStorage.removeItem("username"); - localStorage.removeItem("password"); - localStorage.setItem("enabled", false); - localStorage.setItem("encrypt", false); -} - -function login() { - let [username_, password_] = get_stored_credentials(); - if (username_ == null || password_ == null) { - return; - } - document.getElementById("UserName").value = username_; - document.getElementById("Password").value = password_; - sleep(300); - document.querySelector(".btn.btn-primary").click(); - sleep(1000); -} - -function getAutoLoginState() { - const autologinEnableState = localStorage.getItem("enabled"); - if (autologinEnableState != null || autologinEnableState != undefined) { - if (autologinEnableState === "true") { - return true; - } - } - else { - return false; - } -} \ No newline at end of file diff --git a/color.js b/color.js deleted file mode 100644 index 51a3a60..0000000 --- a/color.js +++ /dev/null @@ -1,37 +0,0 @@ -function get_stored_color() { - const color_ = localStorage.getItem("color"); - if (color_ !== null) { - return color_; - } - else { - return "#4281ff"; - } -} - -function set_stored_color(color_) { - if (color_ !== null && color_ !== undefined && color_ !== "" && color_.includes("#")) { - color = color_; - localStorage.setItem("color", color); - } else if (!color_.includes("#")) { - return "faieldColorValidation"; - } -} - -function set_style_color() { - // Change the --weekdayToday variable to a new color - document.documentElement.style.setProperty('--weekdayToday', color); -} - -function processColorResponse(color_) { - const return_ = set_stored_color(color_); - if (return_ === "faieldColorValidation") { - return "faieldColorValidation"; - } - const elements = document.querySelectorAll('.weekdayToday'); - elements.forEach((el) => { - el.style.setProperty('fill', color_, 'important'); - }); -} - -let color = get_stored_color(); -set_style_color(); \ No newline at end of file diff --git a/constants.js b/constants.js deleted file mode 100644 index eecf705..0000000 --- a/constants.js +++ /dev/null @@ -1,45 +0,0 @@ -const timeTable = [ - { - start: [8, 30], - end: [9, 15], - }, - { - start: [9, 15], - end: [10, 0], - }, - { - start: [10, 0], - end: [11, 0], - }, - { - start: [11, 0], - end: [11, 45], - }, - { - start: [11, 45], - end: [12, 30], - }, - { - start: [12, 30], - end: [13, 15], - }, - { - start: [13, 15], - end: [14, 0], - }, - { - start: [14, 0], - end: [14, 45], - }, - { - start: [14, 45], - end: [15, 30], - }, - { - start: [15, 30], - end: [16, 15], - }, -]; - -const refreshTimeout = 10000; -const hourOver = "grey"; \ No newline at end of file diff --git a/content.js b/content.js deleted file mode 100644 index cd032eb..0000000 --- a/content.js +++ /dev/null @@ -1,35 +0,0 @@ -chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { - if (request.changeColorBtn) { - const return_ = processColorResponse(request.color); - if (return_ === "faieldColorValidation") { - sendResponse({ faieldColorValidation: true }); - } - } - else if (request.autologinresetBtn) { - delete_credentials(); - } - else if (request.get_AutologinState) { - const autologinEnableState = getAutoLoginState(); - const autologinPasswordProtection = getEnrcyptEnabled(); - sendResponse({ autologinEnableState, autologinPasswordProtection }); - } - else if (request.autologinBtn) { - const return_ = processCredentials(request.username, request.pawssword, request.enabled, request.encryptEnabled, request.key); - if (return_ === "failedInputValidation") { - sendResponse({ failedInputValidation: true }); - } - } - else if (request.darkModeToggle) { - setDarkMode(request.darkMode); - } - else if (request.getDarkModeState) { - const darkModeState = getDarkMode(); - sendResponse({ darkModeState: darkModeState }); - } - else if (request.autologinEncryptionBtn) { - const return_ = loginEncrypted(request.key); - if (return_ === "failedInputValidation") { - sendResponse({ failedInputValidation: true }); - } - } -}); \ No newline at end of file diff --git a/highlighting.js b/highlighting.js deleted file mode 100644 index 2663112..0000000 --- a/highlighting.js +++ /dev/null @@ -1,65 +0,0 @@ -function checkTime(item, index) { - const currentTime = new Date(); - const startTime = getTimeObject(item.start[0], item.start[1]); - const endTime = getTimeObject(item.end[0], item.end[1]); - - let box; - - if (window.location.pathname.includes("Stundenplan")) { - box = document.getElementById("umgebung"); - if (box === null) { - return; - } - box = box.children[0]; - } else { - box = document.getElementById("umgebung"); - if (box === null) { - return; - } - box = box.children[0].children[1].children[0]; - } - - const currentBox = box.children[index]; - - if (currentTime > endTime) { - currentBox.children[0].classList.remove("weekdayToday"); - currentBox.children[1].style.fill = hourOver; - currentBox.children[2].style.fill = hourOver; - currentBox.children[3].style.fill = hourOver; - } else if (currentTime > startTime && currentTime < endTime) { - currentBox.children[0].classList.add("weekdayToday"); - } -} -function hidePassedDays() { - if (window.location.pathname.includes("Stundenplan")) { - const box = document.getElementById("umgebung"); - if (box === null) { - return; - } - for (let i = 1; i < 5; i++) { - if ( - box.children[i].children[0].children[0].classList.contains( - "weekdayToday", - ) - ) { - break; - } else { - box.children[i].children[0].children[1].classList.add("passedDay"); - } - } - } -}function markCurrentDay() { - const date = new Date().toLocaleDateString("de-DE"); - - const tables = document.getElementsByTagName("table"); - for (const table of tables) { - const rows = table.getElementsByTagName("tr"); - for (const row of rows) { - const strong = row.querySelector("strong"); - if (strong && strong.textContent.includes(date)) { - row.style.backgroundColor = color; - return; - } - } - } -} diff --git a/init.js b/init.js deleted file mode 100644 index f1a76c7..0000000 --- a/init.js +++ /dev/null @@ -1,42 +0,0 @@ -if ( - document.referrer === "https://www.digikabu.de" || - document.referrer === "https://www.digikabu.de/Main/TestRedirect" -) { - window.location.href = "https://www.digikabu.de/Stundenplan/Klasse"; -} - -if ( - document.referrer === "https://digikabu.de" || - document.referrer === "https://digikabu.de/Main/TestRedirect" -) { - window.location.href = "https://digikabu.de/Stundenplan/Klasse"; -} - -function startInfiniteLoop() { - setTimeout(function () { - timeTable.forEach(checkTime); - startInfiniteLoop(); - }, refreshTimeout); -} - -window.addEventListener("pageshow", () => { - - initDarkMode(); - setDarkMode(getDarkMode()); - const urlpath = window.location.pathname; - if (urlpath.includes("SchulaufgabenPlan")) { - markCurrentDay(); - } - if (urlpath.includes("Stundenplan") || urlpath.includes("Main")) { - setTimeout(() => { - hidePassedDays(); - showTimer(); - timeTable.forEach(checkTime); - startInfiniteLoop(); - }, 600); - } - if (urlpath === "/" && get_credentials_enabled() === "true" && (getEnrcyptEnabled() != "true" && getEnrcyptEnabled() != true)) { - login(); - } - -}); \ No newline at end of file diff --git a/popup.css b/popup.css deleted file mode 100644 index c9e9197..0000000 --- a/popup.css +++ /dev/null @@ -1,206 +0,0 @@ -body { - width: 400px; - border-radius: 20px; - color: white; - display: grid; - flex-direction: column; - text-align: center; - background-color: #292b30; - place-items: center; - overflow: hidden; - justify-content: center; - align-items: center; -} - -h3 { - margin: unset; - font-family: 'Futura', monospace; - font-size: 24px; - color: white; - border-radius: clamp(0.4rem, 0.15vw, 0.5rem); -} - -h4 { - margin: unset; - font-family: 'Futura', monospace; - font-size: 20px; - color: white; - border-radius: clamp(0.4rem, 0.75vw, 1rem); -} - -body.menu-toggled > .meta-link > span { - color: rgb(30, 30, 30); -} - -.meta-link > i, -.meta-link > span { - height: 20px; - line-height: 20px; -} - -.meta-link > span { - color: white; - font-family: "Rubik", sans-serif; - font-weight: 500; -} - -#pBestKabu { - margin-bottom: 0.5vh; - margin-top: 0.5vh; -} - -#colorInputField { - display: flex; - gap: 5px; - margin-top: 5px; - flex-direction: row; - justify-content: center; - align-items: center; -} - -.autologin { - display: flex; - justify-content: center; - align-items: center; - flex-direction: column; - text-align: center; -} - -#autologin { - display: flex; - align-items: center; - justify-content: center; - flex-direction: column; -} - -/* The switch - the box around the slider */ -.switch { - position: relative; - display: inline-block; - width: 40px; - height: 30px; -} - -/* Hide default HTML checkbox */ -.switch input { - opacity: 0; - width: 0; - height: 0; -} - -/* The slider */ -.slider { - position: absolute; - cursor: pointer; - top: 0; - left: 0; - right: 0; - bottom: 0; - height: 30px; - width: 48px; - background-color: #ccc; - -webkit-transition: .4s; - transition: .4s; -} - -.slider:before { - position: absolute; - content: ""; - height: 20px; - width: 20px; - left: 4px; - bottom: 4px; - background-color: white; - -webkit-transition: .4s; - transition: .4s; -} - -input:checked + .slider { - background-color: #2196F3; -} - -input:focus + .slider { - box-shadow: 0 0 1px #2196F3; -} - -input:checked + .slider:before { - -webkit-transform: translateX(20px); - -ms-transform: translateX(20px); - transform: translateX(20px); -} - -/* Rounded sliders */ -.slider.round { - border-radius: 25px; -} - -.slider.round:before { - border-radius: 50%; -} - -.sectionLine { - margin: 10px 0px 10px 0px; -} - -.toggleButton { - margin-top: 10px; - display: flex; - justify-content: center; - align-items: center; - gap: 10px; -} - - -#colorPicker { - width: 140px; -} - -#divMainSettings { - display: flex; - flex-direction: column; - justify-content: center; - align-items: center; - gap: 5px; -} - -.styled-button { - background-color: #4281ff; /* Green */ - border: none; - color: white; - padding: 5px 10px; - text-align: center; - text-decoration: none; - font-size: 14px; - margin: 2px 1px; - cursor: pointer; - border-radius: 8px; - transition-duration: 0.4s; -} - -.styled-button:hover { - background-color: white; - color: black; -} - -.styled-input { - width: 250px; - padding: 5px; - margin: 5px 0; - box-sizing: border-box; - border: 2px solid #ccc; - border-radius: 4px; - background-color: #f8f8f8; - font-size: 14px; - color: #333; - transition: border-color 0.3s; -} - -.styled-input:focus { - border-color: #4281ff; - outline: none; -} - -/* Preserve the behavior of the hidden attribute */ -[hidden] { - display: none !important; -} \ No newline at end of file diff --git a/popup.html b/popup.html deleted file mode 100644 index f6d806b..0000000 --- a/popup.html +++ /dev/null @@ -1,65 +0,0 @@ - - - - - - - - - - - -

BestKabu

-

Verwandelt Digikabu in BestKabu

-
- -
-

Go to digikabu.de to use this extension

-
- - - - \ No newline at end of file diff --git a/popup.js b/popup.js deleted file mode 100644 index c7c4619..0000000 --- a/popup.js +++ /dev/null @@ -1,105 +0,0 @@ -// chrome.tabs..... { : true, parameter… }); -document.getElementById('changeColorBtn').addEventListener('click', () => { - const color = document.getElementById('colorPicker').value; - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, {changeColorBtn: true, color: color}, (response) => { - if (response !== undefined && response.faieldColorValidation) { - alert("Color must be written as #RRGGBB"); - } - }); - }); -}); - -document.getElementById('autologinBtn').addEventListener('click', () => { - const username = document.getElementById('autologinUsername').value; - const password = document.getElementById('autologinPassword').value; - const enabled = document.getElementById('autologinCheckbox').checked; - const encryptEnabled = document.getElementById('autologinPasswordProtection').checked; - const key = document.getElementById('autologinEncryptionPassword').value; - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, { - autologinBtn: true, - pawssword: password, - username: username, - enabled: enabled, - encryptEnabled: encryptEnabled, - key: key - }, (response) => { - if (response !== undefined && response.failedInputValidation) { - alert("Input Validation Failed! Please Check Your Input and Try Again. View the GitHub Repo for more info."); - } - }); - }); - getAutologinState(); -}); - -document.getElementById('autologinresetBtn').addEventListener('click', () => { - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, {autologinresetBtn: true}); - }); - getAutologinState(); -}); - -document.getElementById('darkModeToggle').addEventListener('click', () => { - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, { - darkModeToggle: true, - darkMode: document.getElementById('darkModeToggle').checked - }); - }); -}); - -document.getElementById('autologinEncryptionBtn').addEventListener('click', () => { - const key = document.getElementById('autologinEncryptionPassword').value; - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, {autologinEncryptionBtn: true, key: key}, (response) => { - if (response !== undefined && response.failedInputValidation) { - alert("Input Validation Failed! Please Check Your Input and Try Again. View the GitHub Repo for more info."); - } - }); - }); -}); - -document.getElementById('autologinEncryptionPassword').addEventListener('keypress', (e) => { - if (e.key === 'Enter') { - if(document.getElementById('autologinUsername').value === "" && document.getElementById('autologinPassword').value === "") { - document.getElementById('autologinEncryptionBtn').click(); - } - } -}); - -function getAutologinState() { - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, {get_AutologinState: true}, (response) => { - if (response !== undefined) { - if (response.autologinEnableState == true || response.autologinEnableState == "true") { - document.getElementById("autologinCheckbox").checked = true; - } else { - document.getElementById("autologinCheckbox").checked = false; - } - if (response.autologinPasswordProtection == true || response.autologinPasswordProtection == "true") { - document.getElementById("autologinPasswordProtection").checked = true; - document.getElementById("autologinEncryptionBtn").hidden = false; - } else { - document.getElementById("autologinPasswordProtection").checked = false; - document.getElementById("autologinEncryptionBtn").hidden = true; - } - } - }); - }); -} - -function getDarkMode() { - chrome.tabs.query({active: true, currentWindow: true}, (tabs) => { - chrome.tabs.sendMessage(tabs[0].id, {getDarkModeState: true}, (response) => { - if (response !== undefined) { - document.getElementById("darkModeToggle").checked = response.darkModeState; - document.getElementById("divMainSettings").hidden = false; - document.getElementById("divNotKabu").hidden = true; - } - }); - }); -} - -getAutologinState(); -getDarkMode(); \ No newline at end of file diff --git a/timer.js b/timer.js deleted file mode 100644 index 776ddca..0000000 --- a/timer.js +++ /dev/null @@ -1,51 +0,0 @@ -function showTimer() { - if (window.location.pathname.includes("Stundenplan")) { - let box = document.getElementById("stdplanheading"); - if (box === null) { - box = document.querySelector('div[style="margin-left:10px;"]'); - } - - const timerElement = document.createElement("span"); - timerElement.id = "timerText"; - - box.append(timerElement); - - function updateTimerDisplay(minutes, seconds) { - let timerText; - if (isNaN(minutes)) { - timerText = "Schule zu Ende :)"; - } else { - timerText = `${minutes}m ${seconds}s`; - } - document.querySelector("#timerText").textContent = timerText; - } - - function calculateTimeDiff() { - const currentTime = new Date(); - - let nextLessonStart; - if (getTimeObject(timeTable[0].start[0], timeTable[0].start[1]) > currentTime) { - nextLessonStart = getTimeObject(timeTable[0].start[0], timeTable[0].start[1]); - } - else { - for (let i = 0; i < timeTable.length; i++) { - const endTime = getTimeObject(timeTable[i].end[0], timeTable[i].end[1]); - if (currentTime < endTime) { - nextLessonStart = endTime; - break; - } - } - } - - const timeDiff = Math.max(nextLessonStart - currentTime, 0); - const minutes = Math.floor(timeDiff / 60000); - const seconds = Math.floor((timeDiff % 60000) / 1000); - - updateTimerDisplay(minutes, seconds); - } - - calculateTimeDiff(); - - setInterval(calculateTimeDiff, 1000); - } -} \ No newline at end of file diff --git a/toggleDarkMode.js b/toggleDarkMode.js deleted file mode 100644 index ae4e676..0000000 --- a/toggleDarkMode.js +++ /dev/null @@ -1,74 +0,0 @@ -function setDarkMode(state) { - localStorage.setItem("darkMode", state); - setDarkModeState(state); -} - -function getDarkMode() { - const state = localStorage.getItem("darkMode"); - if (state != null) { - if (state === "true") { - return true; - } - } - else { - return false; - } -} - -function initDarkMode() { - if (localStorage.getItem("darkMode") === null) { - setDarkMode(true); - } -} - -function setDarkModeState(state) { - let navColor; - let backgroundColor; - let planColor; - let lessonColor; - let hourOverlay; - let hourCanceled; - let hourChanged; - let white; - let glyphicon; - let activeTab; - let timerBackgound; - if (state === true) { - navColor = "#1f2124"; - backgroundColor = "#292b30"; - planColor = "#37393f"; - lessonColor = "#434549"; - hourOverlay = "#67696d"; - hourCanceled = "#FF4041"; - hourChanged = "#fab433"; - white = "#DDDDDD"; - activeTab = "#ffffff"; - glyphicon = "#ffffff"; - timerBackgound = "#434549"; - } - else { - navColor = "#767174"; - backgroundColor = "#ffffff"; - planColor = "#bfbfbf"; - lessonColor = "#a3a5a9"; - hourOverlay = "#6e6e6e"; - hourCanceled = "#FF4041"; - hourChanged = "#fab433"; - white = "#000000"; - activeTab = "#000000"; - glyphicon = "#ffffff"; - timerBackgound = "#A3A5A9"; - } - document.documentElement.style.setProperty('--navColor', navColor); - document.documentElement.style.setProperty('--backgroundColor', backgroundColor); - document.documentElement.style.setProperty('--planColor', planColor); - document.documentElement.style.setProperty('--glyphicon', glyphicon); - document.documentElement.style.setProperty('--lessonColor', lessonColor); - document.documentElement.style.setProperty('--hourOverlay', hourOverlay); - document.documentElement.style.setProperty('--hourCanceled', hourCanceled); - document.documentElement.style.setProperty('--hourCanceled', hourCanceled); - document.documentElement.style.setProperty('--hourChanged', hourChanged); - document.documentElement.style.setProperty('--white', white); - document.documentElement.style.setProperty('--activeTab', activeTab); - document.documentElement.style.setProperty('--timerBackgound', timerBackgound); -} \ No newline at end of file diff --git a/utils.js b/utils.js deleted file mode 100644 index 7008edf..0000000 --- a/utils.js +++ /dev/null @@ -1,11 +0,0 @@ -function sleep(ms) { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -function getTimeObject(hours, minutes) { - let obj = new Date(); - obj.setHours(hours); - obj.setMinutes(minutes); - obj.setSeconds(0); - return obj; -} \ No newline at end of file