Compare commits

...

10 Commits

13 changed files with 4377 additions and 3207 deletions

3
.eslintignore Normal file
View File

@ -0,0 +1,3 @@
node_modules
web-ext-artifacts
vendor

20
.eslintrc.json Normal file
View File

@ -0,0 +1,20 @@
{
"env": {
"browser": true,
"es6": true,
"commonjs": true
},
"extends": [
"standard"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parserOptions": {
"ecmaVersion": 2018
},
"rules": {
"no-undef": 2
}
}

BIN
assets/icons/128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.0 KiB

View File

@ -1,44 +1,63 @@
console.log('SOMtodayn\'t background script loaded') console.log('SOMtodayn\'t background script loaded')
// Read array from local storage // Read array from local storage
function getSlogans() { function getSlogans () {
var slogans; let slogans
if (localStorage.getItem('SOMtodayntSlogans') != null) { let tonight
slogans = JSON.parse(localStorage.getItem('SOMtodayntSlogans'));
} else { if (localStorage.getItem('SOMtodayntSlogans') != null) {
var slogans = [ "Welkom bij SOMtodayn't" ] slogans = JSON.parse(localStorage.getItem('SOMtodayntSlogans'))
localStorage.setItem('SOMtodayntSlogans', JSON.stringify(slogans)); tonight = JSON.parse(localStorage.getItem('SOMtonight'))
} } else {
return slogans; slogans = ["Welkom bij SOMtodayn't"]
tonight = true
localStorage.setItem('SOMtodayntSlogans', JSON.stringify(slogans))
localStorage.setItem('SOMtonight', JSON.stringify(tonight))
}
return [
tonight,
slogans
]
} }
// Update array in local storage // Update array in local storage
function setSlogans(array) { function setSlogans (array) {
localStorage.setItem('SOMtodayntSlogans', JSON.stringify(array)); localStorage.setItem('SOMtodayntSlogans', JSON.stringify(array))
return true; return true
}
function setTonight (value) {
localStorage.setItem('SOMtonight', JSON.stringify(value))
} }
// Handle requests // Handle requests
function handleMessage(request, sender, sendResponse) { function handleMessage (request, sender, sendResponse) {
var response; let response
// DEBUG // console.log(sender); // DEBUG // console.log(sender);
// DEBUG // console.log("Request: " + request.type) // DEBUG // console.log("Request: " + request.type)
switch (request.type) { switch (request.type) {
case 'get': case 'get':
response = getSlogans(); response = getSlogans()
break; break
case 'set': case 'setSlogans':
response = setSlogans(request.value); response = setSlogans(request.value)
break; break
}
// Send response to either the content script or popup case 'setTonight':
if (sender.tab) { response = setTonight(request.value)
browser.tabs.sendMessage(sender.tab.id, response); break
} else { }
sendResponse({response: response}); // Send response to either the content script or popup
} if (sender.tab) {
// DEBUG // console.log("Response: " + response) browser.tabs.sendMessage(sender.tab.id, response)
} else {
sendResponse({
response: response
})
}
// DEBUG // console.log("Response: " + response)
} }
browser.runtime.onMessage.addListener(handleMessage); browser.runtime.onMessage.addListener(handleMessage)

236
content/css/index.css Normal file
View File

@ -0,0 +1,236 @@
/* Global styles */
body {
background-color: #121212;
}
a {
color: #01a299;
}
/* Login screen */
/* Background */
.stpanel section div#logo figure.figurelogo {
filter: grayscale(100%) brightness(400%);
}
.stpanel section {
background-color: #121212;
}
/* Marketing text */
.stpanel section div#marketing {
color: #e1e1e1;
}
/* Form container and messages */
.stpanel section div.form--holder .stpanel--error--message, .stpanel section div.form--holder form {
color: #e1e1e1;
box-shadow: unset;
background-color: #1E1E1E;
}
.stpanel .loader--dot1, .stpanel .loader--dot2, .stpanel .loader--dot3, .stpanel .loader--dot4 {
background-color: #01A299;
}
.stpanel--loader {
background-color: unset;
}
.stpanel--links a {
color: #017374;
}
.stpanel--links a:hover {
color: #00B3A6;
}
/* Slogan */
.stpanel section div#slogan span:last-of-type {
color: #01A299;
}
/* Inputs */
.stpanel .form--input input {
color: #e1e1e1;
border-color: #e1e1e1;
background-color: #383838;
}
.stpanel .form--input input:focus {
color: #ebebeb;
border-color: #70EFDE;
}
.stpanel .form--input.state-disabled input {
background-color: #01A299;
border-color: #01A299;
color: #ebebeb;
}
.stpanel .form--input i {
color: #ebebeb;
}
.stpanel .form--input i:hover {
color: #a5a5a5;
}
/* Checkbox */
.stpanel .form--checkbox:focus i, .stpanel .form--checkbox:hover i, .stpanel .form--radio:focus i, .stpanel .form--radio:hover i, .stpanel .form--select:focus select, .stpanel .form--select:hover select, .stpanel--screensaver .form--select:focus select, .stpanel--screensaver .form--select:hover select {
border-color: #01A299;
}
.stpanel .form--checkbox input + i::after{
color: #e1e1e1;
}
.stpanel .form--checkbox input:checked + i, .stpanel .form--radio input:checked + i {
background-color: #01A299;
border-color: #01A299;
}
/* Buttons */
.button--stpanel, button.button--stpanel, input[type="submit"].button--stpanel {
color: #01A299;
}
.stpanel section div#marketing a.btn, .stpanel section div.form--holder .stpanel--error--message a.button--stpanel, .stpanel section div.form--holder form a.button--stpanel, .stpanel--meldingen a.button--stpanel, .stpanel--screensaver section div.form--holder .stpanel--error--message a.button--stpanel, .stpanel--screensaver section div.form--holder form a.button--stpanel {
border-color: #01A299;
color: #01A299!important;
}
.stpanel section div#marketing a.btn:hover, .button--stpanel:active, .button--stpanel:focus, .button--stpanel:hover, .stpanel section div.form--holder .stpanel--error--message a.button--stpanel:active, .stpanel section div.form--holder .stpanel--error--message a.button--stpanel:focus, .stpanel section div.form--holder .stpanel--error--message a.button--stpanel:hover, .stpanel section div.form--holder form a.button--stpanel:active, .stpanel section div.form--holder form a.button--stpanel:focus, .stpanel section div.form--holder form a.button--stpanel:hover, .stpanel--meldingen a.button--stpanel:active, .stpanel--meldingen a.button--stpanel:focus, .stpanel--meldingen a.button--stpanel:hover, .stpanel--screensaver section div.form--holder .stpanel--error--message a.button--stpanel:active, .stpanel--screensaver section div.form--holder .stpanel--error--message a.button--stpanel:focus, .stpanel--screensaver section div.form--holder .stpanel--error--message a.button--stpanel:hover, .stpanel--screensaver section div.form--holder form a.button--stpanel:active, .stpanel--screensaver section div.form--holder form a.button--stpanel:focus, .stpanel--screensaver section div.form--holder form a.button--stpanel:hover, button.button--stpanel:active, button.button--stpanel:focus, button.button--stpanel:hover, input[type="submit"].button--stpanel:active, input[type="submit"].button--stpanel:focus, input[type="submit"].button--stpanel:hover {
background:#01A299;
color: #e1e1e1!important;
}
/* Footer */
footer > span {
color: #e1e1e1;
}
/* Main screen */
/* Header */
span.logo {
opacity: 0.75;
}
#header-wrapper {
background-color: #1E1E1E;
}
#header-wrapper a {
color: #a5a5a5!important;
}
#header-wrapper a:hover {
color: #e1e1e1!important;
opacity: 1;
}
span.header {
color: unset;
}
#user img {
display: none;
}
#user span.header {
color: unset;
}
span#inbox-counter {
background-color: #01A299;
color: #121212!important;
}
/* Content Window */
/* Main menu */
#main-menu a.active, #main-menu a.active:hover {
background-color: #01A299;
color: #e1e1e1!important;
}
#main-menu a {
background-color: #232323;
color: #a5a5a5!important;
}
#main-menu a:hover {
background-color: #292929;
color: #e1e1e1!important;
}
#main-menu-bottom {
background-color: #01A299;
}
#content {
box-shadow: unset;
}
/* Panels */
#master-panel, #master-panel .panel-header {
background-color: #1E1E1E;
border: unset;
color: #e1e1e1;
}
.panel-header h2, #detail-panel h2, #detail-panel h3 {
color: #e1e1e1;
}
#master-panel h2, h1 {
color: #e1e1e1;
}
#master-panel .sub {
color: #a5a5a5;
}
div#detail-panel-wrapper {
background-color: #232323;
}
#master-panel ~ #detail-panel-wrapper, #content {
border: unset!important;
}
/* Date and type tags */
#master-panel .date div, .pauze, .roster-table-header .day .huiswerk-items, .uurNummer, .type {
background-color: #2C2C2C!important;
color: #e1e1e1!important;
border-color: #a5a5a5!important;
}
#master-panel .date div p.date-day, #master-panel .date div p.date-month, #master-panel .date span {
color: #e1e1e1!important;
}
#master-panel .date div {
border-right: 0px !important;
margin: 0 0 0 -40px !important;
padding: 5px !important;
}
#master-panel .date div p.date-day {
background: unset;
}
/* Top-right buttons */
.ribbon .chk.checked, .ribbon .chk:hover, .ribbon.chk.checked, .yellow.ribbon a {
color:#e1e1e1;
border-bottom: 3px solid #00C4B4;
background-color: unset!important;
}
.ribbon .chk, .ribbon .chk.checked:hover{
color: #a5a5a5;
border-color: #019592;
}
.yellow.ribbon span {
color: #a5a5a5;
}
/* Box items */
.box {
background-color: #2C2C2C;
color: #e1e1e1;
border: unset;
margin-top: 5px;
}
.m-element {
color: #e1e1e1;
border: unset!important;
}
.m-element:hover {
background-color: #2C2C2C;
}
.m-wrapper.active {
margin: 0;
background:#333333;
}
.section .block {
background: #2c2c2c;
border: unset;
}
.blue.ribbon p, .blue.ribbon .icon-check, .blue.ribbon .icon-check-empty{
color: #e1e1e1 !important;
}
.huiswerkbijlage .simple-view, .section a.right {
background: #333333;
color: #e1e1e1;
border-radius: 3px;
border: unset;
}
.huiswerkbijlage .simple-view .bijlage-label, .section a.right {
color: #a5a5a5;
}
.huiswerkbijlage .simple-view:hover .bijlage-label, .section a.right:hover {
color: #e1e1e1;
background: unset;
border: unset;
}
/* Ions */
.icon-geen-van-beide, .icon-huiswerk, .icon-leermiddelen, .icon-maatregel, .icon-studiewijzer, .icon-toets {
background-color: #01A299;
color: #121212!important;
}

View File

@ -1,47 +1,63 @@
console.log('Somtoday\'nt content script active'); console.log('Somtoday\'nt content script active')
function changeSlogan(message) function changeSlogan (message) {
{ if (message === 'reload') {
// Select random slogan location.reload()
console.log(`Loaded ${message.length} slogans`); } else {
if (message.length >= 1) { const tonight = message[0]
var random = Math.floor(Math.random() * message.length); const slogans = message[1]
var sloganText = message[random].toLowerCase();
console.log(`Slogan changed to: ${sloganText}`); // Set theme
} else { console.log(tonight)
var sloganText = "welkom bij somtodayn't"; if (tonight) {
console.log('No slogans found') const cssUrl = browser.runtime.getURL('content/css/index.css')
const cssTag = `<link rel='stylesheet' href='${cssUrl}'>`
document.head.innerHTML += cssTag
} }
// Select random slogan
console.log(`Loaded ${slogans.length} slogans`)
let sloganText
if (slogans.length >= 1) {
const random = Math.floor(Math.random() * slogans.length)
sloganText = slogans[random].toLowerCase()
console.log(`Slogan changed to: ${sloganText}`)
} else {
sloganText = "welkom bij somtodayn't"
console.log('No slogans found')
}
// Split the slogan into array // Split the slogan into array
var sloganArray = sloganText.split(" "); const sloganArray = sloganText.split(' ')
var slogan = { const slogan = {
white: '', white: '',
blue: '' blue: ''
}; }
// Set the last word in the array to be blue // Set the last word in the array to be blue
if (sloganArray.length > 1) { if (sloganArray.length > 1) {
slogan.blue = sloganArray.pop(); slogan.blue = sloganArray.pop()
for (let index = 0; index < sloganArray.length; index++) { for (let index = 0; index < sloganArray.length; index++) {
slogan.white = slogan.white + sloganArray[index] + " "; slogan.white = slogan.white + sloganArray[index] + ' '
} }
} else { } else {
slogan.white = sloganArray; slogan.white = sloganArray
} }
// Edit HTML // Edit HTML
document.getElementById('slogan').innerHTML = document.getElementById('slogan').innerHTML =
`<span class="white block">${slogan.white}</span> `<span class="white block">${slogan.white}</span><span>${slogan.blue}</span>`
<span>${slogan.blue}</span>`
;
// Add a little credit // Add a little credit
document.querySelectorAll('footer > span')[0].innerHTML = "Somtodayn't is een add-on door McArn."; document.querySelectorAll('footer > span')[0].innerHTML = "Somtodayn't is een add-on door McArn."
}
} }
// Send request to background script // Send request to background script
browser.runtime.sendMessage({ type: "get"}); browser.runtime.sendMessage({
type: 'get'
})
// Receive response from background script // Receive response from background script
browser.runtime.onMessage.addListener(changeSlogan); browser.runtime.onMessage.addListener(changeSlogan)

View File

@ -2,8 +2,8 @@
"manifest_version": 2, "manifest_version": 2,
"name": "SOMtodayn't", "name": "SOMtodayn't",
"version": "1.15", "version": "1.22.0",
"author": "McArn", "author": "Arne van Iterson",
"description": "Changes the slogan on the login page of the school management system SOMtoday.", "description": "Changes the slogan on the login page of the school management system SOMtoday.",
@ -12,6 +12,11 @@
"id": "arne@arnweb.nl" "id": "arne@arnweb.nl"
} }
}, },
"permissions": [
"tabs",
"storage"
],
"icons": { "icons": {
"25" : "assets/icons/25.png", "25" : "assets/icons/25.png",
@ -21,7 +26,10 @@
"background": { "background": {
"persistent": true, "persistent": true,
"scripts": ["background/js/index.js"] "scripts": [
"vendor/browser-polyfill.js",
"background/js/index.js"
]
}, },
"browser_action": { "browser_action": {
@ -33,10 +41,17 @@
"default_popup": "popup/html/index.html" "default_popup": "popup/html/index.html"
}, },
"web_accessible_resources": [
"content/css/index.css"
],
"content_scripts": [ "content_scripts": [
{ {
"matches": ["*://*.somtoday.nl/*"], "matches": ["*://*.somtoday.nl/*"],
"js": ["content/js/index.js"] "js": [
"vendor/browser-polyfill.js",
"content/js/index.js"
]
} }
] ]

5766
package-lock.json generated

File diff suppressed because it is too large Load Diff

26
package.json Normal file
View File

@ -0,0 +1,26 @@
{
"name": "somtodaynt",
"version": "1.22.0",
"description": "Simple browser plugin for changing the slogan of SOMtoday",
"main": "./content/js/index.js",
"dependencies": {
"web-ext": "^5.4.1",
"webextension-polyfill": "^0.7.0"
},
"devDependencies": {
"eslint": "^7.15.0",
"eslint-config-standard": "^16.0.2",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "https://gitea.arnweb.nl/arne/somtodaynt.git"
},
"author": "Arne van Iterson",
"license": "ISC"
}

View File

@ -2,6 +2,7 @@
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<script type="application/javascript" src="/vendor/browser-polyfill.js"></script>
<link href="https://fonts.googleapis.com/css?family=Bree+Serif&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css?family=Bree+Serif&display=swap" rel="stylesheet">
<link rel="stylesheet" href="../css/index.css"> <link rel="stylesheet" href="../css/index.css">
</head> </head>
@ -9,16 +10,24 @@
<div> <div>
<h2>SOMtodayn't</h2> <h2>SOMtodayn't</h2>
</div> </div>
<h3>Slogan toevoegen</h3> <h3>Slogan toevoegen</h3>
<h6>Het laatste woord van de slogan wordt blauw.</h6> <h6>Het laatste woord van de slogan wordt blauw.</h6>
<form id="sloganForm"> <form id="sloganForm">
<input type="text" placeholder="Nieuwe slogan"> <input type="text" placeholder="Nieuwe slogan">
<button type="submit">Toevoegen</button> <button type="submit">Toevoegen</button>
</form> </form>
<h3>SOMtonight™</h3>
<h6>Donkere modus voor SOMtoday</h6>
<input type="checkbox" name="tonight" id="tonight">
<label for="tonight">SOMtonight™ gebruiken</label>
<h3>Bestaande slogans</h3> <h3>Bestaande slogans</h3>
<h6>Klik op een slogan om deze te verwijderen.</h6> <h6>Klik op een slogan om deze te verwijderen.</h6>
<div id="sloganList"> <div id="sloganList">
</div> </div>
<span class="footer">By McArn - 2019</span> <span class="footer">By McArn - 2019</span>
<script src="../js/index.js"></script> <script src="../js/index.js"></script>
</body> </body>

View File

@ -1,75 +1,103 @@
console.log("SOMtodayn't popup loaded."); console.log("SOMtodayn't popup loaded.")
var request; let request
var response;
// Get slogans from background script // Get slogans from background script
request = browser.runtime.sendMessage({ request = browser.runtime.sendMessage({
type: "get" type: 'get'
}); })
request.then(function(message) { request.then(function (message) {
var sloganArray = message.response; const darkmode = message.response[0]
// DEBUG // console.log(message.response); const sloganArray = message.response[1]
// Add a slogan to the array // Add a slogan to the array
function addSlogan(value) { function addSlogan (value) {
sloganArray.push(value); sloganArray.push(value)
updateSlogans(sloganArray); updateSlogans(sloganArray)
} }
// Remove a slogan from the array // Remove a slogan from the array
function removeSlogan(id) { function removeSlogan (id) {
var array = []; const array = []
if (sloganArray.length > 1) { if (sloganArray.length > 1) {
for (let index = 0; index < sloganArray.length; index++) { for (let index = 0; index < sloganArray.length; index++) {
const element = sloganArray[index]; const element = sloganArray[index]
if (index != id) { if (index !== id) {
array.push(element); array.push(element)
}
}
updateSlogans(array);
} else {
window.alert("U kunt de laatste slogan niet verwijderen.");
} }
}
updateSlogans(array)
} else {
window.alert('U kunt de laatste slogan niet verwijderen.')
} }
}
// Send updated array to background script // Send updated array to background script
function updateSlogans(array) { function updateSlogans (array) {
request = browser.runtime.sendMessage({ request = browser.runtime.sendMessage({
type: "set", type: 'setSlogans',
value: array value: array
}); })
request.then(function() { request.then(function () {
location.reload(); location.reload()
}, handleError); }, handleError)
}
// Add event listener to checkbox
const checkbox = document.getElementById('tonight')
if (darkmode) {
checkbox.checked = true
}
checkbox.addEventListener('click', function (event) {
// Update value in local storage
request = browser.runtime.sendMessage({
type: 'setTonight',
value: checkbox.checked
})
// Reload all SOMtoday tabs
const reload = browser.tabs.query({})
reload.then(logTabs, onError)
})
// Find id of somtoday.nl tab
function logTabs (tabs) {
for (const tab of tabs) {
// Match only tabs with url somtoday.nl
if (tab.url.includes('somtoday.nl')) {
browser.tabs.sendMessage(tab.id, 'reload')
}
} }
}
// Add existing slogans to list items in the popup // Handle query errors
var sloganList = ''; function onError (error) {
for (let index = 0; index < sloganArray.length; index++) { console.log(`Error: ${error}`)
const element = sloganArray[index]; }
sloganList = sloganList + `<ul>${element}</ul>`;
}
document.getElementById('sloganList').innerHTML = sloganList;
// Get value for new slogan // Add existing slogans to list items in the popup
document.getElementById('sloganForm').addEventListener('submit', function(event) { let sloganList = ''
event.preventDefault(); for (let index = 0; index < sloganArray.length; index++) {
addSlogan(event.target.children[0].value); const element = sloganArray[index]
event.target.children[0].value = ''; sloganList = sloganList + `<ul>${element}</ul>`
}); }
document.getElementById('sloganList').innerHTML = sloganList
// Add event listener to every list item for deleting slogans // Get value for new slogan
var listElements = document.querySelectorAll("div#sloganList > ul"); document.getElementById('sloganForm').addEventListener('submit', function (event) {
for (let index = 0; index < listElements.length; index++) { event.preventDefault()
const element = listElements[index]; addSlogan(event.target.children[0].value)
element.addEventListener("click", function() { event.target.children[0].value = ''
removeSlogan(index); })
});
}
}, handleError); // Add event listener to every list item for deleting slogans
const listElements = document.querySelectorAll('div#sloganList > ul')
for (let index = 0; index < listElements.length; index++) {
const element = listElements[index]
element.addEventListener('click', function () {
removeSlogan(index)
})
}
}, handleError)
function handleError(error) { function handleError (error) {
console.error(`SOMtodayn't Error: ${error}`); console.error(`SOMtodayn't Error: ${error}`)
} }

1187
vendor/browser-polyfill.js vendored Normal file

File diff suppressed because it is too large Load Diff

1
vendor/browser-polyfill.js.map vendored Normal file

File diff suppressed because one or more lines are too long