-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
17 changed files
with
362 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
*/web-ext-artifacts/* | ||
*/node_modules/* | ||
Chrome.crx | ||
Chrome.pem | ||
Chrome.pem | ||
Chrome/_metadata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,37 @@ | ||
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 }, | ||
files: cs.js, | ||
}); | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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": [ | ||
"<all_urls>" | ||
], | ||
"content_scripts": [ | ||
{ | ||
"matches": [ | ||
"<all_urls>" | ||
], | ||
"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": ["<all_urls>"] | ||
} | ||
"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": [ | ||
"<all_urls>" | ||
], | ||
"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": [ | ||
"<all_urls>" | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
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%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="options.css"> | ||
<title>Document</title> | ||
</head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="options.css"> | ||
<title>Document</title> | ||
</head> | ||
|
||
<body> | ||
<div class="list"> | ||
|
||
<h3>Settings:</h3> | ||
<div id="form"> | ||
<div class="control"> | ||
<p>Keep Alive:</p> | ||
<input data-item="keepAlive" type="checkbox" /> | ||
</div> | ||
<div class="control"> | ||
<p>Avoid PDF downloads:</p> | ||
<input data-item="avoidPdfDownload" type="checkbox" /> | ||
</div> | ||
<script src="options.js"></script> | ||
</div> | ||
|
||
<script src="options.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
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. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
(async () => { | ||
document.dispatchEvent(new CustomEvent('RetrieveVariable', { detail: "sesskey=" + window.M.cfg.sesskey })); | ||
})(); | ||
if (window.M) { | ||
document.dispatchEvent(new CustomEvent('RetrieveVariable', { detail: "sesskey=" + window.M.cfg.sesskey })); | ||
} | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
] | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: ["<all_urls>"] | ||
}, | ||
["blocking"] | ||
) |
Oops, something went wrong.