Last active
December 27, 2024 04:44
-
-
Save mdashlw/dd7b16177e5a81c2ba1a307c9b4d5b60 to your computer and use it in GitHub Desktop.
philomena rainbow theme chrome extension. Instructions: Download ZIP, extract, enable Developer mode on Extensions page, "Load unpacked"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "manifest_version": 3, | |
| "name": "Philomena Rainbow Theme", | |
| "version": "1.0.0", | |
| "description": "Rainbow theme color for Derpibooru", | |
| "permissions": ["declarativeNetRequest", "webRequest"], | |
| "host_permissions": ["https://derpibooru.org/*"], | |
| "background": { | |
| "service_worker": "service_worker.js" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fetch("https://derpibooru.org/themes") | |
| .then((r) => r.json()) | |
| .then(async (json) => { | |
| const entries = Object.entries(json).map(([name, path]) => [ | |
| name, | |
| path.substring(0, path.indexOf("?")), | |
| ]); | |
| const darkThemePaths = entries | |
| .filter(([name]) => name.startsWith("dark-")) | |
| .map(([, path]) => path); | |
| const lightThemePaths = entries | |
| .filter(([name]) => name.startsWith("light-")) | |
| .map(([, path]) => path); | |
| await chrome.storage.session.set({ | |
| darkThemePaths, | |
| lightThemePaths, | |
| }); | |
| }); | |
| chrome.webRequest.onBeforeRequest.addListener( | |
| async () => { | |
| const { darkThemePaths, lightThemePaths } = | |
| await chrome.storage.session.get(["darkThemePaths", "lightThemePaths"]); | |
| if (!darkThemePaths?.length || !lightThemePaths?.length) { | |
| return; | |
| } | |
| const randomDarkTheme = | |
| darkThemePaths[Math.floor(Math.random() * darkThemePaths.length)]; | |
| const randomLightTheme = | |
| lightThemePaths[Math.floor(Math.random() * lightThemePaths.length)]; | |
| chrome.declarativeNetRequest.updateSessionRules({ | |
| addRules: [ | |
| { | |
| id: 1, | |
| action: { | |
| type: "redirect", | |
| redirect: { | |
| transform: { | |
| path: randomDarkTheme, | |
| query: "?no&vsn=d", | |
| }, | |
| }, | |
| }, | |
| condition: { | |
| urlFilter: "||derpibooru.org/css/dark-*?vsn=d", | |
| resourceTypes: ["stylesheet"], | |
| }, | |
| }, | |
| { | |
| id: 2, | |
| action: { | |
| type: "redirect", | |
| redirect: { | |
| transform: { | |
| path: randomLightTheme, | |
| query: "?no&vsn=d", | |
| }, | |
| }, | |
| }, | |
| condition: { | |
| urlFilter: "||derpibooru.org/css/light-*?vsn=d", | |
| resourceTypes: ["stylesheet"], | |
| }, | |
| }, | |
| ], | |
| removeRuleIds: [1, 2], | |
| }); | |
| }, | |
| { | |
| urls: [ | |
| "https://derpibooru.org/css/dark-*?vsn=d", | |
| "https://derpibooru.org/css/light-*?vsn=d", | |
| ], | |
| }, | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment