Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/background/events/injects/st_detect_inject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Module } from "../../../types/module"

export default <Module>{
action: async (base) => {
await chrome.scripting.executeScript({
target: { tabId: base.tab_id },
files: ["detect_schooltape.js"],
})
},
}
2 changes: 2 additions & 0 deletions src/background/events/on_update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import box_of_books from "./injects/box_of_books"
import launcher_shortcut from "./injects/launcher_shortcut"
import news_tracker_fetch from "./injects/news_tracker"
import news_tracker_display from "./injects/display_history"
import detect_schooltape from "./injects/st_detect_inject"

const INJECTS = [
dark_theme_css,
Expand All @@ -17,6 +18,7 @@ const INJECTS = [
launcher_shortcut,
news_tracker_fetch,
news_tracker_display,
detect_schooltape
]

export default async function on_update(tab_id: number, _: any, tab: chrome.tabs.Tab) {
Expand Down
14 changes: 14 additions & 0 deletions src/background/set_default_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,17 @@ export async function init_settings(): Promise<void> {

await poll_feed()
}

export async function set_setting<K extends keyof Settings>(key: K, value: Settings[K]): Promise<void> {
const current_settings = await chrome.storage.sync.get("settings")
if (!current_settings.settings) {
console.error("Settings not initialized yet.")
return
}

const new_settings = {
...current_settings.settings,
[key]: value,
}
await chrome.storage.sync.set({ settings: new_settings })
}
29 changes: 25 additions & 4 deletions src/content/auto_detection/detect_schooltape.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { set_setting } from "../../background/set_default_settings"

async function main() {
// create marker
const marker = document.createElement("div")
Expand All @@ -8,17 +10,36 @@ async function main() {
const observer = new MutationObserver(mutations => {
for (let mutation of mutations) {
if (mutation.type === "childList") {
// check for updated nodes
// check for added nodes
if (mutation.addedNodes.length > 0) {
Array.from(mutation.addedNodes).some(node => node)
Array.from(mutation.addedNodes).forEach(async node => {
if (
node.nodeType === Node.ELEMENT_NODE &&
(node as Element).getAttribute("data-schooltape") === "stylesheet-themes"
) {
console.log("[Schooltape Detection] Detected Schooltape stylesheet added to the page.")
await set_setting("schooltape_compatibility", true)
}
})
}
// check for removed nodes
if (mutation.removedNodes.length > 0) {
Array.from(mutation.removedNodes).forEach(async node => {
if (
node.nodeType === Node.ELEMENT_NODE &&
(node as Element).getAttribute("data-schooltape") === "stylesheet-themes"
) {
console.log("[Schooltape Detection] Detected Schooltape stylesheet removed from the page.")
await set_setting("schooltape_compatibility", false)
}
})
}
}
}
})
observer.observe(document.head, { childList: true, subtree: true })
}

//8=========D

const marker_elem = document.querySelector("[data-ultrabox-schooltape-marker]")
if (!marker_elem) {
main()
Expand Down
1 change: 1 addition & 0 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module.exports = (env, argv) => {
history_puller: "./src/content/modules/post_history_tracking/puller.ts",
detect_domain: "./src/content/auto_detection/detect_domain.ts",
detect_rss_feed: "./src/content/auto_detection/detect_rss_feed.ts",
detect_schooltape: "./src/content/auto_detection/detect_schooltape.ts",
},

output: {
Expand Down
Loading