aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2018-08-04 03:35:30 +0200
committerTeddy Wing2018-08-04 03:35:30 +0200
commit0db68f29c4631338e8fee87c9d819f2ea21ba032 (patch)
tree55575f12d9ddca41f4303cfc2f585dc6c31aa091
parent76f1058d353100c0e73720349da1c79f0aa2c193 (diff)
downloadLegibility-0db68f29c4631338e8fee87c9d819f2ea21ba032.tar.bz2
Match CSS files with the domain hostname
Load a CSS file based on the current page's domain (e.g. "example.com"). Use: https://stackoverflow.com/questions/13367376/get-the-domain-name-of-the-subdomain-javascript/13367604#13367604 to give us the hostname without any subdomains. This will apply the CSS to all subdomains on the site. Not sure if this what we want yet, but it seemed simpler to consolidate like this now rather than splitting CSS by each subdomain or adding some kind of complicated matching/wildcard logic. Errors are ignored and just happen if the file for the current domain doesn't exist. This seems okay to me to leave errors unhandled, as there doesn't appear to be a clean way to handle them, and even if there was, we'd just be either ignoring them anyway or conditionally executing `insertCSS()`, which seems unnecessary.
-rw-r--r--background.js4
-rw-r--r--content.js7
2 files changed, 8 insertions, 3 deletions
diff --git a/background.js b/background.js
index 44a5c2a..f8b3a71 100644
--- a/background.js
+++ b/background.js
@@ -4,6 +4,6 @@ if (chrome) {
browser = chrome;
}
-browser.runtime.onMessage.addListener(function() {
- browser.tabs.insertCSS({ file: '/css/example.com.css' });
+browser.runtime.onMessage.addListener(function(message) {
+ browser.tabs.insertCSS({ file: '/css/' + message.domain + '.css' });
});
diff --git a/content.js b/content.js
index bf355f2..7d9c68d 100644
--- a/content.js
+++ b/content.js
@@ -4,4 +4,9 @@ if (chrome) {
browser = chrome;
}
-browser.runtime.sendMessage({ url: 'tmp' });
+var domain = location.hostname
+ .split('.')
+ .slice(-2)
+ .join('.');
+
+browser.runtime.sendMessage({ domain: domain });