···11-# This file was created by https://github.com/mozilla/web-ext
22-# Your auto-generated extension ID for addons.mozilla.org is:
33-schooltape@schooltape-community.github.io
-317
src/background.js
···11-import browser from "webextension-polyfill";
22-33-switch (__BROWSER__) {
44- case "chrome":
55- console.log("Service worker active!");
66- break;
77- case "firefox":
88- console.log("Background script active!");
99- break;
1010-}
1111-1212-// ----------------- Variables ----------------- //
1313-const defaultSettings = {
1414- settings: {
1515- global: true,
1616- updates: {
1717- toast: true,
1818- desktop: false,
1919- },
2020- urls: ["https://help.schoolbox.com.au"],
2121- },
2222- snippets: {
2323- toggle: true,
2424- enabled: ["hide-pfp"],
2525- user: {},
2626- },
2727- plugins: {
2828- toggle: true,
2929- enabled: ["subheader", "scroll-segments", "tab-title", "scroll-period", "timetable-labels"],
3030- settings: {},
3131- },
3232- themes: {
3333- toggle: true,
3434- theme: "catppuccin",
3535- flavour: "macchiato",
3636- accent: "rosewater",
3737- logo: "schooltape.png",
3838- },
3939-};
4040-// ----------------- Install/Update ----------------- //
4141-4242-// Check whether new version is installed
4343-browser.runtime.onInstalled.addListener(function (details) {
4444- if (details.reason === "install") {
4545- // Execute code when first installed
4646- browser.notifications.create("tutorial", {
4747- type: "basic",
4848- iconUrl: "assets/icon-128.png",
4949- title: "Thank you for installing Schooltape!",
5050- message: "Click here to look at the tutorial.",
5151- priority: 2,
5252- });
5353- resetSettings();
5454- } else if (details.reason === "update") {
5555- let thisVersion = browser.runtime.getManifest().version;
5656- // set default settings, if major number is increased
5757- if (details.previousVersion.split(".")[0] > thisVersion.split(".")[0]) {
5858- resetSettings();
5959- print("New major version installed, reset settings");
6060- }
6161- // Sends a notification to the user with the changelog
6262- console.log(`Updated from ${details.previousVersion} to ${thisVersion}!`);
6363- browser.notifications.create("updated", {
6464- type: "basic",
6565- iconUrl: "assets/icon-128.png",
6666- title: `Updated from ${details.previousVersion} to ${thisVersion}!`,
6767- message: "Click here to look at the release notes.",
6868- priority: 2,
6969- });
7070- }
7171- updateBadge();
7272-});
7373-7474-// ----------------- Listeners ----------------- //
7575-browser.runtime.onMessage.addListener(function (request, sender, sendResponse) {
7676- console.log("Message received: ");
7777- console.log(request);
7878-7979- sendResponse({ messageReceived: true });
8080-8181- if (request.badgeText) {
8282- updateBadge();
8383- console.log("Running update badge text function");
8484- }
8585-8686- if (request.inject) {
8787- console.log("Injecting " + request.inject);
8888- console.log(`tabid: ${sender.tab.id}`);
8989- // NOTE: see https://github.com/mozilla/webextension-polyfill?tab=readme-ov-file#tabsexecutescript
9090- browser.tabs.executeScript(sender.tab.id, { file: request.inject });
9191- }
9292-9393- // Switch to homepage
9494- if (request.toHomepage) {
9595- console.log("Changing tab to " + request.toHomepage);
9696- browser.tabs.query({ url: request.toHomepage }, function (tabs) {
9797- console.log(tabs);
9898- if (tabs.length > 0) {
9999- browser.tabs.update(tabs[0].id, { active: true });
100100- } else {
101101- browser.tabs.update(sender.tab.id, { url: request.toHomepage });
102102- }
103103- });
104104- }
105105-106106- // Reset settings
107107- if (request.resetSettings) {
108108- console.log("Resetting settings...");
109109- resetSettings();
110110- }
111111-112112- // Check for updates
113113- if (request.checkForUpdates) {
114114- checkForUpdates();
115115- }
116116-});
117117-118118-/*
119119---------------------------------CONTEXT MENUS--------------------------------
120120-*/
121121-// Context menus
122122-// let action = "action";
123123-// switch (__BROWSER__) {
124124-// case "chrome":
125125-// action = "browser_action"
126126-// break;
127127-// case "firefox":
128128-// action = "action"
129129-// break;
130130-// }
131131-// console.log("created context menu");
132132-// browser.contextMenus.removeAll(function () {
133133-// // Github
134134-// let github = browser.contextMenus.create({
135135-// id: "github",
136136-// title: "GitHub",
137137-// contexts: [action],
138138-// });
139139-// browser.contextMenus.create({
140140-// id: "githubRepo",
141141-// parentId: github,
142142-// title: "Repository",
143143-// contexts: [action],
144144-// });
145145-// browser.contextMenus.create({
146146-// id: "githubIssues",
147147-// parentId: github,
148148-// title: "Issues",
149149-// contexts: [action],
150150-// });
151151-// browser.contextMenus.create({
152152-// id: "githubPRs",
153153-// parentId: github,
154154-// title: "Pull Requests",
155155-// contexts: [action],
156156-// });
157157-// browser.contextMenus.create({
158158-// id: "githubProjects",
159159-// parentId: github,
160160-// title: "Projects",
161161-// contexts: [action],
162162-// });
163163-// browser.contextMenus.create({
164164-// id: "githubWiki",
165165-// parentId: github,
166166-// title: "Wiki",
167167-// contexts: [action],
168168-// });
169169-170170-// browser.contextMenus.create({
171171-// id: "extRefresh",
172172-// title: "Refresh Extension",
173173-// contexts: [action],
174174-// });
175175-// });
176176-177177-// // Check which context menu button was clicked
178178-// function contextClick(info, tab) {
179179-// const { menuItemId } = info;
180180-// if (menuItemId === "githubRepo") {
181181-// let newURL = "https://github.com/42willow/schooltape";
182182-// browser.tabs.create({ url: newURL });
183183-// } else if (menuItemId === "githubIssues") {
184184-// let newURL = "https://github.com/42willow/schooltape/issues";
185185-// browser.tabs.create({ url: newURL });
186186-// } else if (menuItemId === "githubPRs") {
187187-// let newURL = "https://github.com/42willow/schooltape/pulls";
188188-// browser.tabs.create({ url: newURL });
189189-// } else if (menuItemId === "githubProjects") {
190190-// let newURL = "https://github.com/42willow/schooltape/projects";
191191-// browser.tabs.create({ url: newURL });
192192-// } else if (menuItemId === "githubWiki") {
193193-// let newURL = "https://github.com/42willow/schooltape/wiki";
194194-// browser.tabs.create({ url: newURL });
195195-// } else if (menuItemId === "extRefresh") {
196196-// console.log("Refreshing extension...");
197197-// browser.runtime.reload();
198198-// }
199199-// }
200200-// browser.contextMenus.onClicked.addListener(contextClick);
201201-202202-// /*
203203-// // --------------------------------UPDATE NOTIFICATION CLICKED LISTERNER--------------------------------
204204-// // */
205205-// browser.notifications.onClicked.addListener(function (notifID) {
206206-// if (notifID === "update") {
207207-// browser.tabs.create({
208208-// url: "https://github.com/42willow/schooltape/releases/latest",
209209-// });
210210-// }
211211-// if (notifID === "tutorial") {
212212-// browser.tabs.create({
213213-// url: "https://github.com/42Willow/schooltape/wiki/Getting-Started#configuring",
214214-// });
215215-// }
216216-// if (notifID === "updated") {
217217-// let thisVersion = browser.runtime.getManifest().version;
218218-// let newURL = "https://github.com/42willow/schooltape/releases/tag/v" + thisVersion;
219219-// browser.tabs.create({ url: newURL });
220220-// }
221221-// });
222222-223223-// /*
224224-// --------------------------------EXTENSION BUTTON CLICKED--------------------------------
225225-// */
226226-// On extension clicked
227227-// browser.action.onClicked.addListener((tab) => {
228228-// console.log("Button clicked!");
229229-230230-// // TOGGLE EXTENSION
231231-// browser.storage.local.get(["settings"], function (result) {
232232-// if (result.settings.global === true) {
233233-// let newSettings = result.settings;
234234-// newSettings.global = false;
235235-// browser.storage.local.set({ settings: newSettings }, function () {});
236236-// browser.action.setBadgeText({ text: "OFF" });
237237-// // Reload current tab
238238-// browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
239239-// browser.tabs.reload(tabs[0].id);
240240-// });
241241-// } else if (result.settings.global === false) {
242242-// let newSettings = result.settings;
243243-// newSettings.global = true;
244244-// browser.storage.local.set({ settings: newSettings }, function () {});
245245-// browser.action.setBadgeText({ text: "ON" });
246246-// browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
247247-// browser.tabs.reload(tabs[0].id);
248248-// });
249249-// }
250250-// browser.action.setBadgeBackgroundColor({ color: "#94DBF9" });
251251-// browser.action.setBadgeTextColor({ color: "black" });
252252-// });
253253-// });
254254-255255-// // /*
256256-// // --------------------------------UPDATE BADGE--------------------------------
257257-// // */
258258-async function updateBadge() {
259259- console.log("Updating badge...");
260260- const settings = await browser.storage.local.get("settings");
261261- console.log(settings);
262262- // if (settings.global) {
263263- // console.log("Badge: ON");
264264- // } else {
265265- // console.log("Badge: OFF");
266266- // }
267267-}
268268-269269-function resetSettings() {
270270- browser.storage.local.clear();
271271- browser.storage.local.set({
272272- settings: defaultSettings.settings,
273273- snippets: defaultSettings.snippets,
274274- plugins: defaultSettings.plugins,
275275- themes: defaultSettings.themes,
276276- });
277277- updateBadge();
278278-}
279279-280280-function checkForUpdates() {
281281- if (!navigator.onLine) {
282282- console.error("You are currently offline. Please check your internet connection and try again.");
283283- } else {
284284- browser.storage.local.get("settings", function (result) {
285285- if (request.checkForUpdates && result.settings.updateReminder) {
286286- // Get latest and pre-release information from github
287287- fetch("https://api.github.com/repos/42willow/schooltape/releases/latest")
288288- .then((response) => response.json())
289289- .then((data) => {
290290- // Get latest version without the "v" in front
291291- let latestVersion = data.tag_name.replace("v", "");
292292- console.log("Latest version is " + latestVersion);
293293- // Get current version
294294- let currentVersion = browser.runtime.getManifest().version;
295295- console.log("Current version is " + currentVersion);
296296- // Compare versions
297297- if (latestVersion > currentVersion) {
298298- console.log("Update available");
299299- // Send notification
300300- browser.notifications.create("update", {
301301- type: "basic",
302302- iconUrl: "assets/icon-128.png",
303303- title: "Update available!",
304304- message: `New version: ${latestVersion}\n(Currently installed: ${currentVersion})\nClick here to look at the release notes.`,
305305- priority: 2,
306306- });
307307- } else {
308308- console.log("No update available");
309309- }
310310- })
311311- .catch((error) => {
312312- console.error("Error occurred while fetching latest release", error);
313313- });
314314- }
315315- });
316316- }
317317-}
···11<script>
22 import { onMount } from "svelte";
33- import browser from "webextension-polyfill";
43 import Title from "../components/Title.svelte";
5465 let plugins = {
···11<script>
22 import { onMount } from "svelte";
33- import browser from "webextension-polyfill";
43 import Title from "../components/Title.svelte";
5465 let snippets = {
···11-import browser from "webextension-polyfill";
22-33-browser.storage.local.get().then(function (storage) {
44- if (storage.settings.global && storage.settings.urls.includes(window.location.origin)) {
55- console.log("Schooltape is enabled on this site");
66- }
77-88- let footer = document.querySelector("#footer > ul");
99- if (footer.innerHTML.includes("Schoolbox")) {
1010- let footerListItem = document.createElement("li");
1111- footerListItem.appendChild(document.createElement("a")).href = "https://github.com/42willow/schooltape";
1212- footerListItem.firstChild.textContent = `Schooltape v${browser.runtime.getManifest().version}`;
1313- footer.appendChild(footerListItem);
1414- if (!storage.settings.urls.includes(window.location.origin)) {
1515- let newSettings = storage.settings;
1616- newSettings.urls.push(window.location.origin);
1717- browser.storage.local.set({ settings: newSettings });
1818- // TODO: hot reload
1919- window.location.reload();
2020- }
2121- }
2222-});
2323-2424-// // This is for:
2525-// // - Plugins (that alter the DOM after is has been loaded)
2626-2727-// // inject enabled plugins if the current URL is stored as Schoolbox and extension is enabled
2828-// browser.storage.local.get(["settings"], function (data) {
2929-// if (data.settings.global) {
3030-// if (data.settings.urls.includes(window.location.origin)) {
3131-// for (let i = 0; i < data.settings.enabledPlugins.length; i++) {
3232-// runUtilsFunction("injectPlugin", data.settings.enabledPlugins[i], "doc-end");
3333-// }
3434-// }
3535-// }
3636-// });
3737-3838-// check if the page is Schoolbox, if not add it to storage and reload the page
3939-4040-// async function runUtilsFunction(functionName, ...args) {
4141-// const src = browser.runtime.getURL("scripts/scriptUtils.js");
4242-// const utils = await import(src);
4343-// if (typeof utils[functionName] === "function") {
4444-// utils[functionName](...args);
4545-// } else {
4646-// console.error(`Function ${functionName} does not exist in utils`);
4747-// }
4848-// }
-116
src/scripts/doc-start.js
···11-import browser from "webextension-polyfill";
22-import { injectCSS, injectCatppuccin } from "./script-utils.js";
33-44-browser.storage.local.get().then(function (storage) {
55- console.log(storage);
66- if (storage.settings.global && storage.settings.urls.includes(window.location.origin)) {
77- console.log("Schooltape is enabled on this site");
88- if (storage.themes.toggle) {
99- console.log(storage.themes);
1010- injectCSS("/themes/catppuccin.css");
1111- injectCatppuccin(storage.themes.flavour, storage.themes.accent);
1212- }
1313- }
1414-});
1515-1616-// // This is for:
1717-// // - Plugins (That inject stylesheets)
1818-// // - Themes
1919-// // - Snippets
2020-2121-// browser.runtime.sendMessage({ checkForUpdates: true }, function () {});
2222-2323-// // check if the current url is saved in the storage and extension is enabled
2424-// browser.storage.local.get(["settings"], function (data) {
2525-// if (data.settings.global && data.settings.urls.includes(window.location.origin)) {
2626-// for (let i = 0; i < data.settings.enabledPlugins.length; i++) {
2727-// runUtilsFunction("injectPlugin", data.settings.enabledPlugins[i], "doc-start");
2828-// }
2929-3030-// if (data.settings.themes) {
3131-// let theme = data.settings.currentTheme;
3232-// // eg theme = "catppuccin-macchiato-pink"
3333-// // now we have to split this into three sections, separated by the -'s
3434-// let sections = theme.split("-");
3535-// // sections will be an array containing ["catppuccin", "macchiato", "pink"]
3636-// // console.log(sections);
3737-// if (sections[0] == "catppuccin") {
3838-// injectCatppuccin(sections[1], sections[2]);
3939-// runUtilsFunction("injectCSS", "/themes/catppuccin.css");
4040-// }
4141-// }
4242-// function injectCatppuccin(flavour, accent) {
4343-// // console.log("injecting catppuccin theme");
4444-// fetch(browser.runtime.getURL("/themes/catppuccin.json"))
4545-// .then((response) => response.json())
4646-// .then((palette) => injectStyles(palette, flavour, accent));
4747-// }
4848-// function injectStyles(palette, flavour, accent) {
4949-// let style = document.createElement("style");
5050-// style.classList.add("schooltape");
5151-// let cssText = "";
5252-// for (let color in palette[flavour]["colors"]) {
5353-// let c = palette[flavour]["colors"][color];
5454-// let hsl = `${c.hsl.h} ${c.hsl.s * 100}% ${c.hsl.l * 100}%`;
5555-// cssText += `:root { --ctp-${color}: ${hsl}; }\n`;
5656-// }
5757-// let a = palette[flavour]["colors"][accent].hsl;
5858-// cssText += `:root { --ctp-accent: ${`${a.h} ${a.s * 100}% ${a.l * 100}%`}; }\n`;
5959-// style.textContent = cssText;
6060-// document.head.appendChild(style);
6161-// }
6262-// injectSnippets();
6363-// }
6464-// });
6565-6666-// // ----------------- Functions ----------------- //
6767-// function injectSnippets() {
6868-// fetch(browser.runtime.getURL("/snippets/snippets.json"))
6969-// .then((response) => response.json())
7070-// .then((data) => {
7171-// // console.log(data);
7272-// browser.storage.local.get(["settings"], function (settingsData) {
7373-// let snippets = Object.entries(data);
7474-// // Inject inbuilt snippets
7575-// snippets.forEach((snippet) => {
7676-// let snippetID = snippet[0];
7777-// let snippetPath = snippet[1].path;
7878-// let snippetToggled = settingsData.settings.enabledSnippets.includes(snippetID);
7979-// if (snippetToggled) {
8080-// runUtilsFunction("injectCSS", `/snippets/${snippetPath}`);
8181-// }
8282-// });
8383-8484-// // Inject user snippets
8585-// let userSnippets = settingsData.settings.userSnippets;
8686-// userSnippets.forEach((snippet) => {
8787-// let snippetID = Object.keys(snippet)[0];
8888-// let snippetAuthor = Object.values(snippet)[0].author;
8989-// let snippetURL = `https://gist.githubusercontent.com/${snippetAuthor}/${snippetID}/raw`;
9090-// let snippetToggled = settingsData.settings.enabledSnippets.includes(snippetID);
9191-// if (snippetToggled) {
9292-// if (snippetToggled) {
9393-// fetch(snippetURL)
9494-// .then((response) => response.text())
9595-// .then((css) => {
9696-// let style = document.createElement("style");
9797-// style.textContent = css;
9898-// style.classList.add("schooltape");
9999-// document.head.appendChild(style);
100100-// });
101101-// }
102102-// }
103103-// });
104104-// });
105105-// });
106106-// }
107107-108108-// async function runUtilsFunction(functionName, ...args) {
109109-// const src = browser.runtime.getURL("scripts/scriptUtils.js");
110110-// const utils = await import(src);
111111-// if (typeof utils[functionName] === "function") {
112112-// utils[functionName](...args);
113113-// } else {
114114-// console.error(`Function ${functionName} does not exist in utils`);
115115-// }
116116-// }
···11-import browser from "webextension-polyfill";
22-31export function injectCSS(css) {
42 let link = document.createElement("link");
53 link.rel = "stylesheet";