From b377be8a18f4be84bfaa64ec3c874ef0f627e3c5 Mon Sep 17 00:00:00 2001 From: hideheader Date: Mon, 23 Feb 2015 00:25:24 -0500 Subject: [PATCH] Reload styles on `history.pushState` --- background.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/background.js b/background.js index 1f204e63..6d07794e 100644 --- a/background.js +++ b/background.js @@ -319,3 +319,20 @@ chrome.tabs.onAttached.addListener(function(tabId, data) { } }); }); + +chrome.webNavigation.onHistoryStateUpdated.addListener(function (details) { + var now = new Date(); + console.log("%conHistoryStateUpdate %s: %s(%s)\n url=%s", "color:olive", now.toTimeString().substr(0,8), + details.transitionType, details.transitionQualifiers.join(" "), details.url); + var request = { + enabled: true, + matchUrl: details.url, + asHash: true + }; + getStyles(request, function(r) { + chrome.tabs.sendMessage(details.tabId, {method: "styleReplaceAll", styles: r}); + if (details.frameId === 0 && localStorage["show-badge"] === "true") { + chrome.browserAction.setBadgeText({text: getBadgeText(Object.keys(r)), tabId: details.tabId}); + } + }); +});