From c2b9015309f7182f7dfd1017bc91e27afcaa4247 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 16 Jul 2022 21:20:30 +0200 Subject: [PATCH] Page action and quicker. --- background.js | 54 ++++++++++++++++++++++++++++++++---------------- button/19.png | Bin 0 -> 1656 bytes button/38.png | Bin 0 -> 3262 bytes manifest.json | 11 +++++++++- to-invidious.js | 32 ++++++++++++++-------------- 5 files changed, 62 insertions(+), 35 deletions(-) create mode 100644 button/19.png create mode 100644 button/38.png diff --git a/background.js b/background.js index 7e5d276..4e38493 100644 --- a/background.js +++ b/background.js @@ -1,3 +1,5 @@ +let urlFromStorage + // Storage init browser.runtime.onInstalled.addListener(function() { browser.storage.sync.set({ @@ -5,6 +7,12 @@ browser.runtime.onInstalled.addListener(function() { }); }); +browser.storage.sync.onChanged.addListener(function(changes) { + if (changes.url && changes.url.newValue) { + urlFromStorage = changes.url.newValue + } +}) + // Url format function getVideoToken(url) { @@ -25,25 +33,35 @@ function cleanToken(token) { } -// Links click event handling -browser.runtime.onMessage.addListener(function(message) { + +function toInvidious(message) { let url = message.url; const name = message.targetName; - browser.storage.sync.get("url").then(function(item) { - const subst = item.url + `/watch?v=`; - let token = getVideoToken(url) - const cleanedToken = cleanToken(token) - url = url.replace(/.*\/watch\?v=/gm, subst); + const subst = urlFromStorage + `/watch?v=`; + let token = getVideoToken(url) + const cleanedToken = cleanToken(token) + url = url.replace(/.*\/watch\?v=/gm, subst); - if (name != "_self") { - browser.tabs.create( - {active: true, url: url} - ); - } else { - browser.tabs.update( - {url: url, loadReplace: false} - ) - } - console.log('Youtube to invidious is redirecting you to invidious') - }) + if (name != "_self") { + browser.tabs.create( + {active: true, url: url} + ); + } else { + browser.tabs.update( + {url: url, loadReplace: false} + ) + } + console.log('Youtube to invidious is redirecting you to invidious') +} + + +// Links click event handling +browser.runtime.onMessage.addListener(function(message) { + toInvidious(message) +}); + + +// Page action +browser.pageAction.onClicked.addListener(function(page) { + toInvidious({url: page.url, targetName: "_self"}); }); \ No newline at end of file diff --git a/button/19.png b/button/19.png new file mode 100644 index 0000000000000000000000000000000000000000..564a7eb375e9c468ed77b8119f9318c3863a29c0 GIT binary patch literal 1656 zcmY*ZX;4#F6uw~-0+gYMgr$&zgV6#Z0kJ&75(pTUU=q-RvPDQRB8wy;k+Mr+0D)ow z5pV{TwwOWLsa34F42z*)K{ineC;_9guY%AQq}bj!_nq&4_dDM?=lysYRL{ezNF5{q zK-HB@qQg-`x)l}RcQnCo| zKoSH1R0M!lROuZW0lr9O`na+v6mS5>ia;LmC6I*?0)7BO2T0vu1l$n1JD85ZY-?ly zNM{4NZOw5wN*5X4(wt9GwhZyvu}o%1tx+cX8B5c8j@teV2c;;oF9!f+ct~Xp1Sl>= z!EU~6Zy&A?#RCeC3^!whM4n`t3BseKS%4sbU>MHiGSGtXGZ7p}U~9OgfM6`8v4-d^ z2{+8v(1$`rJ4Hq_(N<>WX6A-=NHiKvhz?;vbdt++m_v~q7LPZD6{ehX5nP7AG=gLF$>d)j5|a}g&5q)-BO}mKU&hHu9@o~;P+Dkb zed?3TW__*{!Py=Q9uORl|EHNx zlWwu_sCGyKcIUI%A+-ZWcL5-~>PjMdf2*FIALgNVba!jlJqw#UwE_PDfBh50;`-47 zYIw?z&s=D(M6xPku%+lurg6f8dvLefvz6ZBBB8;|^~XLMUh=!$n^797d)VQsjhK++ zTc(u_Q=KaBnqsCFRa``(Nmt`#94BG^{w9ajma(zXzkY!>@C`=3rw{pVN~O^tF+XWQS1;)M;!}v3`P$N5Zi80(`{YUqk!rn{9Ov6*3;j%Ddu`l8SQu3ooysRM zSkubjPTMjR%VPz)l3-r>mY7FRUip|GiE6GdaS>CG%)B&eU*V@#9UZ#EI~0@XB%Er~ zSW8@85)Hhb7qNKV_ch748tUVQxo^6ELMwutI*OhHuH2yF%FU&&KQ?O>l6gvkrP<%U z=rov05VFpSdotU#=zZ}@*cu)IpX4JHGO2VKlahw^H$5_z2N9)^{CfY13(*u6*0F1A z&jVG$a*PHi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KC*j8O@i0b z!s4iwAH6+cc6L^jLZRRQwo9a{j`GFY$(%Oj_AGQ%H52wBC7whikv4$t-tQjcr*_uoHld~MD?jy~k5fE;nq4s4dG#io zHyHz)J%JZOHcaL}x%Rdqo|8Go>Ff4BYvT~B_Y-WIbI&6%U?T43;_K_{HlO%%ciB$$ zXFhhzncL}kN)*OugwRl%mzVdE3hJDWWfd3}`?3;F$#8LdP*x_*QPo#oQ6Yx%pJiE4 zlDHz76PxBw=!k^M44oMr9Tkc>%T39!i5x=i@yx@HfwSS6#!(^xPK|!g*tI2{d2C+r z0as%M*tkza<>YRyPBtI___FpGNCwLSu5*kUu|RUW2DvfM%D7KFa{rJfZI(mdI_D)Y zrj7ri8S#Vc#Au`$$6TEWcetiq%6H5$MU!t3aw?ju8*_{|Cs9a_$PBEuhHi6o3Fc9Y zS$IwbuS`85f9y%Y=tj9fXBz$Qk(S@pjjhhKhO*ix{>k!uOy9~X6Aa`p5NWK~?T-Vw zs<{xvj@U&^(e7-2`j{{ z=#TdQ_z`9m6r|F9oV{FhyzRz8kzE5pe|Tghq$3J?(m9TYo4d#LMUq2-R(R8K`z-c9 zuxD4s*TCy;fe@;0htl$NbHiSLwj$`ZxVV%dL$c}j2x4exxbvRtQ-+*fPGqGxwo2&~ zSE^q7J_f?Krt8q+zxQpi4dK|*DAfM4H% 0) { + // if (window.location.href.indexOf("google.") >= 0) { // const elements = document.getElementsByClassName("NqpkQc"); // while(elements.length > 0){ // elements[0].parentNode.removeChild(elements[0]); // } // } - if (window.location.href.indexOf('youtube.com') > 0) { + if (window.location.href.indexOf('youtube.com') >= 0) { tags = el.querySelectorAll('a[href*="/watch"]'); } else { tags = el.querySelectorAll('a[href*="youtube.com/"]'); @@ -22,22 +22,22 @@ function findATagsAndAddListener(el) { function addListenerToATag(tag) { tag.addEventListener('click', function(e) { - e.preventDefault(); - e.stopImmediatePropagation(); + e.preventDefault(); + e.stopImmediatePropagation(); - // Find the a tag - var target = e.target; - while ((target.tagName != "A" || !target.href) && target.parentNode) { - target = target.parentNode; - } - - let targetName = (target.attributes.target != null ? target.attributes.target.nodeValue : '_self') - if (e.ctrlKey || e.metaKey) { - targetName = "_blank"; - } + // Find the a tag + var target = e.target; + while ((target.tagName != "A" || !target.href) && target.parentNode) { + target = target.parentNode; + } + + let targetName = (target.attributes.target != null ? target.attributes.target.nodeValue : '_self') + if (e.ctrlKey || e.metaKey) { + targetName = "_blank"; + } - browser.runtime.sendMessage({"url": target.href, "targetName": targetName}); - }) + browser.runtime.sendMessage({"url": target.href, "targetName": targetName}); + }) } // Add the event listeners to the current elements of the body