From 274f2870549ea0cfd4981f1d5c9b1f312ccc6101 Mon Sep 17 00:00:00 2001 From: Gerben Date: Wed, 26 Jul 2017 12:15:26 +0200 Subject: [PATCH] Make icon gray when cinema mode is disabled. --- extension/background.js | 48 ++++++++++++++---- .../img/{icon128.png => icon_active/128.png} | Bin .../img/{icon19.png => icon_active/19.png} | Bin .../img/{icon38.png => icon_active/38.png} | Bin .../img/{icon48.png => icon_active/48.png} | Bin .../img/{icon96.png => icon_active/96.png} | Bin extension/img/icon_inactive/128.png | Bin 0 -> 3321 bytes extension/img/icon_inactive/19.png | Bin 0 -> 584 bytes extension/img/icon_inactive/38.png | Bin 0 -> 1034 bytes extension/img/icon_inactive/48.png | Bin 0 -> 1281 bytes extension/img/icon_inactive/96.png | Bin 0 -> 2470 bytes extension/manifest.json | 20 ++++---- 12 files changed, 49 insertions(+), 19 deletions(-) rename extension/img/{icon128.png => icon_active/128.png} (100%) rename extension/img/{icon19.png => icon_active/19.png} (100%) rename extension/img/{icon38.png => icon_active/38.png} (100%) rename extension/img/{icon48.png => icon_active/48.png} (100%) rename extension/img/{icon96.png => icon_active/96.png} (100%) create mode 100644 extension/img/icon_inactive/128.png create mode 100644 extension/img/icon_inactive/19.png create mode 100644 extension/img/icon_inactive/38.png create mode 100644 extension/img/icon_inactive/48.png create mode 100644 extension/img/icon_inactive/96.png diff --git a/extension/background.js b/extension/background.js index 220b30a..3872ee2 100644 --- a/extension/background.js +++ b/extension/background.js @@ -10,6 +10,14 @@ function hasCinemaModeEnabled(tabId) { return !tabsWithCinemaModeDisabled[tabId]; } +function appearsToHaveCinemaModeEnabled(tabId, url) { + return ( + hasCinemaModeEnabled(tabId) + // When viewing an embedded video with cinema mode disabled, behave as if it was enabled. + || isEmbeddedVideo(url) + ); +} + // Our request filters should make use of this test unnecessary, but I prefer to keep it explicit. function isYoutube(url) { return new URL(url).hostname.endsWith('.youtube.com'); @@ -98,6 +106,8 @@ function handleNavigation(details) { if (isYoutube(details.url)) { // Show the pageAction button. browser.pageAction.show(details.tabId); + setIconActive(details.tabId, appearsToHaveCinemaModeEnabled(details.tabId, details.url)) + // In Chrome|ium, listeners stay across page changes, in Firefox they don't. So check first. if (!browser.pageAction.onClicked.hasListener(handlePageAction)) browser.pageAction.onClicked.addListener(handlePageAction); @@ -106,20 +116,40 @@ function handleNavigation(details) { // Enable/Disable cinema mode when the pageAction button is clicked. function handlePageAction(tab) { - if ( - hasCinemaModeEnabled(tab.id) - // When viewing an embedded video with cinema mode disabled, behave as if it was enabled. - || isEmbeddedVideo(tab.url) - ) { - // Disable cinema mode. - tabsWithCinemaModeDisabled[tab.id] = true; - } else { - // Enable cinema mode. + var enable = !appearsToHaveCinemaModeEnabled(tab.id, tab.url) + if (enable) { delete tabsWithCinemaModeDisabled[tab.id]; + } else { + tabsWithCinemaModeDisabled[tab.id] = true; } + setIconActive(tab.id, enable); + // Relocate this page to reflect the new mode. var newUrl = makeNewUrl(tab.url, hasCinemaModeEnabled(tab.id)); if (newUrl) browser.tabs.update(tab.id, {url: newUrl}); } + + +var activeIcons = { + '19': '/img/icon_active/19.png', + '38': '/img/icon_active/38.png', + '48': '/img/icon_active/48.png', + '96': '/img/icon_active/96.png', + '128': '/img/icon_active/128.png', +} +var inactiveIcons = { + '19': '/img/icon_inactive/19.png', + '38': '/img/icon_inactive/38.png', + '48': '/img/icon_inactive/48.png', + '96': '/img/icon_inactive/96.png', + '128': '/img/icon_inactive/128.png', +} + +function setIconActive(tabId, active) { + browser.pageAction.setIcon({ + tabId: tabId, + path: active ? activeIcons : inactiveIcons, + }) +} diff --git a/extension/img/icon128.png b/extension/img/icon_active/128.png similarity index 100% rename from extension/img/icon128.png rename to extension/img/icon_active/128.png diff --git a/extension/img/icon19.png b/extension/img/icon_active/19.png similarity index 100% rename from extension/img/icon19.png rename to extension/img/icon_active/19.png diff --git a/extension/img/icon38.png b/extension/img/icon_active/38.png similarity index 100% rename from extension/img/icon38.png rename to extension/img/icon_active/38.png diff --git a/extension/img/icon48.png b/extension/img/icon_active/48.png similarity index 100% rename from extension/img/icon48.png rename to extension/img/icon_active/48.png diff --git a/extension/img/icon96.png b/extension/img/icon_active/96.png similarity index 100% rename from extension/img/icon96.png rename to extension/img/icon_active/96.png diff --git a/extension/img/icon_inactive/128.png b/extension/img/icon_inactive/128.png new file mode 100644 index 0000000000000000000000000000000000000000..436866b0169c147b52945890668c46045c7ad050 GIT binary patch literal 3321 zcmY+H2{csi|HmKOkgXwmGuFOBwqzfBzLu|D5(;DA8(WNJ#w0@4^7R!)OcI)(WEX?6 zWUcT;WG_+3G9hI9-Om4<|2e;V?sK1W?>YDRJkP!F&+GGkQmieFIaq~Q0RSAPCWf|9 zPx#$fV9>Qo$88Ym7{d%q?O32Amc=s}x<3D<>Z*mNCtxD z=7#9Ug3J92GT%eh8Sav%HPT1kK0g1%x%~1;h~%_Ix{B-ukv8LX+1pLm-TkTCr%B`n zd-T)Mgq6RzzDx+5&@+oOvGLZ)1r;4$)n~ObyW22t&|cO4!fz?VOyX`={a(8d(}7kOOMNG**?k3239+fo24c!f;b#X^${Q?D@dZHLrt5c{M5 zqQZ1w!y0gT?j*FR(4Lr(;JGo|vUe8%D2m^!Y!P$5^t3c03_Kn8pP(;Cw5v!;!enw- ztE;QwER1$Co|LXn!Np}|%o8u2ue!RcKI5A;H8pS~l4DX9do&*LcfR=27nIBzut(?z!m<8U~|Jag>+me|zP6aX|D%@Ri@ zlS!j1Xhi|EQr__NbZSF`YB1vKST0TYt{zA+jBknD%)tC}22hmS{?ODE0$X2_x&-{% z6#a~ev-dCR9w8+vb9<)z0|G)e=UV%58k|s^!oot2Ahp{w)b;7csKXEA;})`6w5KCs zC`$?;U}IDDM1h+7{iWV2=gpKwbQ=~yt)2hY(__@g+!nIfvyE9C9v)t3z~FGL)9Y{F z($c^>8fXR zQK=xXfuH}Gp*WY4l9J@^9d!iy=$;xdL@e*9K(UYUT?sn21bDKccv(ctY{uN2OPMOk znx%7e;#08s>Lu#@GbFQbaG9XwW?w%B0Fu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/img/icon_inactive/48.png b/extension/img/icon_inactive/48.png new file mode 100644 index 0000000000000000000000000000000000000000..c3a51416fb46ed3b9866c896d1ad19fc67d998c4 GIT binary patch literal 1281 zcmV+c1^)VpP)HeVyec(!(K=>gls%)1ZvWgG(j*ig<5FK z%-aL$L}0BQY#9^zoMztpz2EzOXXgEx2m9>vWg~JI!^6XVUDpG4iYb(`va*GNfq~Zm zVsLP<8u$Y^Yp*P82qFHGQeIMp5Wfi_zHMn~;h@MsSvj)20)UN;4FFVC1whwz48y?T zaM&gsAeBn-{Q2{9Qp#UdDdqPK4Gqfi)W4)AenEUyf&0fWamB~8XU_oW=;%PxG#)*A zL?)A=t*wodCr{dHBAHAo(P;Ds1#mf?PSSsmqiEHTO_TZOPhP%!iK?nN91fzp&LnwlEB^zOhkfDou(f3u~s zs;X+sy~pFhDJ4N8@9$nE4s0u(?IZ zX0sn{sA(D_BO`dd-cOXg6_?9JZEY>Bt*zX=d6U)E)x7c9Y}Op7O5VtA1cSl6;uDF4 zm2^8ebm$PlV9-*V9n)w&>gww9)`!Dk-n@B3Utiy@7rXlUdQ0(^-oSwa2R<4zGc&{W z>(?0_9VL}YSrSudAMazyK%wZmP9zfH+O=y$B9W3Vh$S(QV`XK9(a}+E-MYn#7cWZE zM@bFjh{a;uxpRlRcki;av{cmGdtxBR%*+foZrtGBy?d;!traEbo*DqiWHL-nP7;Yk zijvRLG+GQ!oH)VNt5-R4Z+RBp3|R)zw9Ld3n+E zm&||=g7)@yu3WjY<0qt;l*B-NeLa1BeKa;UmLmNYEE#zB?p@w`pU+1q6ynU8GYBE_ z#_qO{?N~A}KR-`POUnoAFJ8Q8sq_D1c6QcMyrp$ua&nS*JZ`B2D=aK5@bKY7OKnux z{Od1-_4Rf7`}?_Y;R4Og&6anLA7X87joH~*CMG6WUtce%O-{24n=^*XielM}O+nDcb~D<$bNDf%E6jqiLEgf~=rv8l9b;=Dh-&M-`Qom4rf} zqU}*i!O^2f357ybR#uuvK&qlBua=jW15!%i_xrhh`!?}-oOnD=I-Ryz@+MBFlf#D( znbR8tRo&UIP3! rYb%u3!0&^DgJX6J*=L`9zI6Tr?m>8C1JDJJ00000NkvXXu0mjfE%#yj literal 0 HcmV?d00001 diff --git a/extension/img/icon_inactive/96.png b/extension/img/icon_inactive/96.png new file mode 100644 index 0000000000000000000000000000000000000000..f23e5b07ac0bed4775815e9ffe5ae75a46d5e4f9 GIT binary patch literal 2470 zcmV;X30d}uP)>D+#yOTY?6osGuTINep1}Z4`r_ z5~H9|H!i5bnCQk04{EIXWU^U!*h@Cv*3BB+c;Cbq4MN=Lmrp>}%PN8^pn@VGrD}mf zJNtmG)&c#rotC!qd+MBX=FI<`e>-!oQ&3P)P*6}%P*6}%P*CtG!sh{p4jr1~a5$z3 zf}r(>pkPH5#X;bS$z*!)X}HS(lgace;19qoA8QLW9teW)+XDvFMdg zYPAv@8%ub2xa@@->sTxnu3Wjo+qZ84binU4zz@y@ix)3Ouh-N6@4wM^`4Hk@KLDC3 zX+-||uc%|E0MOCVL1kqn@7}!wAUr&r?CfkNPo4~b)oP`(vXYlCUjoCws`T`9=FOYu zv%-!=^m;vu7cb`O)vL~+A5?(Rc@!TX&(QyV#(I9AtMUPcp55jB-*wyaO1`eSLFjZ91dz~YG`R`k+XaOK|(^pr-w!rA0EU`YT= zOxNeZ|6W7v>m5!Q6^mxVObiACD%J35Jv}{ic6Peb8;wRHBO_g=I2;b1K7HznpD30!c=xsj04SdsbE!TCICWIw2u})YMe( zDGw4PjeS9-CVKlnu+?2+@afN}qTXZCQRAbdqe)Ls z_gG-CqkJX(jADSF`KAG%&dyG{y1Fo%%?u3<$)zbE(P%Wp#KaI67e{=2{4YQ6YY7Gh z2B@m4;?}KObaZrhBr;S;OiUy*Gn1uDm!i|@zL@rl1~fG_arEd>dV71lDlpjT=;+|$ z#fx0Oex2gtVv>`SM@>8GGoY@njqkv9q5-X~t(-i061&|l zo48QHZntyd#0j21e?DTo!~jtgsi>%M8`Dwn44ciy>C>kXMNt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