From 2f178f5ae8a43954196fcf41ec5598c28acbfe67 Mon Sep 17 00:00:00 2001 From: Guus van Meerveld <50501321+Guuvanmeerveld@users.noreply.github.com> Date: Tue, 2 Jun 2020 19:23:59 +0200 Subject: [PATCH] Uplaod Extension --- .gitignore | 2 + dark-mode.css | 25 +++++++++++++ js/background.js | 19 ++++++++++ js/login.js | 53 ++++++++++++++++++++++++++ js/save.js | 84 ++++++++++++++++++++++++++++++++++++++++++ manifest.json | 28 ++++++++++++++ materials-switches.css | 46 +++++++++++++++++++++++ options/index.css | 29 +++++++++++++++ options/index.html | 46 +++++++++++++++++++++++ popup/index.css | 18 +++++++++ popup/index.html | 40 ++++++++++++++++++++ 11 files changed, 390 insertions(+) create mode 100644 .gitignore create mode 100644 dark-mode.css create mode 100644 js/background.js create mode 100644 js/login.js create mode 100644 js/save.js create mode 100644 manifest.json create mode 100644 materials-switches.css create mode 100644 options/index.css create mode 100644 options/index.html create mode 100644 popup/index.css create mode 100644 popup/index.html diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..27fdd73 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +Magister Auto-Login.crx +Magister Auto-Login.pem \ No newline at end of file diff --git a/dark-mode.css b/dark-mode.css new file mode 100644 index 0000000..a669350 --- /dev/null +++ b/dark-mode.css @@ -0,0 +1,25 @@ +body { + background-color: #282a2d; +} +* { + color: #c5c5c5!important; +} + .input-group-text { + color: #fff; + background-color: #1e2226; + border-color: #383f47; +} +.form-control, .bg-light { + background-color: #22262a!important; + color: #fff!important; + border-color: #383f47; +} +.btn-primary { + background-color: #0167d4; +} +.btn-primary:hover { + background-color: #0056b2; +} +.active.btn-primary { + background-color: #0052aa!important; +} \ No newline at end of file diff --git a/js/background.js b/js/background.js new file mode 100644 index 0000000..1e79602 --- /dev/null +++ b/js/background.js @@ -0,0 +1,19 @@ +chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { + if (changeInfo.status == 'complete' && tab.active) { + chrome.tabs.executeScript(tab.ib, { + file: 'js/login.js' + }); + } +}); + +chrome.runtime.onInstalled.addListener(function () { + // open options.html + window.open('/options/index.html', '_blank'); + + chrome.storage.sync.set({ + "enabled": true + }); + chrome.browserAction.setBadgeText({ + text: 'ON' + }); +}); \ No newline at end of file diff --git a/js/login.js b/js/login.js new file mode 100644 index 0000000..c978f90 --- /dev/null +++ b/js/login.js @@ -0,0 +1,53 @@ +const d = document.getElementById.bind(document); + +// user object moet gemaakt worden vanuit chrome.storage.sync + +var snooze = ms => new Promise(res => setTimeout(res, ms)); +function login() { + chrome.storage.sync.get(['number', 'password'], async function (result) { + console.log(result); + + await waitForSel("username"); + + if (d("username") && result.number) { + d("username").value = result.number; + d("username").dispatchEvent(new Event("input")); + }; + + await waitForSel("username_submit") + if (d("username_submit")) { + d("username_submit").click(); + }; + + await waitForSel("rswp_password") + + if (d("rswp_password") && result.password) { + d("rswp_password").value = result.password; + d("rswp_password").dispatchEvent(new Event("input")); + }; + + await waitForSel("rswp_submit") + if (d("rswp_submit")) { + d("rswp_submit").click(); + }; + }); +} + +function waitForSel(s) { + return new Promise(res => { + setInterval(() => { + if (d(s)) { + res() + } + }, 10); + }); +}; + +chrome.storage.sync.get(['enabled'], function (result){ + if(result.enabled){ + login(); + }; +}); + + + diff --git a/js/save.js b/js/save.js new file mode 100644 index 0000000..7c4ed32 --- /dev/null +++ b/js/save.js @@ -0,0 +1,84 @@ +const d = document.getElementById.bind(document); +const qAll = document.querySelectorAll.bind(document); + +d("save").addEventListener("click", save); + +qAll(".login").forEach(s => { + s.addEventListener("keydown", e => { + if (e.key == "Enter") { + if (e.target.id == "number") { + d("password").focus() + }; + if (e.target.id == "password") { + save() + }; + } + }); +}); + +function save() { + + var number = d("number").value; + var password = d("password").value; + + try { + chrome.storage.sync.set({ + "number": number, + "password": password + }); + + d("save").innerHTML = "Saved!" + } catch (e) { + d("save").innerHTML = "Error" + d("save").className = "btn btn-danger float-right" + } +}; + +function onLoad() { + chrome.storage.sync.get(['number', 'password'], function (result) { + if (result.number !== undefined){ + + d("number").value = result.number + }; + + if (result.password !== undefined) { + d("password").value = result.password + }; + }); + + chrome.storage.sync.get(['enabled'], function (result) { + d("switch").checked = result.enabled + }); + + chrome.storage.sync.get(['darkmode'], function (result) { + d("dark-mode").checked = result.darkmode + d("dark-link").disabled = d("dark-mode").checked ? false : true + }); + + d("switch").addEventListener("click", toggle) + d("dark-mode").addEventListener("click", darkMode) +}; + +function toggle() { + var checked = d("switch").checked; + chrome.storage.sync.set({ + "enabled": checked + }); + + chrome.browserAction.setBadgeText({ + text: checked ? "ON" : "OFF" + }); +}; + +function darkMode() { + chrome.storage.sync.set({ + "darkmode": d("dark-mode").checked + }); + + console.log(!d("dark-mode").checked); + + d("dark-link").disabled = d("dark-mode").checked ? false : true + +} + +onLoad() \ No newline at end of file diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..27c7bb0 --- /dev/null +++ b/manifest.json @@ -0,0 +1,28 @@ +{ + "name": "Magister Auto-Login", + "version": "1.0", + "manifest_version": 2, + "description": "Auto-Login for Magister 6 webapp.", + "options_page": "options/index.html", + "homepage_url": "http://mb-o.nl/autologin", + "background": { + "scripts": [ + "js/background.js" + ], + "persistent": true + }, + "browser_action": { + "default_title": "Auto-login", + "default_popup": "/popup/index.html" + }, + // "icons": { + // "16": "/img/icon16.png", + // "32": "/img/icon32.png", + // "48": "/img/icon48.png", + // "128": "/img/icon128.png" + // }, + "permissions": [ + "https://accounts.magister.net/*", + "storage" + ] +} \ No newline at end of file diff --git a/materials-switches.css b/materials-switches.css new file mode 100644 index 0000000..a738ad6 --- /dev/null +++ b/materials-switches.css @@ -0,0 +1,46 @@ +.material-switch > input[type="checkbox"] { + display: none; +} + +.material-switch > label { + cursor: pointer; + margin-top: .8rem; + float: right; + height: 0px; + position: relative; + width: 40px; +} + +.material-switch > label::before { + background: rgb(0, 0, 0); + box-shadow: inset 0px 0px 10px rgba(0, 0, 0, 0.5); + border-radius: 8px; + content: ''; + height: 16px; + margin-top: -8px; + position:absolute; + opacity: 0.3; + transition: all 0.4s ease-in-out; + width: 40px; +} +.material-switch > label::after { + background: rgb(255, 255, 255); + border-radius: 16px; + box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.3); + content: ''; + height: 24px; + left: -4px; + margin-top: -8px; + position: absolute; + top: -4px; + transition: all 0.3s ease-in-out; + width: 24px; +} +.material-switch > input[type="checkbox"]:checked + label::before { + background: #007bff; + opacity: 0.5; +} +.material-switch > input[type="checkbox"]:checked + label::after { + background: #007bff; + left: 20px; +} \ No newline at end of file diff --git a/options/index.css b/options/index.css new file mode 100644 index 0000000..0675030 --- /dev/null +++ b/options/index.css @@ -0,0 +1,29 @@ +.screen { + width: 100vw; + height: 100vh; +} +.copyright { + position: absolute; + margin: 7px; + right: 0; + bottom: 0; +} + +.switch-span { + width: 2rem; +} +.enable { + position: absolute; + left: 1rem; + bottom: 1.7rem; +} + +.darkcheck{ + position: absolute; + margin: 7px; + right: 0px; +} + +body { + min-width: 20rem; +} \ No newline at end of file diff --git a/options/index.html b/options/index.html new file mode 100644 index 0000000..11d8f84 --- /dev/null +++ b/options/index.html @@ -0,0 +1,46 @@ + + + + + Options | Magister Auto-Login + + + + + + + + +
+
+
+

Magister Auto-Login

+ +
+ + +
+
+
+
+
+ + +
+ + +
+ +
+
+
+ +
+ + + + + + \ No newline at end of file diff --git a/popup/index.css b/popup/index.css new file mode 100644 index 0000000..92a4919 --- /dev/null +++ b/popup/index.css @@ -0,0 +1,18 @@ +body { + min-width: 20rem; + min-height: 17rem; +} + +.darkcheck{ + position: absolute; + margin: 7px; + right: 0px; +} + +.enable { + position: absolute; + bottom: 0; + left: 0; + margin-bottom: 10px; + margin-left: 20px; +} \ No newline at end of file diff --git a/popup/index.html b/popup/index.html new file mode 100644 index 0000000..3d57a07 --- /dev/null +++ b/popup/index.html @@ -0,0 +1,40 @@ + + + + + + + + + + + + +
+
+
+
+
+
+ + +
+ + +
+ +
+ + +
+
+
+
+
+ + + + + \ No newline at end of file