summaryrefslogtreecommitdiff
path: root/content-script.js
diff options
context:
space:
mode:
authorsameerasw <[email protected]>2025-04-29 22:07:14 +0530
committersameerasw <[email protected]>2025-04-29 22:07:14 +0530
commit76c2fbe1b5c63a9f6ad74a5a726f9a308b1ab9db (patch)
tree7f6883682f7f1b95cdf3e0041ec6f13b3c9a6f80 /content-script.js
parent3abd67a040c840738684a78d91f654d583550f41 (diff)
Fixed theming for existing users
Diffstat (limited to 'content-script.js')
-rw-r--r--content-script.js85
1 files changed, 47 insertions, 38 deletions
diff --git a/content-script.js b/content-script.js
index 4f02174..4e99e29 100644
--- a/content-script.js
+++ b/content-script.js
@@ -1,42 +1,51 @@
-(function() {
- const stylesheetId = 'zeninternet-custom-styles';
-
- // Create or get our stylesheet element
- function getStylesheet() {
- let stylesheet = document.getElementById(stylesheetId);
- if (!stylesheet) {
- stylesheet = document.createElement('style');
- stylesheet.id = stylesheetId;
- stylesheet.type = 'text/css';
- document.head.appendChild(stylesheet);
- }
- return stylesheet;
+(function () {
+ const stylesheetId = "zeninternet-custom-styles";
+
+ // Create or get our stylesheet element
+ function getStylesheet() {
+ let stylesheet = document.getElementById(stylesheetId);
+ if (!stylesheet) {
+ stylesheet = document.createElement("style");
+ stylesheet.id = stylesheetId;
+ stylesheet.type = "text/css";
+ document.head.appendChild(stylesheet);
}
-
- // Update our stylesheet content
- function updateStyles(css) {
- const stylesheet = getStylesheet();
- stylesheet.textContent = css || '';
- console.log('ZenInternet: Styles were ' + (css ? 'updated' : 'removed'));
- }
-
- // Announce content script is ready and provide current hostname
- function announceReady() {
- browser.runtime.sendMessage({
- action: 'contentScriptReady',
- hostname: window.location.hostname,
+ return stylesheet;
+ }
+
+ // Update our stylesheet content
+ function updateStyles(css) {
+ const stylesheet = getStylesheet();
+ stylesheet.textContent = css || "";
+ console.log("ZenInternet: Styles were " + (css ? "updated" : "removed"));
+ }
+
+ // Announce content script is ready and provide current hostname
+ function announceReady() {
+ try {
+ browser.runtime
+ .sendMessage({
+ action: "contentScriptReady",
+ hostname: window.location.hostname,
+ })
+ .catch((err) => {
+ // Silent fail - background might not be ready yet
+ console.log("ZenInternet: Could not announce ready state");
});
+ } catch (e) {
+ // Fail silently
+ }
+ }
+
+ // Listen for messages from background script
+ browser.runtime.onMessage.addListener((message) => {
+ if (message.action === "applyStyles") {
+ updateStyles(message.css);
+ return Promise.resolve({ success: true });
}
-
- // Listen for messages from background script
- browser.runtime.onMessage.addListener((message) => {
- if (message.action === 'applyStyles') {
- updateStyles(message.css);
- return Promise.resolve({ success: true });
- }
- return false;
- });
-
- // Announce content script is ready on load
- announceReady();
+ return false;
+ });
+
+ // Announce content script is ready on load
+ announceReady();
})();