schoolbox web extension :)
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: `doc-end.js` #44

Willow 2f5ff2ff 51d85bff

+13 -52
+13 -52
src/scripts/doc-end.js
··· 13 13 }); 14 14 15 15 // check if the page is Schoolbox, if not add it to storage and reload the page 16 - schoolboxChecker(); 17 - 18 - // ----------------- Functions ----------------- // 19 - 20 - 21 - function schoolboxChecker() { 22 - // check if the page is schoolbox 23 - try { 24 - let footer = getChildNode(document.getElementById("footer"), 1); 25 - if (footer.innerHTML.includes("Schoolbox")) { 26 - let footerListItem = document.createElement("LI"); 27 - footerListItem.innerHTML = "<a href='https://github.com/42willow/schooltape'>Schooltape</a> "+chrome.runtime.getManifest().version; 28 - footer.appendChild(footerListItem); 29 - // check if the current url is saved in the storage 30 - chrome.storage.local.get("settings", function (data) { 31 - // if the url is not saved 32 - if (!data.settings.urls.includes(window.location.origin)) { 33 - let settings = data.settings; 34 - settings.urls.push(window.location.origin); 35 - chrome.storage.local.set({"settings": settings}, function () { 36 - // console.log(`%c[doc-end.js]`, docEndConsole, "Added URL to storage"); 37 - }); 38 - // reload page 39 - window.location.reload(); 40 - } 41 - }); 42 - return true; 43 - } else { 44 - return false; 16 + let footer = document.querySelector("#footer > ul"); 17 + if (footer.innerHTML.includes("Schoolbox")) { 18 + let footerListItem = document.createElement("li"); 19 + footerListItem.appendChild(document.createElement('a')).href = 'https://github.com/42willow/schooltape'; 20 + footerListItem.firstChild.textContent = `Schooltape v${chrome.runtime.getManifest().version}`; 21 + footer.appendChild(footerListItem); 22 + chrome.storage.local.get("settings", function ({settings}) { 23 + if (!settings.urls.includes(window.location.origin)) { 24 + settings.urls.push(window.location.origin); 25 + chrome.storage.local.set({"settings": settings}); 26 + // TODO: hot reload 27 + window.location.reload(); 45 28 } 46 - } 47 - catch (e) { 48 - return false; 49 - } 50 - } 51 - 52 - function getChildNode(node, childNum, nodeName = null) { 53 - let childCounter = 0; 54 - for (let i = 0; i < node.childNodes.length; i++) { 55 - // If node type is an element node 56 - if (node.childNodes[i].nodeType === 1) { 57 - if (nodeName) { 58 - if (node.childNodes[i].nodeName === nodeName) { 59 - childCounter++; 60 - } 61 - } else { 62 - childCounter++; 63 - } 64 - if (childCounter === childNum) { 65 - return node.childNodes[i]; 66 - } 67 - } 68 - } 29 + }); 69 30 } 70 31 71 32 async function runUtilsFunction(functionName, ...args) {