prepare for release

This commit is contained in:
SethBurkart123
2023-10-11 12:20:41 +11:00
parent 7a672b1b1b
commit 5abb0b08f6
16 changed files with 324 additions and 114 deletions
+87 -75
View File
@@ -73,10 +73,16 @@ function OpenWhatsNewPopup() {
let imagecont = document.createElement("div");
imagecont.classList.add("whatsnewImgContainer");
var image = document.createElement("img");
image.src = chrome.runtime.getURL("icons/betterseqta-dark-icon.png");
image.classList.add("whatsnewImg");
imagecont.append(image);
let video = document.createElement("video");
let source = document.createElement("source");
source.setAttribute("src", chrome.runtime.getURL("resources/update-video.mp4"));
source.setAttribute("type", "video/mp4");
video.autoplay = true;
video.muted = true;
video.loop = true;
video.appendChild(source);
video.classList.add("whatsnewImg");
imagecont.appendChild(video);
let textcontainer = document.createElement("div");
textcontainer.classList.add("whatsnewTextContainer");
@@ -91,7 +97,8 @@ function OpenWhatsNewPopup() {
<div class="whatsnewTextContainer" style="height: 50%;overflow-y: scroll;">
<li>Custom backgrounds and themes coming soon!</li>
<h1>3.1.2 - New settings menu!</h1>
<li>Overhauled the settings menu!!!</li>
<li>Overhauled the settings menu</li>
<li>Added custom gradients</li>
<h1>3.1.1 - Minor Bug fixes</h1>
<li>Fixed assessments overlapping</li>
<li>Fixed houses not displaying if they aren't a specific color</li>
@@ -199,7 +206,7 @@ async function DeleteWhatsNew() {
popup.remove();
}
function CreateBackground() {
export function CreateBackground() {
// Creating and inserting 3 divs containing the background applied to the pages
var bklocation = document.getElementById("container");
var menu = document.getElementById("menu");
@@ -219,7 +226,7 @@ function CreateBackground() {
bklocation.insertBefore(bk3, menu);
}
function RemoveBackground() {
export function RemoveBackground() {
var bk = document.getElementsByClassName("bg");
var bk2 = document.getElementsByClassName("bg2");
var bk3 = document.getElementsByClassName("bg3");
@@ -780,6 +787,12 @@ document.addEventListener(
);
function addExtensionSettings() {
let link = document.createElement("link");
link.href = chrome.runtime.getURL("popup/popup.css");
link.type = "text/css";
link.rel = "stylesheet";
document.getElementsByTagName("html")[0].appendChild(link);
let Settings =
stringToHTML(
String.raw`
@@ -852,7 +865,6 @@ function dragDrop() {
// Save position of all menu items
let children = parentA.childNodes;
// console.log(children)
let listorder = [];
for (let i = 0; i < children.length; i++) {
@@ -1206,7 +1218,6 @@ function AddBetterSEQTAElements(toggle) {
houseelement.innerText =
students[index].year + students[index].house;
} catch (error) {
console.log(students[index]);
houseelement.innerText = students[index].house;
}
} else {
@@ -1264,9 +1275,8 @@ function AddBetterSEQTAElements(toggle) {
SendNewsPage();
}
});
}
appendBackgroundToUI();
addExtensionSettings();
@@ -1611,7 +1621,6 @@ function callHomeTimetable(date, change) {
// If items in response:
if (serverResponse.payload.items.length > 0) {
if (!DayContainer.innerText || change) {
// console.log(serverResponse.payload.items.length);
for (let i = 0; i < serverResponse.payload.items.length; i++) {
lessonArray.push(serverResponse.payload.items[i]);
}
@@ -2099,7 +2108,7 @@ chrome.storage.onChanged.addListener(function (changes) {
}
});
function GetLessonColours() {
async function GetLessonColours() {
let func = fetch(`${location.origin}/seqta/student/load/prefs?`, {
method: "POST",
headers: {
@@ -2148,17 +2157,25 @@ export function CreateCustomShortcutDiv(element) {
document.getElementById("shortcuts").append(shortcut);
}
export function RemoveCustomShortcutDiv(element) {
// Iterate through each shortcut
const shortcuts = document.querySelectorAll(".shortcut");
shortcuts.forEach((shortcut) => {
const anchorElement = shortcut.parentElement; // the <a> element is the parent
const textElement = shortcut.querySelector("p"); // <p> is a direct child of .shortcut
const title = textElement ? textElement.textContent : "";
if (anchorElement.getAttribute("href") === element.url && title === element.name) {
anchorElement.remove();
}
export function RemoveShortcutDiv(elements) {
elements.forEach((element) => {
const shortcuts = document.querySelectorAll(".shortcut");
shortcuts.forEach((shortcut) => {
const anchorElement = shortcut.parentElement; // the <a> element is the parent
const textElement = shortcut.querySelector("p"); // <p> is a direct child of .shortcut
const title = textElement ? textElement.textContent : "";
let shouldRemove = title === element.name;
// Check href only if element.url exists
if (element.url) {
shouldRemove = shouldRemove && (anchorElement.getAttribute("href") === element.url);
}
if (shouldRemove) {
anchorElement.remove();
}
});
});
}
@@ -2282,57 +2299,10 @@ function SendHomePage() {
changeTimetable(1);
});
function createNewShortcut(link, icon, viewBox, title) {
// Creates the stucture and element information for each seperate shortcut
var shortcut = document.createElement("a");
shortcut.setAttribute("href", link);
shortcut.setAttribute("target", "_blank");
var shortcutdiv = document.createElement("div");
shortcutdiv.classList.add("shortcut");
let image = stringToHTML(
`<svg style="width:39px;height:39px" viewBox="${viewBox}"><path fill="currentColor" d="${icon}" /></svg>`,
).firstChild;
image.classList.add("shortcuticondiv");
var text = document.createElement("p");
text.textContent = title;
shortcutdiv.append(image);
shortcutdiv.append(text);
shortcut.append(shortcutdiv);
document.getElementById("shortcuts").append(shortcut);
}
// Adds the shortcuts to the shortcut container
chrome.storage.local.get(["shortcuts"], function (result) {
var shortcuts = Object.values(result)[0];
for (let i = 0; i < shortcuts.length; i++) {
const currentShortcut = shortcuts[i];
if (currentShortcut?.enabled) {
const Itemname = currentShortcut?.name;
const linkDetails = ShortcutLinks?.[Itemname];
if (linkDetails) {
createNewShortcut(
linkDetails.link,
linkDetails.icon,
linkDetails.viewBox,
Itemname
);
} else {
console.warn(`No link details found for '${Itemname}'`);
}
}
}
AddCustomShortcutsToPage();
// Checks if shortcut container is empty
if (document.getElementById("shortcuts").childElementCount == 0) {
// If there are no shortcuts, hide the container
document.getElementsByClassName("shortcut-container")[0].style.display =
"none";
}
const shortcuts = Object.values(result)[0];
addShortcuts(shortcuts);
});
// Creates the upcoming container and appends to the home container
@@ -2462,7 +2432,6 @@ function SendHomePage() {
enableNotificationCollector();
}
});
console.log("Getting assessments");
let activeClassList;
GetUpcomingAssessments().then((assessments) => {
GetActiveClasses().then((classes) => {
@@ -2494,7 +2463,6 @@ function SendHomePage() {
}
CurrentAssessments.sort(comparedate);
console.log(CurrentAssessments, activeSubjects);
CreateUpcomingSection(CurrentAssessments, activeSubjects);
@@ -2504,6 +2472,29 @@ function SendHomePage() {
}, 8);
}
export function addShortcuts(shortcuts) {
for (let i = 0; i < shortcuts.length; i++) {
const currentShortcut = shortcuts[i];
if (currentShortcut?.enabled) {
const Itemname = currentShortcut?.name.replace(/\s/g, "");
const linkDetails = ShortcutLinks?.[Itemname];
if (linkDetails) {
createNewShortcut(
linkDetails.link,
linkDetails.icon,
linkDetails.viewBox,
currentShortcut?.name
);
} else {
console.warn(`No link details found for '${Itemname}'`);
}
}
}
AddCustomShortcutsToPage();
}
export function enableNotificationCollector() {
var xhr3 = new XMLHttpRequest();
xhr3.open("POST", `${location.origin}/seqta/student/heartbeat?`, true);
@@ -2544,6 +2535,27 @@ export function disableNotificationCollector() {
}
}
function createNewShortcut(link, icon, viewBox, title) {
// Creates the stucture and element information for each seperate shortcut
let shortcut = document.createElement("a");
shortcut.setAttribute("href", link);
shortcut.setAttribute("target", "_blank");
let shortcutdiv = document.createElement("div");
shortcutdiv.classList.add("shortcut");
let image = stringToHTML(
`<svg style="width:39px;height:39px" viewBox="${viewBox}"><path fill="currentColor" d="${icon}" /></svg>`,
).firstChild;
image.classList.add("shortcuticondiv");
let text = document.createElement("p");
text.textContent = title;
shortcutdiv.append(image);
shortcutdiv.append(text);
shortcut.append(shortcutdiv);
document.getElementById("shortcuts").appendChild(shortcut);
}
function SendNewsPage() {
setTimeout(function () {
// Sends the html data for the home page
+5 -23
View File
@@ -20,16 +20,12 @@ export const openDB = () => {
};
export const writeData = async (type, data) => {
console.log("Reading Data");
const db = await openDB();
console.log("Opened DB");
const tx = db.transaction("backgrounds", "readwrite");
const store = tx.objectStore("backgrounds");
const request = await store.put({ id: "customBackground", type, data });
console.log("Data written successfully");
return request.result;
};
@@ -37,17 +33,14 @@ export const readData = () => {
return new Promise((resolve, reject) => {
openDB()
.then(db => {
console.log("Database, typeof", typeof db, "Is: ", db);
const tx = db.transaction("backgrounds", "readonly");
const store = tx.objectStore("backgrounds");
console.log("Current store: ", store);
// Retrieve the custom background
const getRequest = store.get("customBackground");
// Attach success and error event handlers
getRequest.onsuccess = function(event) {
console.log("CustomBackground", event.target.result);
resolve(event.target.result);
};
@@ -99,8 +92,6 @@ const handleAddPermissions = () => {
// Main message listener
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
console.log("Message received in background script", request);
switch (request.type) {
case "reloadTabs":
ReloadSEQTAPages();
@@ -115,7 +106,6 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
break;
case "setDefaultStorage":
console.log("Setting default values");
SetStorageValue(DefaultValues);
break;
@@ -156,9 +146,6 @@ function HandleIntexedDB(request, sendResponse) {
function GetNews(sendResponse) {
// Gets the current date
const date = new Date();
// Formats the current date used send a request for timetable and notices later
const TodayFormatted =
date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate();
const from =
date.getFullYear() +
@@ -166,12 +153,9 @@ function GetNews(sendResponse) {
(date.getMonth() + 1) +
"-" +
(date.getDate() - 1);
console.log(TodayFormatted);
console.log(from);
let url = `https://newsapi.org/v2/everything?domains=abc.net.au&from=${from}&apiKey=17c0da766ba347c89d094449504e3080`;
console.log("Fetching news from " + url);
fetch(url)
.then((result) => result.json())
.then((response) => {
@@ -179,7 +163,6 @@ function GetNews(sendResponse) {
url += "%00";
GetNews();
} else {
console.log(response);
sendResponse({ news: response });
}
});
@@ -244,7 +227,7 @@ const DefaultValues = {
},
{
name: "Education Perfect",
enabled: true,
enabled: false,
},
],
customshortcuts: [],
@@ -256,9 +239,7 @@ function SetStorageValue(object) {
}
}
function UpdateCurrentValues(details) {
console.log(details);
function UpdateCurrentValues() {
chrome.storage.local.get(null, function (items) {
var CurrentValues = items;
@@ -310,9 +291,9 @@ function migrateOldStorage() {
// Check for "educationperfect" and convert it to "Education Perfect"
if (items.shortcuts && items.shortcuts.length > 0) {
for (let shortcut of items.shortcuts) {
if (shortcut.name === "educationperfect") {
if (shortcut.name === "educationperfect" || shortcut.name === "Education Perfect") {
shouldUpdate = true;
shortcut.name = "Education Perfect"; // Convert to "Education Perfect"
shortcut.name = "Education Perfect";
}
}
}
@@ -329,6 +310,7 @@ function migrateOldStorage() {
chrome.runtime.onInstalled.addListener(function (event) {
chrome.storage.local.remove(["justupdated"]);
UpdateCurrentValues();
chrome.storage.local.set({ justupdated: true });
if ( event.reason == "install" ) {
chrome.storage.local.set({ justupdated: true });
migrateOldStorage();
+3 -4
View File
@@ -2825,16 +2825,15 @@ body {
.whatsnewImgContainer {
width: 96%;
display: flex;
padding: 2em 0;
margin: 0 auto;
background: #141414;
border-radius: 10px;
margin-bottom: 20px;
}
.whatsnewImg {
margin: 0 auto;
width: 30%;
margin: 0.5rem 0.5rem;
width: 90%;
border-radius: 1rem;
}
.whatsnewTextContainer {
+5
View File
@@ -53,5 +53,10 @@
"link": "https://netflix.com",
"viewBox": "0 0 24 24",
"icon": "M6.5,2H10.5L13.44,10.83L13.5,2H17.5V22C16.25,21.78 14.87,21.64 13.41,21.58L10.5,13L10.43,21.59C9.03,21.65 7.7,21.79 6.5,22V2Z"
},
"EducationPerfect": {
"link": "https://app.educationperfect.com/",
"viewBox": "4.425358206338695 10.109853742009532 167.75614842212613 167.76529918293508",
"icon": "M 41.218842,159.903778 C 32.220757000000006,154.49694799999997 28.320898,146.39567599999998 27.144720000000003,136.691025 C 24.344646000000004,113.587677 21.58695,90.479164 18.767124000000003,67.378227 C 16.473593,48.588874999999994 27.314493000000002,35.167511 46.150131,33.008185999999995 C 69.436394,30.338643999999995 92.70422400000001,27.486617999999993 115.943047,24.432179999999995 C 132.274689,22.285605999999994 146.786301,32.505539 148.981033,48.8368 C 152.235703,73.05532099999999 155.27562,97.309608 157.905701,121.602943 C 159.93542499999998,140.350937 148.836945,152.964386 130.02818299999998,155.067184 C 107.06863399999999,157.634018 84.15766899999998,160.637604 61.23078899999999,163.49321 C 54.302176999999986,164.35621600000002 47.67153899999999,163.743561 41.21884199999999,159.90377800000002 M 90.16155199999999,104.49991600000001 C 90.16451299999999,111.81823700000001 90.16574099999998,119.136559 90.17105099999999,126.45488000000002 C 90.17446899999999,131.15861500000003 93.67040999999999,130.323944 96.55354299999999,130.48759500000003 C 99.573128,130.65899700000003 101.204872,129.66064500000002 101.05652599999999,126.23024700000002 C 100.843948,121.31488000000002 101.00233499999999,116.38347600000002 101.00233499999999,110.84864000000002 C 102.03786499999998,111.51373300000002 102.54609699999999,111.83288600000002 103.04710399999999,112.16302500000002 C 112.86791199999999,118.63465100000002 124.983047,115.43300600000002 129.53965799999997,104.62981400000002 C 131.216278,100.65472400000003 131.70472699999996,95.99940500000002 131.89942899999997,91.61723300000003 C 132.25656099999998,83.57922400000002 129.14271499999998,76.85495800000002 121.90178699999997,72.91539800000002 C 114.83421299999998,69.07015200000002 107.87258899999998,70.25764500000002 101.40912599999997,75.00357800000002 C 100.15898099999997,69.73184200000001 95.94058999999997,71.49647500000002 92.94792199999998,71.84281900000002 C 91.83303799999997,71.97184800000002 90.34555799999998,75.20201900000002 90.28659099999997,77.05806700000002 C 90.00683599999998,85.86446400000003 90.16157499999997,94.68465400000002 90.16155199999997,104.49991600000003 M 47.135135999999974,102.84149200000003 C 47.50462699999997,103.58536500000002 47.86649299999998,104.33315300000002 48.24474299999997,105.07254000000003 C 55.63482299999997,119.51831800000004 75.42236299999998,117.51798200000003 83.29843899999997,107.84790800000003 C 84.09340699999997,106.87186400000003 84.45175199999997,105.03819300000004 84.12631199999997,103.84413100000003 C 83.93784299999997,103.15265700000003 81.92327899999997,102.47944600000004 80.82456999999997,102.60716200000003 C 77.76956899999996,102.96225700000004 74.59602399999997,103.31630700000004 71.77092699999997,104.43350200000003 C 64.22663099999997,107.41690800000003 57.34320099999997,104.57150300000004 57.25969299999997,97.83805100000004 C 65.24485799999997,97.83805100000004 73.23475599999998,97.99984700000003 81.20797699999997,97.70718400000004 C 82.88577299999997,97.64559900000005 85.63535299999997,96.20201100000004 85.96279899999998,94.90748600000003 C 88.05384099999998,86.64054900000004 82.07756799999997,75.75166300000004 74.07153299999997,72.37247500000004 C 64.91693899999997,68.50850700000004 54.85903499999998,71.43896500000004 49.47143599999997,79.54177900000003 C 44.77263999999997,86.60865000000004 45.10080699999997,94.24294300000004 47.13513599999997,102.84149200000003 L 47.135135999999974,102.84149200000003 M 47.035309,102.444016 C 45.100806999999996,94.24294300000001 44.772639999999996,86.60865000000001 49.471436,79.541779 C 54.859035,71.43896500000001 64.916939,68.50850700000001 74.071533,72.37247500000001 C 82.077568,75.75166300000001 88.053841,86.64054900000001 85.962799,94.907486 C 85.63535300000001,96.202011 82.885773,97.645599 81.207977,97.70718400000001 C 73.234756,97.99984700000002 65.244858,97.83805100000001 57.259693,97.83805100000001 C 57.343201,104.571503 64.226631,107.416908 71.770927,104.433502 C 74.596024,103.31630700000001 77.769569,102.96225700000001 80.82457,102.607162 C 81.923279,102.479446 83.937843,103.152657 84.126312,103.844131 C 84.451752,105.038193 84.093407,106.871864 83.298439,107.847908 C 75.422363,117.517982 55.634823,119.51831800000001 48.244743,105.07254 C 47.866493,104.33315300000001 47.504627,103.58536500000001 47.035309,102.444016 M 68.89061,81.05638900000001 C 60.57823199999999,80.556335 57.77417799999999,82.19622000000001 57.24161899999999,88.020081 L 74.64141099999999,88.020081 C 74.94538899999999,87.678658 75.24935899999998,87.337227 75.55333699999998,86.995804 C 73.60168499999999,85.07057200000001 71.65003199999998,83.14534800000001 68.89060999999998,81.05638900000001 L 68.89061,81.05638900000001"
}
}
+8 -5
View File
@@ -4,14 +4,17 @@
* @param {number} [minDuration=1] - The minimum animation duration in seconds.
* @param {number} [maxDuration=10] - The maximum animation duration in seconds.
*/
export function updateBgDurations(item, minDuration = 1, maxDuration = 10) {
export function updateBgDurations(speed, minDuration = 0.5, maxDuration = 10) {
// Class names to look for
const bgClasses = ["bg", "bg2", "bg3"];
// Reverse the slider direction to align with the animation
const reversedValue = 150 - item.bksliderinput;
let reversedValue;
console.log("reversedValue:", reversedValue);
if (speed.bksliderinput === undefined) {
// Reverse the slider direction to align with the animation
reversedValue = 150 - speed;
} else {
reversedValue = 150 - speed.bksliderinput;
}
// Range of possible animation durations
const durationRange = maxDuration - minDuration;
+59 -2
View File
@@ -1,11 +1,15 @@
/* global chrome */
import {
CreateBackground,
CreateCustomShortcutDiv,
RemoveCustomShortcutDiv,
RemoveBackground,
RemoveShortcutDiv,
addShortcuts,
disableNotificationCollector,
enableNotificationCollector,
} from "../../SEQTA.js";
import { updateBgDurations } from "../ui/Animation.js";
import { updateAllColors } from "../ui/Colors.js";
export default class StorageListener {
@@ -18,6 +22,13 @@ export default class StorageListener {
this.handleSelectedColorChange(changes.selectedColor.newValue);
}
if (changes.shortcuts) {
this.handleShortcutsChange(
changes.shortcuts.oldValue,
changes.shortcuts.newValue
);
}
if (changes?.customshortcuts?.newValue) {
this.handleCustomShortcutsChange(
changes.customshortcuts.oldValue,
@@ -28,6 +39,19 @@ export default class StorageListener {
if (changes.notificationcollector) {
this.handleNotificationCollectorChange(changes.notificationcollector);
}
if (changes.bksliderinput) {
updateBgDurations(changes.bksliderinput.newValue);
}
if (changes.animatedbk !== undefined) {
if (changes.animatedbk.newValue) {
CreateBackground();
} else {
RemoveBackground();
document.getElementById("container").style.background = "var(--background-secondary)";
}
}
}
handleSelectedColorChange(newColor) {
@@ -61,8 +85,41 @@ export default class StorageListener {
);
if (removedElement) {
RemoveCustomShortcutDiv(removedElement);
RemoveShortcutDiv(removedElement);
}
}
}
handleShortcutsChange(oldValue, newValue) {
// Find Added Shortcuts
const addedShortcuts = newValue.filter(newItem => {
const isAdded = oldValue.some(oldItem => {
const match = oldItem.name === newItem.name;
const wasDisabled = !oldItem.enabled;
const isEnabled = newItem.enabled;
return match && wasDisabled && isEnabled;
});
return isAdded;
});
// Find Removed Shortcuts
const removedShortcuts = newValue.filter(newItem => {
const isRemoved = oldValue.some(oldItem => {
const match = oldItem.name === newItem.name;
const wasEnabled = oldItem.enabled; // Was enabled in the old array
const isDisabled = !newItem.enabled; // Is disabled in the new array
return match && wasEnabled && isDisabled;
});
return isRemoved;
});
// Add new shortcuts to the UI
addShortcuts(addedShortcuts);
// Remove deleted shortcuts from the UI
RemoveShortcutDiv(removedShortcuts);
}
}