From 6e266ffd48daba91f9f850163bdcea8c088ea046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Daron?= <34960023+Kaporos@users.noreply.github.com> Date: Fri, 17 Nov 2023 21:13:24 +0100 Subject: [PATCH] Prevent moodle from downloading pdfs (#2) By passing forceDownload=1 to forceDownload=0, we can block moodle from forcing download of pdf's before reading --- .gitignore | 3 +- Chrome/background.js | 31 +++++- Chrome/index.js | 6 +- Chrome/manifest.json | 96 ++++++++++-------- Chrome/popup/options.css | 63 +++++++++--- Chrome/popup/options.html | 29 ++++-- Chrome/popup/options.js | 37 +++---- Chrome/retrieveVariables.js | 6 +- Chrome/rules.json | 27 +++++ Firefox/background.js | 17 ++++ Firefox/index.js | 8 +- Firefox/manifest.json | 74 ++++++++------ ...r-1.1.1.zip => moodlecustomizer-1.1.2.zip} | Bin 97750 -> 99329 bytes Firefox/popup/options.css | 61 ++++++++--- Firefox/popup/options.html | 27 +++-- Firefox/popup/options.js | 35 ++++--- README.md | 6 +- 17 files changed, 362 insertions(+), 164 deletions(-) create mode 100644 Chrome/rules.json create mode 100644 Firefox/background.js rename Firefox/{moodlecustomizer-1.1.1.zip => moodlecustomizer-1.1.2.zip} (94%) diff --git a/.gitignore b/.gitignore index ea031ba..185cdc2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ */web-ext-artifacts/* */node_modules/* Chrome.crx -Chrome.pem \ No newline at end of file +Chrome.pem +Chrome/_metadata diff --git a/Chrome/background.js b/Chrome/background.js index be18561..515f99b 100644 --- a/Chrome/background.js +++ b/Chrome/background.js @@ -1,5 +1,6 @@ chrome.runtime.onInstalled.addListener(async () => { - for (const cs of chrome.runtime.getManifest().content_scripts) { + + for (const cs of chrome.runtime.getManifest().content_scripts) { for (const tab of await chrome.tabs.query({ url: cs.matches })) { chrome.scripting.executeScript({ target: { tabId: tab.id }, @@ -7,4 +8,30 @@ chrome.runtime.onInstalled.addListener(async () => { }); } } -}); \ No newline at end of file +}); + +chrome.storage.local.onChanged.addListener(async (chan) => { + if (chan.avoidPdfDownload) { + let enabled = chan.avoidPdfDownload.newValue; + await chrome.declarativeNetRequest.updateStaticRules({ + disableRuleIds: enabled ? [] : [1], + enableRuleIds: enabled ? [1] : [], + rulesetId: "ruleset_1" + }) + console.log("updated") + } +}) + +async function pdfSetup() { + let storage = await chrome.storage.local.get('avoidPdfDownload'); + if (Object.keys(storage).includes("avoidPdfDownload") && !storage.avoidPdfDownload) { //If avoidPdfDownload is not in keys -> default setting -> should not disable. + console.log("Disabling pdfDownload because of settings.") + await chrome.declarativeNetRequest.updateStaticRules({ + disableRuleIds: [1], + enableRuleIds: [], + rulesetId: "ruleset_1" + }) + } +} + +pdfSetup(); diff --git a/Chrome/index.js b/Chrome/index.js index 3ddf9df..079c19f 100644 --- a/Chrome/index.js +++ b/Chrome/index.js @@ -1,5 +1,5 @@ var keepAliveIntervalId; -var keepAliveEnabled = localStorage.getItem("keepAlive") === 'true'; +var keepAliveEnabled = localStorage.getItem("keepAlive") !== 'false'; var sesskey = ''; var moodleURLBase = '' @@ -9,6 +9,7 @@ chrome.storage.onChanged.addListener((changes, area) => { if (keepAliveEnabled) { runKeepAlive(); } else { + console.log("clear") clearInterval(keepAliveIntervalId); } localStorage.setItem("keepAlive", keepAliveEnabled); @@ -50,6 +51,7 @@ function setupSesskey(callback) { } function runKeepAlive() { + console.log("ran") if(moodleURLBase === '') { return; } @@ -77,4 +79,4 @@ function runKeepAlive() { } }); }, 1 * 60 * 60 * 1000); -} \ No newline at end of file +} diff --git a/Chrome/manifest.json b/Chrome/manifest.json index 0746d5f..980e784 100644 --- a/Chrome/manifest.json +++ b/Chrome/manifest.json @@ -1,43 +1,59 @@ { - "manifest_version": 3, - "name": "MoodleCustomizer", - "version": "1.1.1", - "author": "Hokkaydo", - "description": "Improve your Moodle experience.", - "icons": { - "16": "icons/logo.png" - }, - "permissions": [ - "activeTab", - "tabs", - "webNavigation", - "scripting", - "storage" - ], - "host_permissions": [ - "" - ], - "content_scripts": [ - { - "matches": [ - "" - ], - "js": [ - "index.js" - ] - } - ], - "action": { - "default_title": "On/Off", - "default_popup": "popup/options.html" - }, - "background": { - "service_worker": "background.js" - }, - "web_accessible_resources":[ - { - "resources": ["retrieveVariables.js"], - "matches": [""] - } + "manifest_version": 3, + "name": "MoodleCustomizer", + "version": "1.1.2", + "author": "Hokkaydo", + "description": "Improve your Moodle experience.", + "icons": { + "16": "icons/logo.png" + }, + "permissions": [ + "activeTab", + "tabs", + "webNavigation", + "scripting", + "storage", + "declarativeNetRequest", + "declarativeNetRequestWithHostAccess" + ], + "host_permissions": [ + "" + ], + "content_scripts": [ + { + "matches": [ + "http://*/*", + "https://*/*" + ], + "js": [ + "index.js" + ] + } + ], + "action": { + "default_title": "On/Off", + "default_popup": "popup/options.html" + }, + "background": { + "service_worker": "background.js" + }, + "declarative_net_request": { + "rule_resources": [ + { + "id": "ruleset_1", + "enabled": true, + "path": "rules.json" + } ] + }, + "web_accessible_resources": [ + { + "resources": [ + "retrieveVariables.js" + ], + "matches": [ + "" + ] + } + ] } \ No newline at end of file diff --git a/Chrome/popup/options.css b/Chrome/popup/options.css index 85271ef..185bb17 100644 --- a/Chrome/popup/options.css +++ b/Chrome/popup/options.css @@ -1,19 +1,52 @@ -.list { - width: 240px; - background-color: white; - display: grid; - grid-template-columns: repeat(2, 1fr); - font-size: small; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +body { + width: 300px; + height: 200px; + display: flex; + flex-direction: column; + align-items: center; } -.onoff > img { - width: 70%; + + +.control { + display: flex; + align-items: center; +} +.control > p { + margin-right: 10px; + +} + +input[type="checkbox"] { + position: relative; + appearance: none; + width: 37.5px; + height: 18.75px; + background: #ccc; + border-radius: 50px; + box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); + cursor: pointer; + transition: 0.4s; } -.list > .onoff { - display: flex; - justify-content: center; - align-items: center; - width: 50px; -} \ No newline at end of file +input:checked[type="checkbox"] { + background: #7da6ff; +} + +input[type="checkbox"]::after { + position: absolute; + content: ""; + width: 18.75px; + height: 18.75px; + top: 0; + left: 0; + background: #fff; + border-radius: 50%; + box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); + transform: scale(1.1); + transition: 0.4s; +} + +input:checked[type="checkbox"]::after { + left: 50%; +} diff --git a/Chrome/popup/options.html b/Chrome/popup/options.html index 6de283f..dbab794 100644 --- a/Chrome/popup/options.html +++ b/Chrome/popup/options.html @@ -1,16 +1,29 @@ + - - - - - Document - + + + + + Document + + -
+

Settings:

+
+
+

Keep Alive:

+ +
+
+

Avoid PDF downloads:

+
- +
+ + + \ No newline at end of file diff --git a/Chrome/popup/options.js b/Chrome/popup/options.js index f3e682a..4bd09e1 100644 --- a/Chrome/popup/options.js +++ b/Chrome/popup/options.js @@ -1,18 +1,19 @@ -const toggleKeepAlive = document.createElement("p"); -const keepAliveOnOff = document.createElement("img"); -var keepAlive = localStorage.getItem("keepAlive") === 'true'; -keepAliveOnOff.src = chrome.runtime.getURL("icons/" + (keepAlive ? "on.png" : "off.png")); -toggleKeepAlive.textContent = "KeepAlive : "; -toggleKeepAlive.addEventListener("click", (_event) => { - const keepAlive = localStorage.getItem("keepAlive") === 'true'; - localStorage.setItem("keepAlive", !keepAlive); - toggleKeepAlive.textContent = "KeepAlive : "; - keepAliveOnOff.src = chrome.runtime.getURL("icons/" + (!keepAlive ? 'on.png': 'off.png')); - chrome.storage.local.set({keepAlive: !keepAlive}) -}); -const list = document.getElementsByClassName("list")[0] -const onoff = document.createElement("div"); -onoff.classList.add("onoff"); -onoff.appendChild(keepAliveOnOff); -list.appendChild(toggleKeepAlive); -list.appendChild(onoff); \ No newline at end of file +let settings = {}; + +for (input of document.getElementsByTagName("input")) { + if (!input.type == "checkbox") { + console.log(input); + continue; + } + let item = input.dataset.item; + input.checked = localStorage.getItem(item) !== 'false'; + settings[item] = input.checked; + input.addEventListener("click", (e) => { + settings[item] = e.target.checked; + chrome.storage.local.set(settings); + localStorage.setItem(item, e.target.checked); + }) +} + +chrome.storage.local.set(settings) //Setting defaults if there are not. + diff --git a/Chrome/retrieveVariables.js b/Chrome/retrieveVariables.js index 49b079a..8735300 100644 --- a/Chrome/retrieveVariables.js +++ b/Chrome/retrieveVariables.js @@ -1,3 +1,5 @@ (async () => { - document.dispatchEvent(new CustomEvent('RetrieveVariable', { detail: "sesskey=" + window.M.cfg.sesskey })); -})(); \ No newline at end of file + if (window.M) { + document.dispatchEvent(new CustomEvent('RetrieveVariable', { detail: "sesskey=" + window.M.cfg.sesskey })); + } +})(); diff --git a/Chrome/rules.json b/Chrome/rules.json new file mode 100644 index 0000000..3206008 --- /dev/null +++ b/Chrome/rules.json @@ -0,0 +1,27 @@ +[ + { + "id": 1, + "priority": 1, + "action": { + "type": "redirect", + "redirect": { + "transform": { + "queryTransform": { + "addOrReplaceParams": [ + { + "key": "forcedownload", + "value": "0" + } + ] + } + } + } + }, + "condition": { + "urlFilter": "*://moodle.*.*/*.pdf", + "resourceTypes": [ + "main_frame" + ] + } + } +] \ No newline at end of file diff --git a/Firefox/background.js b/Firefox/background.js new file mode 100644 index 0000000..a205c41 --- /dev/null +++ b/Firefox/background.js @@ -0,0 +1,17 @@ +browser.webRequest.onBeforeRequest.addListener( + async function (details) { + let settings = await browser.storage.local.get("avoidPdfDownload"); + console.log(settings) + if (!details.url.includes("moodle") || !details.url.includes("forcedownload=1") || settings.avoidPdfDownload === false) { + return; + } + let new_url = details.url.replace("forcedownload=1","forcedownload=0"); + return { + redirectUrl: new_url + } + }, + { + urls: [""] + }, + ["blocking"] +) diff --git a/Firefox/index.js b/Firefox/index.js index cb4c42a..a85aa2d 100644 --- a/Firefox/index.js +++ b/Firefox/index.js @@ -1,5 +1,5 @@ var keepAliveIntervalId; -var keepAliveEnabled = localStorage.getItem("keepAlive") === 'true'; +var keepAliveEnabled = localStorage.getItem("keepAlive") !== 'false'; // not === true to avoid disabled by default. var moodleURLBase = '' browser.storage.local.onChanged.addListener(changes => { @@ -8,6 +8,7 @@ browser.storage.local.onChanged.addListener(changes => { if (keepAliveEnabled) { runKeepAlive(); } else { + console.log("clear") clearInterval(keepAliveIntervalId); } localStorage.setItem("keepAlive", keepAliveEnabled); @@ -21,6 +22,9 @@ if (document.URL.includes("moodle") && location.hostname !== 'moodle') { } } + + + function runKeepAlive() { wrappedJSObject.console.log("ran") if(moodleURLBase === '') { @@ -46,4 +50,4 @@ function runKeepAlive() { } }); }, 1 * 60 * 60 * 1000); -} \ No newline at end of file +} diff --git a/Firefox/manifest.json b/Firefox/manifest.json index da748bf..e966be8 100644 --- a/Firefox/manifest.json +++ b/Firefox/manifest.json @@ -1,37 +1,45 @@ { - "name": "MoodleCustomizer", - "version": "1.1.1", - "manifest_version": 2, - "browser_specific_settings": { - "gecko": { - "id": "{34ba4e89-9b36-487b-8866-a27b304f3db6}" - } - }, - "author": "Hokkaydo", - "permissions": [ - "activeTab", - "storage", - "*://*/*" - ], - "description": "Improve Moodle global experience.", - "content_scripts": [ - { - "matches": [ - "*://*/*" - ], - "js": [ - "index.js" - ] - } + "name": "MoodleCustomizer", + "version": "1.1.2", + "manifest_version": 2, + "browser_specific_settings": { + "gecko": { + "id": "{34ba4e89-9b36-487b-8866-a27b304f3db6}" + } + }, + "author": "Hokkaydo", + "permissions": [ + "activeTab", + "storage", + "webRequest", + "webRequestBlocking", + "*://*/*" + ], + "background": { + "scripts": [ + "background.js" ], - "browser_action": { - "default_icon": { - "48": "icons/logo.png" - }, - "default_title": "On/Off", - "default_popup": "popup/options.html" - }, - "icons": { - "48": "icons/logo.png" + "persistent": false + }, + "description": "Improve Moodle global experience.", + "content_scripts": [ + { + "matches": [ + "*://*/*" + ], + "js": [ + "index.js" + ] } + ], + "browser_action": { + "default_icon": { + "48": "icons/logo.png" + }, + "default_title": "On/Off", + "default_popup": "popup/options.html" + }, + "icons": { + "48": "icons/logo.png" + } } \ No newline at end of file diff --git a/Firefox/moodlecustomizer-1.1.1.zip b/Firefox/moodlecustomizer-1.1.2.zip similarity index 94% rename from Firefox/moodlecustomizer-1.1.1.zip rename to Firefox/moodlecustomizer-1.1.2.zip index e06f6eec14c499a3bae56ad0304b04355c1f3344..890d9154f0f263ef8e5bdbc1a9bc94b504ad7d4c 100644 GIT binary patch delta 4759 zcmb7I2{@Gd7yiarMp;UOBtpuTU8$@!WmkhK5m_=s%$Uq%i?5L_`^b8uOHD#o*=5aM z60$^Sk(5NzMn(L;PfbR*|GnMg;rGnr@&3+p&igy>dG*e+QN!6mtTB=m4WOW}aubpz z@I9nh0Dv110~{TW9(OrGq!64G+`JCpxB-qMn=SEg@8Iz8N%2_;AXr}_0bub5#jI{$ zgA!Nu8#$AGd1`w-MG}z1w-Mr`KUNv7DT`22Zj|A7ob~SVcvK;A>g>C@;h8yeeQ=WP z(qutkeFx7bS03*No{et_Y5r63O7>d>;#zNe=iejOZSFv<2y5|)=LJ;N0Lg_W8^aEqSow%rQ#IXpDs4xErZA|aLU|9; zj&Q#|BesA*LE0QImCg&e;m%$zXAX-$gknww*vszkNk;* z-$K8H{!jsOpv>6$tKU@s0F1GOZf3ef=?HcJA~{rHf)n0{!Dc_HZ)}FoWpx37L|h$V z5MuMJ+;$N+m)3+2g_t1sml2{BB`@<&R+9H-8bsyw(pU`ltwV$JGlns*oAzPtH6Mf; zXve?lv{prSgkLSPx%Sq4huZNZy9n3f$KE#5+d9l@xlXiM1&$Xx$aJ9}U2eed9?(@e z?Oi0)xH9Q*)D@+5)Gi+9`Maqsb*}cu<=IfK-f{2cQ8xJ!-o?4)J=Ph*Whq7T?icHVUW=WyBR(XV$PPP5D#QVM}3Z|$Invlv%_TVDDOC#ZK zv-|_sV;rZk1y2!(ttLW=^KvV^R z%KlLYp17mk&7?&E|6P>n=KT9Bn#u;xe_nG!Un4;{ z%dP&o#Mst#dS^AXGUTG%+!kVY>T6yI7c)6GKIlCIO|hp>oC!+Wm^8wP}Q%{x+y)OaHVFS+4X*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7=mte8qD@j5 z5@H`c{!@Ij5Ht5WcXC@^M&&ErEQ}R47v}xcf<)&qfVLV_hfl}(`6a& z`$QI_>9u$>f+VWNPUjIPbI`ymX4w-Px4$$iu0&|t4Ko=Mfxt_09F;l6>~Zw>kqzE> z`HXbzvCLXHn)iozyG28kqQm%^teHs*7 zkazZks!Lg9SnP9B`d{?MB(B-aQFd6)HD7ObK~kNp+DlY~IBMsGBP<|&fajacqO0OC z{Ti~x?_p%=?+53kFGq=ND|j*HaALoy6kK1b`T4GosDkKsmg3Q-q8U4|kb)BIXzRnh z8m}<|2LsAA{m+vUnOUVy^=WTRYi1eqDE6O2@BPG4&O4AuQCv%-Z!!69oT^?~=J;ZZ zp-&RY3(wWlwpHW%{AMg*3FQ)p{PzwF+$nG@rSj5P?Z^IKMjm8V`?FPMeTN3DwrI=# zmv3fE3;k%=us?s^zZb|gY5|n!b>)&1<<#;O6j*vhZTJ^y=j1tceQoIx?w|Ow%5##O z8ox&B^MLEGZ0f4ybHbd0zXk`3ud*xh&q;EM{~DRt^OFQtY5^z9Sqauy-XJK4s)2QZ y6X%q{HT)oLJ?=~aw~Q0#JgaN?Nbq``f?7JbSWE7ue+yu_6@)wh^I-XqL;eF-QJ@h3 diff --git a/Firefox/popup/options.css b/Firefox/popup/options.css index 34f2a79..185bb17 100644 --- a/Firefox/popup/options.css +++ b/Firefox/popup/options.css @@ -1,19 +1,52 @@ -.list { - background-color: white; - display: grid; - grid-template-columns: repeat(2, 1fr); - font-size: small; - font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif; +body { + width: 300px; + height: 200px; + display: flex; + flex-direction: column; + align-items: center; } -.onoff > img { - width: 70%; + + +.control { + display: flex; + align-items: center; +} +.control > p { + margin-right: 10px; + } -.list > .onoff { - display: flex; - justify-content: center; - align-items: center; - width: 50px; +input[type="checkbox"] { + position: relative; + appearance: none; + width: 37.5px; + height: 18.75px; + background: #ccc; + border-radius: 50px; + box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2); + cursor: pointer; + transition: 0.4s; +} -} \ No newline at end of file +input:checked[type="checkbox"] { + background: #7da6ff; +} + +input[type="checkbox"]::after { + position: absolute; + content: ""; + width: 18.75px; + height: 18.75px; + top: 0; + left: 0; + background: #fff; + border-radius: 50%; + box-shadow: 0 0 5px rgba(0, 0, 0, 0.2); + transform: scale(1.1); + transition: 0.4s; +} + +input:checked[type="checkbox"]::after { + left: 50%; +} diff --git a/Firefox/popup/options.html b/Firefox/popup/options.html index 723f9b4..dbab794 100644 --- a/Firefox/popup/options.html +++ b/Firefox/popup/options.html @@ -1,16 +1,29 @@ + - - - - - Document + + + + + Document + -
+

Settings:

+
+
+

Keep Alive:

+ +
+
+

Avoid PDF downloads:

+
- +
+ + + \ No newline at end of file diff --git a/Firefox/popup/options.js b/Firefox/popup/options.js index b8cd60b..2d9616f 100644 --- a/Firefox/popup/options.js +++ b/Firefox/popup/options.js @@ -1,20 +1,19 @@ -const toggleKeepAlive = document.createElement("p"); -const keepAliveOnOff = document.createElement("img"); -var keepAlive = localStorage.getItem("keepAlive") === 'true'; -keepAliveOnOff.src = browser.runtime.getURL("icons/" + (keepAlive ? "on.png" : "off.png")); -toggleKeepAlive.textContent = "KeepAlive : "; +let settings = {}; -toggleKeepAlive.addEventListener("click", (_event) => { - const keepAlive = localStorage.getItem("keepAlive") === 'true'; - localStorage.setItem("keepAlive", !keepAlive); - toggleKeepAlive.textContent = "KeepAlive : "; - keepAliveOnOff.src = browser.runtime.getURL("icons/" + (!keepAlive ? 'on.png': 'off.png')); - browser.storage.local.set({keepAlive: !keepAlive}) -}); +for (input of document.getElementsByTagName("input")) { + if (!input.type == "checkbox") { + console.log(input); + continue; + } + let item = input.dataset.item; + input.checked = localStorage.getItem(item) !== 'false'; + settings[item] = input.checked; + input.addEventListener("click", (e) => { + settings[item] = e.target.checked; + browser.storage.local.set(settings); + localStorage.setItem(item, e.target.checked); + }) +} + +browser.storage.local.set(settings) //Setting defaults if there are not. -const list = document.getElementsByClassName("list")[0] -const onoff = document.createElement("div"); -onoff.classList.add("onoff"); -onoff.appendChild(keepAliveOnOff); -list.appendChild(toggleKeepAlive); -list.appendChild(onoff); \ No newline at end of file diff --git a/README.md b/README.md index 061fb2f..0c05fde 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Improve your Moodle experience. ### Firefox - Go to [MoodleCustomizer](https://addons.mozilla.org/addon/moodlecustomizer)'s add-on page and install it from there.\ - You can also choose to use install it by yourself. \ - 1. Download [the latest firefox zip archive](https://github.com/Hokkaydo/MoodleCustomizer/blob/master/Firefox/moodlecustomizer-1.1.1.zip). + 1. Download [the latest firefox zip archive](https://github.com/Hokkaydo/MoodleCustomizer/blob/master/Firefox/moodlecustomizer-1.1.2.zip). 2. Once done, go to your extensions tab click on the settings icon in the top right corner. 3. Select "Install module from a file" 4. Go to your download location and selected the previously downloaded archive @@ -25,7 +25,9 @@ All features can be enabled or disabled by clicking on the addon icon in the top Currently supported features are : - **KeepAlive**\ This prevents Moodle from disconnecting your session while you're working and studying and long PDF or whatever else. +- **PDF Previews**\ + This prevents Moodle to force you to download pdfs, and will always preview then in your browser. ## Contribution Feel free to contribute using the [Pull Request](https://github.com/Hokkaydo/MoodleCustomizer/pulls) system. \ -You can help by suggesting new ideas in the [Issues](https://github.com/Hokkaydo/MoodleCustomizer/issues) section. \ No newline at end of file +You can help by suggesting new ideas in the [Issues](https://github.com/Hokkaydo/MoodleCustomizer/issues) section.