From ac7050371830d4a2991d5f72d61ed71ee2289436 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 31 Dec 2015 02:31:09 +0300 Subject: [PATCH] Apply styles upon direct URL hash modification --- background.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/background.js b/background.js index be6cc985..bb658b1b 100644 --- a/background.js +++ b/background.js @@ -30,6 +30,25 @@ function webNavigationListener(method, data) { }); } +// catch direct URL hash modifications not invoked via HTML5 history API +var tabUrlHasHash = {}; +chrome.tabs.onUpdated.addListener(function(tabId, info, tab) { + if (info.status == "loading" && info.url) { + if (info.url.indexOf('#') > 0) { + tabUrlHasHash[tabId] = true; + } else if (tabUrlHasHash[tabId]) { + delete tabUrlHasHash[tabId]; + } else { + // do nothing since the tab neither had # before nor has # now + return; + } + webNavigationListener("styleReplaceAll", {tabId: tabId, frameId: 0, url: info.url}); + } +}); +chrome.tabs.onRemoved.addListener(function(tabId, info) { + delete tabUrlHasHash[tabId]; +}); + chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { switch (request.method) { case "getStyles":