Skip to content

Commit

Permalink
Added nextCoursesPanel
Browse files Browse the repository at this point in the history
  • Loading branch information
coderesting committed May 18, 2021
1 parent 372e8e2 commit 637602d
Show file tree
Hide file tree
Showing 12 changed files with 710 additions and 37 deletions.
4 changes: 3 additions & 1 deletion NAKExtension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@
{
"matches": ["*://moodle2.nordakademie.de/*"],
"js": [
"scripts/storage.js",
"scripts/enhanceMoodle/ical.js",
"scripts/enhanceMoodle/fillSidebar.js",
"scripts/enhanceMoodle/showCurrentCourse.js",
"scripts/enhanceMoodle/nextCoursesPanel.js",
"scripts/enhanceMoodle/showNextCourses.js",
"scripts/enhanceMoodle/main.js"
],
"css": ["scripts/enhanceMoodle/styles.css"]
Expand Down
20 changes: 18 additions & 2 deletions NAKExtension/options/options.html
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
<!DOCTYPE html>
<html>
<body>
<h2>Auto Login (Cis/Moodle/Owa)</h2>
<div class="input">
<span> CIS/Moodle username: </span>
<span> username: </span>
<input type="text" id="username" />
</div>

<div class="input">
<span> CIS/Moodle password:</span>
<span> password:</span>
<input type="password" id="password" />
</div>

<h2>Show next courses in Moodle</h2>
<div class="input">
<span> centuria: </span>
<input type="text" id="centuria" />
</div>

<div class="input">
<span> semester:</span>
<input type="number" id="semester" />
</div>

<div class="input submit">
<button id="save">Save</button>
<div id="status"></div>
</div>

<style>
span {
font-size: 13px;
}
.input {
display: flex;
justify-content: space-between;
Expand All @@ -32,6 +47,7 @@
}
</style>

<script src="../scripts/storage.js"></script>
<script src="options.js"></script>
</body>
</html>
73 changes: 45 additions & 28 deletions NAKExtension/options/options.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
function save_options() {
var username = document.getElementById("username").value;
var password = document.getElementById("password").value;
chrome.storage.local.set(
{
username,
password,
},
function () {
var status = document.getElementById("status");
status.textContent = "Options saved locally.";
setTimeout(function () {
status.textContent = "";
}, 750);
}
);
}
class Options {
constructor() {
this.usernameInput = document.getElementById("username");
this.passwordInput = document.getElementById("password");
this.centuriaInput = document.getElementById("centuria");
this.semesterInput = document.getElementById("semester");

this.statusElm = document.getElementById("status");
}

async save() {
await setData({
username: this.usernameInput.value,
password: this.passwordInput.value,
centuria: this.centuriaInput.value,
semester: this.semesterInput.value,
});

this.statusElm.textContent = "Options saved locally.";
setTimeout(() => {
this.statusElm.textContent = "";
}, 750);
}

function restore_options() {
chrome.storage.local.get(
{
async load() {
const { username, password, centuria, semester } = await getData({
username: "",
password: "",
},
function (items) {
document.getElementById("username").value = items.username;
document.getElementById("password").value = items.password;
}
);
centuria: "",
semester: "",
});

this.usernameInput.value = username;
this.passwordInput.value = password;
this.centuriaInput.value = centuria;
this.semesterInput.value = semester;
}
}

function init() {
const options = new Options();
options.load();
const saveButton = document.getElementById("save");
saveButton.addEventListener("click", options.save.bind(options));
}
document.addEventListener("DOMContentLoaded", restore_options);
document.getElementById("save").addEventListener("click", save_options);

if (document.readyState === "loading")
document.addEventListener("DOMContentLoaded", init);
else init();
1 change: 0 additions & 1 deletion NAKExtension/scripts/autoLogin/clicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async function attemptLogin(usernameInput, passwordInput, loginButton) {
}

if (Date.now() - lastTry > 10000) {
console.log("auto login");
await setData({ lastTry: Date.now() });
loginButton.click();
} else {
Expand Down
1 change: 0 additions & 1 deletion NAKExtension/scripts/enhanceMoodle/fillSidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ async function fillSidebar() {
if (!courseAlreadyExists(course.href)) {
const courseElm = createCourseElm(course.title, course.href);
nav.insertBefore(courseElm, moreButton);
console.log("added: " + course.title);
}
}
}
Expand Down
Loading

0 comments on commit 637602d

Please sign in to comment.