From f765934316a3eab99268a4fa053a11725827740c Mon Sep 17 00:00:00 2001 From: tophf Date: Fri, 15 May 2015 00:24:10 +0300 Subject: [PATCH] Dim toolbar icon on unstyled tabs, regenerate icons --- 128.png | Bin 1413 -> 1398 bytes 16.png | Bin 395 -> 369 bytes 19.png | Bin 450 -> 431 bytes 19w.png | Bin 0 -> 446 bytes 38.png | Bin 0 -> 618 bytes 38w.png | Bin 0 -> 619 bytes 48.png | Bin 834 -> 711 bytes apply.js | 2 +- background.js | 19 +++++++++------- manifest.json | 7 ++++-- messaging.js | 59 ++++++++++++++++++++++++++++++++++---------------- 11 files changed, 57 insertions(+), 30 deletions(-) create mode 100644 19w.png create mode 100644 38.png create mode 100644 38w.png diff --git a/128.png b/128.png index 1961df309651cf5285e371a01c3b6225b51fbdb8..d3579ad6c198c9c172c3fcfec6d264e62bb61885 100644 GIT binary patch delta 1350 zcmV-M1-bf#3-$_-L4O%^MObuGZ)S9NVRB^vL1b@YWgtmyVP|DhWnpA_ami&o0001H zP)t-s0000wJ3AvB7Ik`kuEk=W$l(6+1<;#y|NsBJKrs*w3obDhh%O_)zrWbn*iR}M zSYj>j@9$t>U};V}fqMdbi$zUOP@kWl!np*mudk1fkES>)yMK#mqM8Gpu~_2R1d(h} zg{i$`R>JZC00fCiL_t(|+U=X^mZC5ag-tRD9Y|PORu%2{f637XWXql?Gv{!BcK4W% zsw8!*a1MuEyLSB}`eUp9bH0?d1MC3*H$a=`$xM0vF@QV?q2M@2=XV0MNvLq8z&MWH z0+5Fq7aNRav47A6XcMe`yJ8`P9zc!_ulU#rK+6g~27{mxfd;_h@j-?N2^ONHMhF1b zxv&P9ek#uDG!Ti_Xb}-?2`~*mr~@UX4~p?$ovi@c@o@?o=!gsukrlw}`5_6kn1Aj0CjdH|2HEq0C|)MW)Rs#lfRmOzpon6V#w1*d573McxBB~jKoLRh){G;f zdkTh+KX+lk(U%;#JWCqWHhN??M}@OObCfPa~q>`Xfmkh=?10bb6aPbbo2D7iUM2k@7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+Yu5&oia40jPCps4%W&SGK$?*VS!wpKJZzW_xGqcE4#7-q@<)KCMIl%n2awZnwpwh zTwKn?1Z;Xeevd~-FD6u3H-TVC{_+Jf5e?4H&T49Es;a7NY=3NKA{y%I>W!dJt$|^8 zaRNm`0nM3nWnv4Um;;NRPS@Ah2_NCo0001uNkl3b~fj@ z|Mdxn(m}sj-2)$R65uR%>3f{#3UnB)ja9WE=pu)d(<=gzZf-tM{{cXcZyZ?pf|$TC z#1oAwHRK6r_DnRY)I$W9SIw5-ivBt3GXNu~#QoLYjsW%tE;P*U(hDgIK&f65teHM= l9-4F)P`GKmM=1+T`U3nf34$T6$$0<(002ovPDHLkV1g90k%RyM diff --git a/19.png b/19.png index 9ea023436a4f9fbed171917f94f823b8a30e8d88..69babc93471c0400b4ea9937ae9f032bedce5d96 100644 GIT binary patch delta 375 zcmV--0f_#>1Fr*+L4O%^MObuGZ)S9NVRB^vL1b@YWgtmyVP|DhWnpA_ami&o0001f zP)t-s0000D3It$aV86e=uEk=W$l!p0fdBvhy+AS0n{^-_9X&un{_+JdFfdvMntwDXudlB`77)FSYLAbP zl)TcItX9v@&v%xnBMb>&TLLgG0nWt)gOp0h5Xz7M0062ifPd{$u-^*yZa_)__jyc~tBkocJx04A!+cq?yt2!Z z($ahxWo$x44sb}#-fY%PB>{%M^Tv6N!)+Li(YRQ{8&}jtTR^RT8r%n48hEu0ayQT+ zSb;Hmv@K|B{!wd`89SakU7ZMt7SiGztX8GoXcBgtH(tXNl>HZZBgr@%TtG;$-##~j V3q@WuP;meN002ovPDHLkV1gbkpuPYA delta 395 zcmV;60d)Sa1HuE4L4OHwNLh0L01m+b01m+cxRGn^0001!P)t-s|NsB|{QR%4ujAw6 zuEk=W$l#EWjQ{`uy+AS0n{^)_AN}zJEF~prX=hR#7It=YtHNNTqoF)KJsS`S&d$yY z3jn2*~)?xn(OoN%nxbX&r3>E~8WcTAge=iS%uEoy{Hn pziD<&_5P}}Iff7dsdcjF?lhha{}pt&V*mgE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ehlbmj{~6J4Jj}_ZZstUO6N^bI*yD-fkH~)j(P)K^#=X|KXgWC7$R2C00000 MNe4wvM6N<$f@tPosQ>@~ diff --git a/apply.js b/apply.js index 179a0817..7c141c8d 100644 --- a/apply.js +++ b/apply.js @@ -14,8 +14,8 @@ function requestStyles() { if (location.href.indexOf(chrome.extension.getURL("")) == 0) { var bg = chrome.extension.getBackgroundPage(); if (bg && bg.getStyles) { + // apply styles immediately, then proceed with a normal request that will update the icon bg.getStyles(request, applyStyles); - return; } } chrome.extension.sendMessage(request, applyStyles); diff --git a/background.js b/background.js index 8ad9d131..9c011585 100644 --- a/background.js +++ b/background.js @@ -2,6 +2,7 @@ // why the content script also asks for this stuff. chrome.webNavigation.onCommitted.addListener(webNavigationListener.bind(this, "styleApply")); chrome.webNavigation.onHistoryStateUpdated.addListener(webNavigationListener.bind(this, "styleReplaceAll")); +chrome.webNavigation.onBeforeNavigate.addListener(webNavigationListener.bind(this, null)); function webNavigationListener(method, data) { // Until Chrome 41, we can't target a frame with a message // (https://developer.chrome.com/extensions/tabs#method-sendMessage) @@ -11,19 +12,21 @@ function webNavigationListener(method, data) { return; } getStyles({matchUrl: data.url, enabled: true, asHash: true}, function(styleHash) { - chrome.tabs.sendMessage(data.tabId, {method: method, styles: styleHash}); - // Don't show the badge for frames - if (data.frameId == 0 && prefs.getPref("show-badge")) { - delete styleHash.disableAll; - chrome.browserAction.setBadgeText({text: getBadgeText(Object.keys(styleHash)), tabId: data.tabId}); + if (method) { + chrome.tabs.sendMessage(data.tabId, {method: method, styles: styleHash}); } + updateIcon({id: data.tabId}, styleHash) }); } chrome.extension.onMessage.addListener(function(request, sender, sendResponse) { switch (request.method) { case "getStyles": - getStyles(request, sendResponse); + var styles = getStyles(request, sendResponse); + if (request.matchUrl && sender && sender.tab && sender.frameId == 0) { + // this is a main content frame, so update the icon + updateIcon(sender.tab, styles); + } return true; case "saveStyle": saveStyle(request, sendResponse); @@ -123,11 +126,11 @@ function getStyles(options, callback) { } }); callback(styles); + return styles; } if (cachedStyles) { - callCallback(); - return; + return callCallback(); } getDatabase(function(db) { diff --git a/manifest.json b/manifest.json index 98f13be6..e2c2ba5e 100644 --- a/manifest.json +++ b/manifest.json @@ -5,7 +5,7 @@ "homepage_url": "https://userstyles.org", "manifest_version": 2, "icons": { - "16": "16.png", + "16": "16.png", "48": "48.png", "128": "128.png" }, @@ -43,7 +43,10 @@ ], "options_page": "manage.html", "browser_action": { - "default_icon": "19.png", + "default_icon": { + "19": "19w.png", + "38": "38w.png" + }, "default_title": "Stylish", "default_popup": "popup.html" }, diff --git a/messaging.js b/messaging.js index 6921f1f0..0f6032a0 100644 --- a/messaging.js +++ b/messaging.js @@ -3,7 +3,7 @@ function notifyAllTabs(request) { windows.forEach(function(win) { win.tabs.forEach(function(tab) { chrome.tabs.sendMessage(tab.id, request); - updateBadgeText(tab); + updateIcon(tab); }); }); }); @@ -16,24 +16,45 @@ function notifyAllTabs(request) { chrome.extension.sendMessage(reqPopup); } -function updateBadgeText(tab) { - if (prefs.getPref("show-badge")) { - function stylesReceived(styles) { - var t = getBadgeText(styles); - console.log("Tab " + tab.id + " (" + tab.url + ") badge text set to '" + t + "'."); - chrome.browserAction.setBadgeText({text: t, tabId: tab.id}); - } - // if we have access to this, call directly. a page sending a message to itself doesn't seem to work right. - if (typeof getStyles != "undefined") { - getStyles({matchUrl: tab.url, enabled: true}, stylesReceived); - } else { - chrome.extension.sendMessage({method: "getStyles", matchUrl: tab.url, enabled: true}, stylesReceived); - } +var defaultBadgeColor = "red"; +chrome.browserAction.getBadgeBackgroundColor({}, function(color) { + defaultBadgeColor = color; +}); + +function updateIcon(tab, styles) { + if (styles) { + // check for not-yet-existing tabs e.g. omnibox instant search + chrome.tabs.get(tab.id, function() { + if (!chrome.runtime.lastError) { + // for 'styles' asHash:true fake the length by counting numeric ids manually + if (styles.length === undefined) { + styles.length = 0; + for (var id in styles) { + styles.length += id.match(/^\d+$/) ? 1 : 0; + } + } + stylesReceived(styles); + } + }); + return; + } + // if we have access to this, call directly. a page sending a message to itself doesn't seem to work right. + if (typeof getStyles != "undefined") { + getStyles({matchUrl: tab.url, enabled: true}, stylesReceived); } else { - chrome.browserAction.setBadgeText({text: "", tabId: tab.id}); + chrome.extension.sendMessage({method: "getStyles", matchUrl: tab.url, enabled: true}, stylesReceived); + } + + function stylesReceived(styles) { + var disableAll = prefs.getPref("disableAll"); + var postfix = styles.length == 0 || disableAll ? "w" : ""; + chrome.browserAction.setIcon({ + path: {19: "19" + postfix + ".png", 38: "38" + postfix + ".png"}, + tabId: tab.id + }); + var t = prefs.getPref("show-badge") && styles.length ? ("" + styles.length) : ""; + chrome.browserAction.setBadgeText({text: t, tabId: tab.id}); + chrome.browserAction.setBadgeBackgroundColor({color: disableAll ? "#aaa" : defaultBadgeColor}); + //console.log("Tab " + tab.id + " (" + tab.url + ") badge text set to '" + t + "'."); } } - -function getBadgeText(styles) { - return styles.length == 0 ? "" : ("" + styles.length); -}