summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--content-script.js42
-rw-r--r--manifest.json2
2 files changed, 43 insertions, 1 deletions
diff --git a/content-script.js b/content-script.js
new file mode 100644
index 0000000..4f02174
--- /dev/null
+++ b/content-script.js
@@ -0,0 +1,42 @@
+(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;
+ }
+
+ // 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,
+ });
+ }
+
+ // 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();
+})();
diff --git a/manifest.json b/manifest.json
index 802bbb6..beae3aa 100644
--- a/manifest.json
+++ b/manifest.json
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Zen Internet",
- "version": "1.8.0",
+ "version": "1.9.0",
"description": "Inject custom css from my repository in real time",
"browser_specific_settings": {
"gecko": {