Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
hokkaydo committed Jan 11, 2023
1 parent 0e6913f commit 80f1ced
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/web-ext-artifacts/*
/node_modules/*
Binary file added icons/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
if (document.URL.includes("moodle") && location.hostname !== 'moodle') {
var keepAliveIntervalId = runKeepAlive();
browser.runtime.onMessage.addListener(message => {
if(message.command === "toggle") {
if(message.feature === "keepAlive") {
if(keepAliveIntervalId !== -1) {
clearInterval(keepAliveIntervalId);
keepAliveIntervalId = -1;
}else {
keepAliveIntervalId = runKeepAlive();
}
}
}
});
}

function runKeepAlive() {
return setInterval(() => {
const fetchOptions =
{
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: '[{"index":0,"methodname":"core_session_touch","args":{}}]'
}
fetch("https://moodle.uclouvain.be/lib/ajax/service.php?sesskey=" + wrappedJSObject.M.cfg.sesskey, fetchOptions)
.then(body => body.json())
.then(body => {
body = body[0];
if (body.error) {
const err = body.exception;
console.error("An error occured while trying to keep Moodle session alive : " + err.message + "\n Error code : " + err.errorcode);
}
});
}, 1*60*60*1000);
}
36 changes: 36 additions & 0 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "MoodleCustomizer",
"version": "1.1.0",
"manifest_version": 2,
"author": "Hokkaydo",
"permissions": [
"activeTab",
"https://moodle.uclouvain.be/"
],
"description": "Improve Moodle global experience.",
"content_scripts": [
{
"matches": [
"*://*/*"
],
"js": [
"index.js"
]
}
],
"options_ui": {
"page": "options.html",
"browser_style": true,
"chrome_style": true
},
"browser_action": {
"default_icon": {
"48": "icons/logo.png"
},
"default_title": "On/Off",
"default_popup": "popup/options.html"
},
"icons": {
"48": "icons/logo.png"
}
}
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"dependencies": {
"web-ext": "^0.0.1"
}
}
19 changes: 19 additions & 0 deletions popup/options.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.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;
}

.onoff > img {
width: 70%;
}

.list > .onoff {
display: flex;
justify-content: center;
align-items: center;
width: 50px;

}
16 changes: 16 additions & 0 deletions popup/options.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!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>
<body>
<div class="list">

</div>
<script src="options.js"></script>
</body>
</html>
24 changes: 24 additions & 0 deletions popup/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
const icons = {
on: "icons/on.png",
off: "icons/off.png"
};

const toggleKeepAlive = document.createElement("p");
const keepAliveOnOff = document.createElement("img");
keepAliveOnOff.src = browser.runtime.getURL("icons/on.png");
toggleKeepAlive.textContent = "KeepAlive : "
var keepAlive = true;
toggleKeepAlive.addEventListener("click", (event) => {
keepAlive = !keepAlive;
toggleKeepAlive.textContent = "KeepAlive : ";
keepAliveOnOff.src = browser.runtime.getURL("icons/" + (keepAlive ? "on.png" : "off.png"));
browser.tabs.query({active: true, currentWindow: true}).then(tabs => {
browser.tabs.sendMessage(tabs[0].id, {command: "toggle", feature: "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);

0 comments on commit 80f1ced

Please sign in to comment.