From 84f660340e057f79569ceaba1b8b61d1c3561468 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Fri, 17 Nov 2023 07:10:10 +1100 Subject: [PATCH 1/7] working firefox --- public/backgrounds/background.html | 1 + public/manifest.json | 104 ++++++++++----------------- src/SEQTA.js | 111 +++++++++++++++-------------- src/background.js | 37 +++++----- 4 files changed, 113 insertions(+), 140 deletions(-) diff --git a/public/backgrounds/background.html b/public/backgrounds/background.html index b7fd1faf..e6561a62 100644 --- a/public/backgrounds/background.html +++ b/public/backgrounds/background.html @@ -19,6 +19,7 @@ object-fit: cover; } + diff --git a/public/manifest.json b/public/manifest.json index 1ae9889c..310432a1 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,79 +1,49 @@ { - "manifest_version": 3, + "manifest_version": 2, "name": "BetterSEQTA+", "version": "3.2.0", - "description": "Make SEQTA usable and beautiful! A fork of BetterSEQTA to continue development and add WAY more features!!!", + "description": "A dark-themed Firefox/Chrome Extension that adds additional features and gives an overall better experience for SEQTA Learn.", "icons": { - "32": "icons/icon-32.png", - "48": "icons/icon-48.png", - "64": "icons/icon-64.png" + "48": "icons/icon-48.png" }, - "action": { - "browser_style": true, - "default_popup": "popup/info.html", - "default_icon": { - "32": "icons/icon-32.png", - "48": "icons/icon-48.png", - "64": "icons/icon-64.png" - } + "browser_action": { + "browser_style": true, + "default_popup": "popup/info.html", + "default_icon": { + "32": "icons/icon-32.png", + "64": "icons/icon-64.png" + } }, - "permissions": ["tabs", "notifications", "storage"], - "host_permissions": ["https://newsapi.org/", "*://*/*"], + "permissions": [ + "tabs", + "notifications", + "storage", + "https://newsapi.org/" + ], "background": { - "service_worker": "background.js" + "scripts": [ + "background.js" + ] }, - "optional_permissions": ["declarativeContent"], + "optional_permissions": [ + "*://*/*", + "declarativeContent" + ], "content_scripts": [ - { - "matches": ["https://*.edu.au/*"], - "js": ["purify.min.js", "SEQTA.js"], - "run_at": "document_start" - } + { + "matches": [ + "https://*.edu.au/*" + ], + "js": [ + "SEQTA.js" + ], + "run_at": "document_start" + } ], "web_accessible_resources": [ - { - "resources": ["icons/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["fonts/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["images/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["css/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["popup/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["client.js"], - "matches": ["*://*/*"] - }, - { - "resources": ["index.css"], - "matches": ["*://*/*"] - }, - { - "resources": ["interface/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["client/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["resources/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["backgrounds/*"], - "matches": ["*://*/*"] - } + "icons/*", + "images/*", + "inject/*", + "popup/*" ] -} +} \ No newline at end of file diff --git a/src/SEQTA.js b/src/SEQTA.js index 126a2aa4..18cc567c 100644 --- a/src/SEQTA.js +++ b/src/SEQTA.js @@ -1,4 +1,5 @@ -/* global chrome */ +import browser from 'webextension-polyfill'; + import { animate, spring, stagger } from 'motion'; import Color from 'color'; @@ -44,13 +45,13 @@ document.addEventListener( console.log('[BetterSEQTA+] Verified SEQTA Page'); let link = document.createElement('link'); - link.href = chrome.runtime.getURL('css/documentload.css'); + link.href = browser.runtime.getURL('css/documentload.css'); link.type = 'text/css'; link.rel = 'stylesheet'; document.getElementsByTagName('html')[0].appendChild(link); enableCurrentTheme(); - chrome.storage.local.get(null, function (items) { + browser.storage.local.get(null, function (items) { main(items); }); } @@ -83,7 +84,7 @@ function animbkEnable(item) { export function ApplyCSSToHiddenMenuItems() { var stylesheetInnerText = ''; - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { for (let i = 0; i < Object.keys(result.menuitems).length; i++) { if (!Object.values(result.menuitems)[i].toggle) { stylesheetInnerText += SetDisplayNone(Object.keys(result.menuitems)[i]); @@ -110,14 +111,14 @@ function OpenWhatsNewPopup() { var header = stringToHTML(`

What's New

-

BetterSEQTA+ V${chrome.runtime.getManifest().version}

+

BetterSEQTA+ V${browser.runtime.getManifest().version}

`).firstChild; let imagecont = document.createElement('div'); imagecont.classList.add('whatsnewImgContainer'); let video = document.createElement('video'); let source = document.createElement('source'); - source.setAttribute('src', chrome.runtime.getURL('resources/update-video.mp4')); + source.setAttribute('src', browser.runtime.getURL('resources/update-video.mp4')); source.setAttribute('type', 'video/mp4'); video.autoplay = true; video.muted = true; @@ -211,7 +212,7 @@ function OpenWhatsNewPopup() { - + @@ -253,7 +254,7 @@ function OpenWhatsNewPopup() { } ); - chrome.storage.local.remove(['justupdated']); + browser.storage.local.remove(['justupdated']); bkelement.addEventListener('click', function (event) { // Check if the click event originated from the element itself and not any of its children @@ -278,7 +279,7 @@ async function finishLoad() { console.log(err); } - chrome.storage.local.get(['justupdated'], function (result) { + browser.storage.local.get(['justupdated'], function (result) { if (result.justupdated) { OpenWhatsNewPopup(); } @@ -362,7 +363,7 @@ async function RunColourCheck(element) { } export function GetiFrameCSSElement() { - var cssFile = chrome.runtime.getURL('css/iframe.css'); + var cssFile = browser.runtime.getURL('css/iframe.css'); var fileref = document.createElement('link'); fileref.setAttribute('rel', 'stylesheet'); fileref.setAttribute('type', 'text/css'); @@ -379,7 +380,7 @@ function CheckiFrameItems() { mutations_list.forEach(function (mutation) { mutation.addedNodes.forEach(function (added_node) { if (added_node.tagName == 'IFRAME') { - chrome.storage.local.get(['DarkMode'], function (result) { + browser.storage.local.get(['DarkMode'], function (result) { DarkMode = result.DarkMode; if (DarkMode) { RunColourCheck(added_node); @@ -462,12 +463,12 @@ async function LoadPageElements() { switch (sublink) { case 'news': console.log('[BetterSEQTA+] Started Init'); - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { if (result.onoff) { SendNewsPage(); // Sends similar HTTP Post Request for the notices - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { if (result.notificationcollector) { enableNotificationCollector(); } @@ -489,7 +490,7 @@ async function LoadPageElements() { finishLoad(); // Sends similar HTTP Post Request for the notices - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { if (result.notificationcollector) { enableNotificationCollector(); } @@ -579,7 +580,7 @@ function CheckNoticeTextColour(notice) { const observer = new MutationObserver(function (mutations_list) { mutations_list.forEach(function (mutation) { mutation.addedNodes.forEach(function (added_node) { - chrome.storage.local.get(['DarkMode'], function (result) { + browser.storage.local.get(['DarkMode'], function (result) { DarkMode = result.DarkMode; if (added_node.classList.contains('notice')) { var hex = added_node.style.cssText.split(' ')[1]; @@ -655,7 +656,7 @@ function ChangeMenuItemPositions(storage) { } export async function ObserveMenuItemPosition() { - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { let menuorder = result.menuorder; if (menuorder && result.onoff) { const observer = new MutationObserver(function (mutations_list) { @@ -688,7 +689,7 @@ function main(storedSetting) { // Handle undefined onoff setting if (typeof onoff === 'undefined') { - chrome.runtime.sendMessage({ type: 'setDefaultStorage' }); + browser.runtime.sendMessage({ type: 'setDefaultStorage' }); } const initialize = () => { @@ -722,7 +723,7 @@ function main(storedSetting) { } function InjectStyles() { - var cssFile = chrome.runtime.getURL('css/injected.css'); + var cssFile = browser.runtime.getURL('css/injected.css'); var fileref = document.createElement('link'); fileref.setAttribute('rel', 'stylesheet'); fileref.setAttribute('type', 'text/css'); @@ -732,7 +733,7 @@ function InjectStyles() { } function InjectCustomIcons() { - const fontURL = chrome.runtime.getURL('fonts/IconFamily.woff'); + const fontURL = browser.runtime.getURL('fonts/IconFamily.woff'); const style = document.createElement('style'); style.setAttribute('type', 'text/css'); @@ -801,7 +802,7 @@ export function closeSettings() { function addExtensionSettings() { const link = document.createElement('link'); - link.href = chrome.runtime.getURL('popup/popup.css'); + link.href = browser.runtime.getURL('popup/popup.css'); link.type = 'text/css'; link.rel = 'stylesheet'; document.querySelector('html').appendChild(link); @@ -812,7 +813,7 @@ function addExtensionSettings() { document.body.appendChild(extensionPopup); const extensionIframe = document.createElement('iframe'); - extensionIframe.src = chrome.runtime.getURL('interface/index.html'); + extensionIframe.src = browser.runtime.getURL('interface/index.html'); extensionIframe.id = 'ExtensionIframe'; extensionIframe.allowTransparency = true; extensionIframe.style.width = '384px'; @@ -889,7 +890,7 @@ function dragDrop() { listorder.push(elm.dataset.key); } - chrome.storage.local.set({ menuorder: listorder }); + browser.storage.local.set({ menuorder: listorder }); } return false; } @@ -918,7 +919,7 @@ function cloneAttributes(target, source) { } export function OpenMenuOptions() { - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { var container = document.getElementById('container'); var menu = document.getElementById('menu'); @@ -928,7 +929,7 @@ export function OpenMenuOptions() { for (let i = 0; i < childnodes.length; i++) { const element = childnodes[i]; newdefaultmenuorder.push(element.dataset.key); - chrome.storage.local.set({ defaultmenuorder: newdefaultmenuorder }); + browser.storage.local.set({ defaultmenuorder: newdefaultmenuorder }); } } let childnodes = menu.firstChild.childNodes; @@ -938,7 +939,7 @@ export function OpenMenuOptions() { if (!result.defaultmenuorder.indexOf(element.dataset.key)) { let newdefaultmenuorder = result.defaultmenuorder; newdefaultmenuorder.push(element.dataset.key); - chrome.storage.local.set({ defaultmenuorder: newdefaultmenuorder }); + browser.storage.local.set({ defaultmenuorder: newdefaultmenuorder }); } } } @@ -1003,11 +1004,11 @@ export function OpenMenuOptions() { element.toggle = true; menuItems[id] = element; } - chrome.storage.local.set({ menuitems: menuItems }); + browser.storage.local.set({ menuitems: menuItems }); } var menubuttons = document.getElementsByClassName('menuitem'); - chrome.storage.local.get(['menuitems'], function (result) { + browser.storage.local.get(['menuitems'], function (result) { var menuItems = result.menuitems; let buttons = document.getElementsByClassName('menuitem'); for (var i = 0; i < buttons.length; i++) { @@ -1024,7 +1025,7 @@ export function OpenMenuOptions() { ApplyDraggableFunctions(); function StoreMenuSettings() { - chrome.storage.local.get(['menuitems'], function () { + browser.storage.local.get(['menuitems'], function () { var menuItems = {}; menubuttons = menu.firstChild.childNodes; let button = document.getElementsByClassName('menuitem'); @@ -1035,7 +1036,7 @@ export function OpenMenuOptions() { menuItems[id] = element; } - chrome.storage.local.set({ menuitems: menuItems }); + browser.storage.local.set({ menuitems: menuItems }); }); } @@ -1093,9 +1094,9 @@ export function OpenMenuOptions() { savebutton.addEventListener('click', closeAll); defaultbutton.addEventListener('click', function () { - chrome.storage.local.get(null, function (response) { + browser.storage.local.get(null, function (response) { const options = response.defaultmenuorder; - chrome.storage.local.set({ menuorder: options }); + browser.storage.local.set({ menuorder: options }); ChangeMenuItemPositions(options); for (let i = 0; i < menubuttons.length; i++) { @@ -1131,7 +1132,7 @@ async function AddBetterSEQTAElements(toggle) { if (code != null) { if (!code.innerHTML.includes('BetterSEQTA')) { UserInitalCode = code.innerText; - code.innerText = `BetterSEQTA v${chrome.runtime.getManifest().version}`; + code.innerText = `BetterSEQTA v${browser.runtime.getManifest().version}`; code.setAttribute('data-hover', 'Click for user code'); code.addEventListener('click', function () { var code = document.getElementsByClassName('code')[0]; @@ -1140,7 +1141,7 @@ async function AddBetterSEQTAElements(toggle) { code.setAttribute('data-hover', 'Click for BetterSEQTA version'); } else { code.innerText = `BetterSEQTA v${ - chrome.runtime.getManifest().version + browser.runtime.getManifest().version }`; code.setAttribute('data-hover', 'Click for user code'); } @@ -1148,14 +1149,14 @@ async function AddBetterSEQTAElements(toggle) { if (toggle) { // Creates Home menu button and appends it as the first child of the list - const result = chrome.storage.local.get(['animatedbk']); - const sliderVal = chrome.storage.local.get(['bksliderinput']); + const result = browser.storage.local.get(['animatedbk']); + const sliderVal = browser.storage.local.get(['bksliderinput']); result.then(animbkEnable); sliderVal.then(updateBgDurations); // Load darkmode state - chrome.storage.local.get(['DarkMode'], function (result) { + browser.storage.local.get(['DarkMode'], function (result) { DarkMode = result.DarkMode; }); @@ -1307,7 +1308,7 @@ async function AddBetterSEQTAElements(toggle) { ContentDiv.append(SettingsButton.firstChild); const result = await new Promise(resolve => { - chrome.storage.local.get(null, resolve); + browser.storage.local.get(null, resolve); }); const DarkMode = result.DarkMode; @@ -1339,11 +1340,11 @@ async function AddBetterSEQTAElements(toggle) { document.getElementById('LightDarkModeButton').addEventListener('click', async () => { const result = await new Promise(resolve => { - chrome.storage.local.get(null, resolve); + browser.storage.local.get(null, resolve); }); const newDarkMode = !result.DarkMode; - chrome.storage.local.set({ DarkMode: newDarkMode }); + browser.storage.local.set({ DarkMode: newDarkMode }); updateAllColors(newDarkMode, result.selectedColor); @@ -1432,7 +1433,7 @@ function CheckCurrentLesson(lesson, num) { // If 5 minutes before the start of another lesson: if (minutes == 5) { - chrome.storage.local.get('lessonalert', function (result) { + browser.storage.local.get('lessonalert', function (result) { if (result.lessonalert) { // Checks if notifications are supported if (!window.Notification) { @@ -1663,7 +1664,7 @@ function callHomeTimetable(date, change) { var dummyDay = document.createElement('div'); dummyDay.classList.add('day-empty'); let img = document.createElement('img'); - img.src = chrome.runtime.getURL('icons/betterseqta-light-icon.png'); + img.src = browser.runtime.getURL('icons/betterseqta-light-icon.png'); let text = document.createElement('p'); text.innerText = 'No lessons available.'; dummyDay.append(img); @@ -1874,12 +1875,12 @@ function CreateSubjectFilter(subjectcode, itemcolour, checked) { label.append(span); input.addEventListener('change', function (change) { - chrome.storage.local.get(null, function (storage) { + browser.storage.local.get(null, function (storage) { let filters = storage.subjectfilters; let id = change.target.id.split('-')[1]; filters[id] = change.target.checked; - chrome.storage.local.set({ subjectfilters: filters }); + browser.storage.local.set({ subjectfilters: filters }); }); }); @@ -1887,7 +1888,7 @@ function CreateSubjectFilter(subjectcode, itemcolour, checked) { } function CreateFilters(subjects) { - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { let filteroptions = result.subjectfilters; let filterdiv = document.querySelector('#upcoming-filters'); @@ -1896,7 +1897,7 @@ function CreateFilters(subjects) { // eslint-disable-next-line if (!Object.prototype.hasOwnProperty.call(filteroptions, element.code)) { filteroptions[element.code] = true; - chrome.storage.local.set({ subjectfilters: filteroptions }); + browser.storage.local.set({ subjectfilters: filteroptions }); } let elementdiv = CreateSubjectFilter( element.code, @@ -2018,7 +2019,7 @@ function CreateUpcomingSection(assessments) { } } - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { FilterUpcomingAssessments(result.subjectfilters); }); }); @@ -2082,7 +2083,7 @@ function FilterUpcomingAssessments(subjectoptions) { } } -chrome.storage.onChanged.addListener(function (changes) { +browser.storage.onChanged.addListener(function (changes) { if (changes.subjectfilters) { FilterUpcomingAssessments(changes.subjectfilters.newValue); } @@ -2160,7 +2161,7 @@ export function RemoveShortcutDiv(elements) { } function AddCustomShortcutsToPage() { - chrome.storage.local.get(['customshortcuts'], function (result) { + browser.storage.local.get(['customshortcuts'], function (result) { var customshortcuts = Object.values(result)[0]; if (customshortcuts.length > 0) { document.getElementsByClassName('shortcut-container')[0].style.display = @@ -2190,7 +2191,7 @@ function SendHomePage() { const titlediv = document.getElementById('title').firstChild; titlediv.innerText = 'Home'; document.querySelector('link[rel*="icon"]').href = - chrome.runtime.getURL('icons/icon-48.png'); + browser.runtime.getURL('icons/icon-48.png'); currentSelectedDate = new Date(); @@ -2280,7 +2281,7 @@ function SendHomePage() { }); // Adds the shortcuts to the shortcut container - chrome.storage.local.get(['shortcuts'], function (result) { + browser.storage.local.get(['shortcuts'], function (result) { const shortcuts = Object.values(result)[0]; addShortcuts(shortcuts); }); @@ -2351,7 +2352,7 @@ function SendHomePage() { } else { if (!NoticeContainer.innerText) { // For each element in the response json: - chrome.storage.local.get(['DarkMode'], function (result) { + browser.storage.local.get(['DarkMode'], function (result) { DarkMode = result.DarkMode; for (let i = 0; i < NoticesPayload.payload.length; i++) { // Create a div, and place information from json response @@ -2417,7 +2418,7 @@ function SendHomePage() { xhr2.send(JSON.stringify({ date: TodayFormatted })); // Sends similar HTTP Post Request for the notices - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { if (result.notificationcollector) { enableNotificationCollector(); } @@ -2570,7 +2571,7 @@ function SendNewsPage() { titlediv.innerText = 'News'; AppendLoadingSymbol('newsloading', '#news-container'); - chrome.runtime.sendMessage({ type: 'sendNews' }, function (response) { + browser.runtime.sendMessage({ type: 'sendNews' }, function (response) { let newsarticles = response.news.articles; var newscontainer = document.querySelector('#news-container'); document.getElementById('newsloading').remove(); @@ -2584,7 +2585,7 @@ function SendNewsPage() { articleimage.classList.add('articleimage'); if (newsarticles[i].urlToImage == 'null') { - articleimage.style.backgroundImage = `url(${chrome.runtime.getURL( + articleimage.style.backgroundImage = `url(${browser.runtime.getURL( 'icons/betterseqta-light-outline.png', )})`; articleimage.style.width = '20%'; @@ -2629,7 +2630,7 @@ async function CheckForMenuList() { function LoadInit() { console.log('[BetterSEQTA] Started Init'); - chrome.storage.local.get(null, function (result) { + browser.storage.local.get(null, function (result) { if (result.onoff) { SendHomePage(); } diff --git a/src/background.js b/src/background.js index 52f447b4..db5d9a74 100644 --- a/src/background.js +++ b/src/background.js @@ -1,4 +1,5 @@ -/*global chrome*/ +import browser from 'webextension-polyfill'; + export const openDB = () => { return new Promise((resolve, reject) => { const request = indexedDB.open('MyDatabase', 1); @@ -56,10 +57,10 @@ export const readData = () => { }; function reloadSeqtaPages() { - chrome.tabs.query({}, function (tabs) { + browser.tabs.query({}, function (tabs) { for (let tab of tabs) { if (tab.title.includes('SEQTA Learn')) { - chrome.tabs.reload(tab.id); + browser.tabs.reload(tab.id); } } }); @@ -67,11 +68,11 @@ function reloadSeqtaPages() { // Helper function to handle setting permissions const handleAddPermissions = () => { - if (typeof chrome.declarativeContent !== 'undefined') { - chrome.declarativeContent.onPageChanged.removeRules(undefined, () => {}); + if (typeof browser.declarativeContent !== 'undefined') { + browser.declarativeContent.onPageChanged.removeRules(undefined, () => {}); } - chrome.permissions.request( + browser.permissions.request( { permissions: ['declarativeContent'], origins: ['*://*/*'] }, (granted) => { if (granted) { @@ -80,7 +81,7 @@ const handleAddPermissions = () => { ]; rules.forEach(rule => { - chrome.declarativeContent.onPageChanged.addRules([rule]); + browser.declarativeContent.onPageChanged.addRules([rule]); }); alert('Permissions granted. Reload SEQTA pages to see changes. If this workaround doesn\'t work, please contact the developer. It will be an easy fix'); @@ -90,22 +91,22 @@ const handleAddPermissions = () => { }; // Main message listener -chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { +browser.runtime.onMessage.addListener((request, sender, sendResponse) => { switch (request.type) { case 'reloadTabs': reloadSeqtaPages(); break; case 'currentTab': - chrome.tabs.query({ active: true, currentWindow: true }, function (tabs) { - chrome.tabs.sendMessage(tabs[0].id, request, function (response) { + browser.tabs.query({ active: true, currentWindow: true }, function (tabs) { + browser.tabs.sendMessage(tabs[0].id, request, function (response) { sendResponse(response); }); }); return true; case 'githubTab': - chrome.tabs.create({ url: 'github.com/SethBurkart123/EvenBetterSEQTA' }); + browser.tabs.create({ url: 'github.com/SethBurkart123/EvenBetterSEQTA' }); break; case 'setDefaultStorage': @@ -218,12 +219,12 @@ const DefaultValues = { function SetStorageValue(object) { for (var i in object) { - chrome.storage.local.set({ [i]: object[i] }); + browser.storage.local.set({ [i]: object[i] }); } } function UpdateCurrentValues() { - chrome.storage.local.get(null, function (items) { + browser.storage.local.get(null, function (items) { var CurrentValues = items; const NewValue = Object.assign({}, DefaultValues, CurrentValues); @@ -257,7 +258,7 @@ function UpdateCurrentValues() { } function migrateOldStorage() { - chrome.storage.local.get(null, function (items) { + browser.storage.local.get(null, function (items) { let shouldUpdate = false; // Flag to check if there is anything to update // Check for the old "Name" field and convert it to "name" @@ -283,18 +284,18 @@ function migrateOldStorage() { // If there"s something to update, set the new values in storage if (shouldUpdate) { - chrome.storage.local.set({ shortcuts: items.shortcuts }, function() { + browser.storage.local.set({ shortcuts: items.shortcuts }, function() { console.log('Migration completed.'); }); } }); } -chrome.runtime.onInstalled.addListener(function (event) { - chrome.storage.local.remove(['justupdated']); +browser.runtime.onInstalled.addListener(function (event) { + browser.storage.local.remove(['justupdated']); UpdateCurrentValues(); if ( event.reason == 'install', event.reason == 'update' ) { - chrome.storage.local.set({ justupdated: true }); + browser.storage.local.set({ justupdated: true }); migrateOldStorage(); } }); \ No newline at end of file From 970cc65f64ca4861c851102485212502bc1ed315 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Fri, 17 Nov 2023 15:46:35 +1100 Subject: [PATCH 2/7] slightly broken :( --- src/css/injected.scss | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/css/injected.scss b/src/css/injected.scss index ef24e188..61345103 100644 --- a/src/css/injected.scss +++ b/src/css/injected.scss @@ -339,7 +339,7 @@ td.colourBar { /* Provides space for the icon */ } #toolbar span:has(.search)::before { - content: ""; + content: "\eca5"; /* Unicode for the search icon */ position: absolute; left: 8px; @@ -1664,7 +1664,7 @@ body { text-shadow: 0 0 5px black; } [data-label="inbox"] > .LabelList__name___-CHgq::before { - content: ""; + content: "\eb70"; /* Unicode for the search icon */ color: currentColor; font-size: 16px; @@ -1674,7 +1674,7 @@ body { pointer-events: none; } [data-label="outbox"] > .LabelList__name___-CHgq::before { - content: ""; + content: "\eca6"; /* Unicode for the search icon */ color: currentColor; font-size: 16px; @@ -1684,7 +1684,7 @@ body { pointer-events: none; } [data-label="starred"] > .LabelList__name___-CHgq::before { - content: ""; + content: "\ece8"; color: currentColor; font-size: 16px; margin-right: 8px; @@ -1693,7 +1693,7 @@ body { pointer-events: none; } [data-label="trash"] > .LabelList__name___-CHgq::before { - content: ""; + content: "\ed2c"; /* Unicode for the search icon */ color: currentColor; font-size: 16px; @@ -2516,7 +2516,7 @@ body { cursor: pointer; } #whatsnewclosebutton::before { - content: ""; + content: "\ed8a"; color: currentColor; font-size: 24px; font-family: "IconFamily"; From 47b63f975ae7dc6aa8bd7d95a4452f7e8b28fb15 Mon Sep 17 00:00:00 2001 From: Alphons <93847055+Crazypersonalph@users.noreply.github.com> Date: Sat, 2 Dec 2023 22:52:31 +0800 Subject: [PATCH 3/7] moved firefox to manifest v2, it works! --- public/manifest.json | 74 ++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 51 deletions(-) diff --git a/public/manifest.json b/public/manifest.json index e2b61f59..d04db9ce 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,5 +1,5 @@ { - "manifest_version": 3, + "manifest_version": 2, "name": "BetterSEQTA+", "version": "3.2.2", "description": "Make SEQTA usable and beautiful! A fork of BetterSEQTA to continue development and add WAY more features!!!", @@ -8,7 +8,7 @@ "48": "icons/icon-48.png", "64": "icons/icon-64.png" }, - "action": { + "browser_action": { "browser_style": true, "default_popup": "interface/index.html#settings", "default_icon": { @@ -17,12 +17,17 @@ "64": "icons/icon-64.png" } }, - "permissions": ["tabs", "notifications", "storage"], - "host_permissions": ["https://newsapi.org/", "*://*/*"], + "permissions": ["tabs", "notifications", "storage", "https://newsapi.org/"], "background": { - "service_worker": "background.js" - }, - "optional_permissions": ["declarativeContent"], + "scripts": [ + "browser-polyfill.js", + "background.js" + ] +}, + "optional_permissions": [ + "*://*/*", + "declarativeContent" + ], "content_scripts": [ { "matches": ["*://*/*"], @@ -31,49 +36,16 @@ } ], "web_accessible_resources": [ - { - "resources": ["icons/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["fonts/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["images/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["css/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["popup/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["client.js"], - "matches": ["*://*/*"] - }, - { - "resources": ["index.css"], - "matches": ["*://*/*"] - }, - { - "resources": ["interface/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["client/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["resources/*"], - "matches": ["*://*/*"] - }, - { - "resources": ["backgrounds/*"], - "matches": ["*://*/*"] - } + "icons/*", + "fonts/*", + "images/*", + "css/*", + "popup/*", + "client.js", + "index.css", + "interface/*", + "client/*", + "resources/*", + "backgrounds/*" ] } From d4dbacb1c018c3c672bd4650a64ca524e05df990 Mon Sep 17 00:00:00 2001 From: SethBurkart123 Date: Sun, 3 Dec 2023 06:04:49 +1100 Subject: [PATCH 4/7] fix manifest.json --- public/manifest.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/public/manifest.json b/public/manifest.json index ecffa5c3..502aaf07 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -45,4 +45,5 @@ "client/*", "resources/*", "backgrounds/*" -] \ No newline at end of file + ] +} \ No newline at end of file From e5f3c30a31acc4c0016efa443c723f9aa23fb31c Mon Sep 17 00:00:00 2001 From: Crazypersonalph <93847055+Crazypersonalph@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:13:36 +0800 Subject: [PATCH 5/7] fix animatedbk --- interface/package.json | 4 +++- interface/pnpm-lock.yaml | 14 ++++++++++++++ interface/src/hooks/ThemeManagment.tsx | 11 ++++++----- interface/src/hooks/settingsState.ts | 13 +++++++------ interface/src/main.tsx | 3 ++- interface/src/pages/Settings.tsx | 4 +++- pnpm-lock.yaml | 8 +++----- src/SEQTA.js | 6 +++++- 8 files changed, 43 insertions(+), 20 deletions(-) diff --git a/interface/package.json b/interface/package.json index 7a7f2365..381e2b97 100644 --- a/interface/package.json +++ b/interface/package.json @@ -11,12 +11,14 @@ }, "dependencies": { "@types/chrome": "^0.0.246", + "@types/webextension-polyfill": "^0.10.7", "framer-motion": "^10.16.4", "react": "^18.2.0", "react-best-gradient-color-picker": "2.2.24", "react-dom": "^18.2.0", "react-router-dom": "latest", - "tinycolor2": "^1.6.0" + "tinycolor2": "^1.6.0", + "webextension-polyfill": "^0.10.0" }, "devDependencies": { "@types/react": "^18.2.15", diff --git a/interface/pnpm-lock.yaml b/interface/pnpm-lock.yaml index 8a595000..7718c35e 100644 --- a/interface/pnpm-lock.yaml +++ b/interface/pnpm-lock.yaml @@ -8,6 +8,9 @@ dependencies: '@types/chrome': specifier: ^0.0.246 version: 0.0.246 + '@types/webextension-polyfill': + specifier: ^0.10.7 + version: 0.10.7 framer-motion: specifier: ^10.16.4 version: 10.16.12(react-dom@18.2.0)(react@18.2.0) @@ -26,6 +29,9 @@ dependencies: tinycolor2: specifier: ^1.6.0 version: 1.6.0 + webextension-polyfill: + specifier: ^0.10.0 + version: 0.10.0 devDependencies: '@types/react': @@ -709,6 +715,10 @@ packages: resolution: {integrity: sha512-dn1l8LaMea/IjDoHNd9J52uBbInB796CDffS6VdIxvqYCPSG0V0DzHp76GpaWnlhg88uYyPbXCDIowa86ybd5A==} dev: true + /@types/webextension-polyfill@0.10.7: + resolution: {integrity: sha512-10ql7A0qzBmFB+F+qAke/nP1PIonS0TXZAOMVOxEUsm+lGSW6uwVcISFNa0I4Oyj0884TZVWGGMIWeXOVSNFHw==} + dev: false + /@typescript-eslint/eslint-plugin@6.13.1(@typescript-eslint/parser@6.13.1)(eslint@8.55.0)(typescript@5.3.2): resolution: {integrity: sha512-5bQDGkXaxD46bPvQt08BUz9YSaO4S0fB1LB5JHQuXTfkGPI3+UUeS387C/e9jRie5GqT8u5kFTrMvAjtX4O5kA==} engines: {node: ^16.0.0 || >=18.0.0} @@ -2249,6 +2259,10 @@ packages: fsevents: 2.3.3 dev: true + /webextension-polyfill@0.10.0: + resolution: {integrity: sha512-c5s35LgVa5tFaHhrZDnr3FpQpjj1BB+RXhLTYUxGqBVN460HkbM8TBtEqdXWbpTKfzwCcjAZVF7zXCYSKtcp9g==} + dev: false + /which@2.0.2: resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==} engines: {node: '>= 8'} diff --git a/interface/src/hooks/ThemeManagment.tsx b/interface/src/hooks/ThemeManagment.tsx index 5bd45538..51c8bf5f 100644 --- a/interface/src/hooks/ThemeManagment.tsx +++ b/interface/src/hooks/ThemeManagment.tsx @@ -1,3 +1,4 @@ +import browser from 'webextension-polyfill' interface ThemeList { themes: string[]; selectedTheme: string; @@ -5,7 +6,7 @@ interface ThemeList { export const downloadTheme = async (themeName: string, themeURL: string) => { // send message to the background script - const response = await chrome.runtime.sendMessage({ + const response = await browser.runtime.sendMessage({ type: 'currentTab', info: 'DownloadTheme', body: { @@ -19,7 +20,7 @@ export const downloadTheme = async (themeName: string, themeURL: string) => { export const setTheme = async (themeName: string, themeURL: string) => { // send message to the background script - const response = await chrome.runtime.sendMessage({ + const response = await browser.runtime.sendMessage({ type: 'currentTab', info: 'SetTheme', body: { @@ -33,7 +34,7 @@ export const setTheme = async (themeName: string, themeURL: string) => { export const listThemes = async () => { // send message to the background script - const response: ThemeList = await chrome.runtime.sendMessage({ + const response: ThemeList = await browser.runtime.sendMessage({ type: 'currentTab', info: 'ListThemes' }); @@ -45,14 +46,14 @@ export const listThemes = async () => { } export const disableTheme = async () => { - await chrome.runtime.sendMessage({ + await browser.runtime.sendMessage({ type: 'currentTab', info: 'DisableTheme', }); }; export const deleteTheme = async (themeName: string) => { - await chrome.runtime.sendMessage({ + await browser.runtime.sendMessage({ type: 'currentTab', info: 'DeleteTheme', body: { diff --git a/interface/src/hooks/settingsState.ts b/interface/src/hooks/settingsState.ts index 2c5f6ffd..1bbdf309 100644 --- a/interface/src/hooks/settingsState.ts +++ b/interface/src/hooks/settingsState.ts @@ -1,4 +1,4 @@ -/*global chrome*/ +import browser from 'webextension-polyfill' import { useEffect, useMemo } from "react"; import { SettingsProps } from "../types/SettingsProps"; import { MainConfig, SettingsState } from "../types/AppProps"; @@ -12,7 +12,8 @@ const useSettingsState = ({ settingsState, setSettingsState }: SettingsProps) => RanOnce = true; // get the current settings state - chrome.storage.local.get(function(result: MainConfig) { + // @ts-expect-error idk js/ts wizardry + browser.storage.local.get().then().then(function(result: MainConfig) { setSettingsState({ notificationCollector: result.notificationcollector, lessonAlerts: result.lessonalert, @@ -43,7 +44,7 @@ const useSettingsState = ({ settingsState, setSettingsState }: SettingsProps) => "transparencyEffects": "transparencyEffects" }), []); - const storageChangeListener = (changes: chrome.storage.StorageChange) => { + const storageChangeListener = (changes: browser.Storage.StorageChange) => { for (const [key, { newValue }] of Object.entries(changes)) { if (key === "DarkMode") { if (key === "DarkMode" && newValue) { @@ -66,14 +67,14 @@ const useSettingsState = ({ settingsState, setSettingsState }: SettingsProps) => }; useEffect(() => { - chrome.storage.onChanged.addListener(storageChangeListener); + browser.storage.onChanged.addListener(storageChangeListener); return () => { - chrome.storage.onChanged.removeListener(storageChangeListener); + browser.storage.onChanged.removeListener(storageChangeListener); }; }); const setStorage = (key: keyof MainConfig, value: any) => { - chrome.storage.local.set({ [key]: value }); + browser.storage.local.set({ [key]: value }); } useEffect(() => { diff --git a/interface/src/main.tsx b/interface/src/main.tsx index 39082ae5..04114747 100644 --- a/interface/src/main.tsx +++ b/interface/src/main.tsx @@ -4,7 +4,8 @@ import { HashRouter, Routes, Route } from 'react-router-dom'; import './index.css'; import { SettingsContextProvider } from './SettingsContext.js'; import SettingsPage from './SettingsPage.js'; -const fontURL = chrome.runtime.getURL("fonts/IconFamily.woff"); +import browser from 'webextension-polyfill' +const fontURL = browser.runtime.getURL("fonts/IconFamily.woff"); const style = document.createElement("style"); style.setAttribute("type", "text/css"); diff --git a/interface/src/pages/Settings.tsx b/interface/src/pages/Settings.tsx index 13689a2d..fa6840f6 100644 --- a/interface/src/pages/Settings.tsx +++ b/interface/src/pages/Settings.tsx @@ -5,6 +5,8 @@ import PickerSwatch from '../components/PickerSwatch'; import { SettingsList } from '../types/SettingsProps'; import { useSettingsContext } from '../SettingsContext'; +import browser from 'webextension-polyfill' + const Settings: React.FC = () => { const { settingsState, setSettingsState } = useSettingsContext(); @@ -51,7 +53,7 @@ const Settings: React.FC = () => { { title: "Edit Sidebar Layout", description: "Customise the sidebar layout.", - modifyElement: + modifyElement: }, { title: "Transparency Effects", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 764beb31..32ff2fcb 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,7 +1,7 @@ lockfileVersion: '6.0' settings: - autoInstallPeers: true + autoInstallPeers: false excludeLinksFromLockfile: false dependencies: @@ -563,10 +563,8 @@ packages: hasBin: true dev: true - /ajv-formats@2.1.1(ajv@8.12.0): + /ajv-formats@2.1.1: resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==} - peerDependencies: - ajv: ^8.0.0 peerDependenciesMeta: ajv: optional: true @@ -2057,7 +2055,7 @@ packages: dependencies: '@types/json-schema': 7.0.15 ajv: 8.12.0 - ajv-formats: 2.1.1(ajv@8.12.0) + ajv-formats: 2.1.1 ajv-keywords: 5.1.0(ajv@8.12.0) dev: true diff --git a/src/SEQTA.js b/src/SEQTA.js index 813505af..8a314818 100644 --- a/src/SEQTA.js +++ b/src/SEQTA.js @@ -311,6 +311,10 @@ async function DeleteWhatsNew() { } export function CreateBackground() { + var bkCheck = document.getElementsByClassName('bg'); + if (bkCheck.length !== 0) { + return; + } // Creating and inserting 3 divs containing the background applied to the pages var bklocation = document.getElementById('container'); var menu = document.getElementById('menu'); @@ -336,10 +340,10 @@ export function RemoveBackground() { var bk3 = document.getElementsByClassName('bg3'); if (bk.length == 0 || bk2.length == 0 || bk3.length == 0) return; - bk[0].remove(); bk2[0].remove(); bk3[0].remove(); + console.log('it deleted???') } export function waitForElm(selector) { From 4f74ea72ee180473540332b27561988352b93ddf Mon Sep 17 00:00:00 2001 From: Crazypersonalph <93847055+Crazypersonalph@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:23:05 +0800 Subject: [PATCH 6/7] added line --- interface/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/interface/index.html b/interface/index.html index b4b12537..2f1b4e8e 100644 --- a/interface/index.html +++ b/interface/index.html @@ -11,3 +11,4 @@ + From 1bae7392a174cafb3b91d69d419ddd4c52be1e5f Mon Sep 17 00:00:00 2001 From: Crazypersonalph <93847055+Crazypersonalph@users.noreply.github.com> Date: Mon, 4 Dec 2023 12:25:56 +0800 Subject: [PATCH 7/7] switch to mv3 --- public/manifest.json | 78 ++++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 24 deletions(-) diff --git a/public/manifest.json b/public/manifest.json index 502aaf07..f823b0fb 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,12 +1,14 @@ { - "manifest_version": 2, + "manifest_version": 3, "name": "BetterSEQTA+", "version": "3.2.2", "description": "Make SEQTA usable and beautiful! A fork of BetterSEQTA to continue development and add WAY more features!!!", "icons": { - "48": "icons/icon-48.png" + "32": "icons/icon-32.png", + "48": "icons/icon-48.png", + "64": "icons/icon-64.png" }, - "browser_action": { + "action": { "browser_style": true, "default_popup": "interface/index.html#settings", "default_icon": { @@ -15,17 +17,12 @@ "64": "icons/icon-64.png" } }, - "permissions": ["tabs", "notifications", "storage", "https://newsapi.org/"], + "permissions": ["tabs", "notifications", "storage"], + "host_permissions": ["https://newsapi.org/", "*://*/*"], "background": { - "scripts": [ - "browser-polyfill.js", - "background.js" - ] -}, - "optional_permissions": [ - "*://*/*", - "declarativeContent" - ], + "service_worker": "background.js" + }, + "optional_permissions": ["declarativeContent"], "content_scripts": [ { "matches": ["*://*/*"], @@ -34,16 +31,49 @@ } ], "web_accessible_resources": [ - "icons/*", - "fonts/*", - "images/*", - "css/*", - "popup/*", - "client.js", - "index.css", - "interface/*", - "client/*", - "resources/*", - "backgrounds/*" + { + "resources": ["icons/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["fonts/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["images/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["css/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["popup/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["client.js"], + "matches": ["*://*/*"] + }, + { + "resources": ["index.css"], + "matches": ["*://*/*"] + }, + { + "resources": ["interface/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["client/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["resources/*"], + "matches": ["*://*/*"] + }, + { + "resources": ["backgrounds/*"], + "matches": ["*://*/*"] + } ] } \ No newline at end of file