Updated manifest to v3 and added "css" to content scripts#39
Updated manifest to v3 and added "css" to content scripts#39vittoopugliese wants to merge 1 commit into
Conversation
| }, | ||
| "background": { | ||
| "scripts": ["background.js"] | ||
| "service_worker": "background.js" |
There was a problem hiding this comment.
I don't think this is required given what this plugin is doing, albeit I've only tested this on Chrome, not Edge. The unpacked extension works as it previously did with the changes I mention below, but requires more testing.
|
Testing the above it didn't work for me so I've made some adjustments.
and then updating the background.js |
|
let's merge that one @iamdiogo @MyNameIsJulian! |
|
@CTRPaul
I would change this a bit so it stops checking the rest of the mutated nodes when it has already re-added the CSS and keeps a reference to the // background.js
const link = document.createElement('link');
link.id = 'darkstyle_css';
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = chrome.extension.getURL('css_dark.css');
link.media = 'all';
document.head.appendChild(link);
const observer = new MutationObserver((mutationsList) => {
'use strict';
for (const mutation of mutationsList) {
for (const node of mutation.removedNodes) {
if (node.id !== 'darkstyle_css') continue;
document.head.appendChild(link);
return;
}
}
});
observer.observe(document, { childList: true, subtree: true });Also, here is the JSON you posted, formatted for ease of reading{
"name": "DarkCloud",
"description": "SoundCloud Dark Theme",
"version": "2024.07.30",
"permissions": ["scripting"],
"manifest_version": 3,
"icons": {
"128": "darklogo.png"
},
"action": {
"default_title": "DarkCloud",
"default_icon": "darklogo.png"
},
"web_accessible_resources": [
{
"resources": ["css_dark.css"],
"matches": ["https://soundcloud.com/*"]
}
],
"content_scripts": [
{
"matches": ["https://soundcloud.com/*"],
"js": ["background.js"],
"css": ["css_dark.css"],
"run_at": "document_start"
}
]
} |
|
I just realized for const link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = chrome.extension.getURL('css_dark.css');
document.head.appendChild(link);
const observer = new MutationObserver(() => link.parentNode == null && document.head.appendChild(link));
observer.observe(document, { childList: true, subtree: true });The |
I have noticed that the extension stopped working at least on my Chrome and it seems that updating the manifest to v3 and loading the "css_dark.css" in the "css" prop inside "content_scripts" fixes it, also changed the version in case this is approved, but I don't know if that's correct.
I am trying to resolve some CSS issues that are open, I will push them sooner!
I hope this helps! Please tell me if there's something wrong..