Add toolbar button to disable the extension

parent 941e9da1
......@@ -52,4 +52,4 @@ Some websites (like joinmastodon.org) use this API to generate the iFrame.
So, the browser needs first to load a script called `iframe_api` on `youtube.com` and then load a script called `www-widgetapi.js` on `s.ytimg.com`.
To bypass this need, those two files have been integrated in the extension, so you never have to call youtube to generate the iFrame.
The reason why you need to allow frames is the same explained above: Invidition can't read the iFrame URL if you block it.
\ No newline at end of file
The reason why you need to allow frames is the same explained above: Invidition can't read the iFrame URL if you block it.
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created using Krita: http://krita.org -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="607.68pt"
height="607.68pt"
viewBox="0 0 607.68 607.68"
version="1.1"
id="svg3785"
sodipodi:docname="logo.svg"
inkscape:version="0.92.3 (2405546, 2018-03-11)">
<metadata
id="metadata3789">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1023"
id="namedview3787"
showgrid="false"
inkscape:zoom="1.0034064"
inkscape:cx="405.12"
inkscape:cy="405.12"
inkscape:window-x="0"
inkscape:window-y="0"
inkscape:window-maximized="1"
inkscape:current-layer="svg3785" />
<defs
id="defs3779" />
<g
id="group0"
transform="matrix(0.1,0,0,0.1,0,-0.55354834)"
style="fill:none">
<path
id="shape0"
transform="translate(6.9926481,120.15091)"
d="m 2763.01,5828.85 c -775,-68 -1523,-436 -2020.003,-994 -491,-551 -742.99964812,-1200 -742.99964812,-1915 -0.99999988,-466 99.99964812,-884 311.99964812,-1296 146,-284 307,-502 540,-734.001 172.003,-171 264.003,-247 461.003,-378 415,-277 905,-451.9999 1404,-500.9999 161,-16.00001 508,-14.00001 666,4 914,104.9999 1715,589.9999 2213,1342.0009 306,462 467,995 467,1553 0,268 -22,448 -85,699 -94,378 -293,778 -541,1091 -156,196 -449,465 -665,611 -405,272 -894,453 -1379,509 -130,15 -502,21 -630,9 z m 475,-139 c 527,-39 1012,-203 1435,-485 176,-117 274,-198 436,-360 315,-313 518,-633 664,-1045 52,-148 112,-399 131,-555 19,-150 17,-533 -4,-684 -102,-730 -489,-1382 -1092,-1836.001 -332,-250 -716,-425 -1135,-519 -348,-77 -784,-87 -1150,-25 -1214,205 -2177.003,1157.001 -2350.003,2324.001 -56,377 -30,801 70,1148 151,520 427,950 850.003,1326 566,502 1368,768 2145,711 z"
inkscape:connector-curvature="0"
style="fill:#000000" />
<path
id="shape1"
transform="translate(2694.744,4329.1572)"
d="m 92.256,339.843 c -124,-65 -123,-255.0002 3,-319.0002 86,-44 196,-15.99996 247,62 58,87.0002 26,211.0002 -67,258.0002 -51,26 -132,26 -183,-1 z"
inkscape:connector-curvature="0"
style="fill:#000000" />
<path
id="shape2"
transform="translate(1941.5649,1380)"
d="m 940.435,2728 c -12,-16 -63,-166 -102,-303 -30,-104 -101,-350 -165,-565 -20,-69 -58,-199 -85,-290 -26,-91 -64,-221 -85,-290 -20,-69 -58,-199 -85,-290 -26,-91 -64,-221 -85,-290 -20,-69 -57,-195 -81,-280 -59,-207 -93,-299 -115,-310 -10,-6 -35,-10 -55.9999,-10 C 8.43515,100 -2.56485,92 0.435148,46 L 3.43515,5 231.435,2 l 228,-2 -3,47 -3,48 -73,3 c -66,3 -74,5 -84,27 -13,28 0,104 37,225 13,41 47,156 75,255 28,99 66,230 85,290 18,61 56,191 85,290 28,99 66,230 85,290 18,61 56,191 85,290 85,297 123,419 131,429 5,5 17,-11 28,-35 10,-24 192.005,-393 403.005,-819 211,-426 447,-902 523,-1058 l 139,-282 h 168 c 92,0 168,4 168,8 0,4 -75,158 -166,342 -588,1183 -969,1958 -1033,2100 -29,63 -69,151 -89,195 -44.005,95 -58.005,110 -80.005,83 z"
inkscape:connector-curvature="0"
style="fill:#000000" />
</g>
</svg>
var isEnabled = true;
const blockedHostnames = [
'www.youtube.com',
'youtube.com',
'www.youtube-nocookie.com',
'youtube-nocookie.com'
];
const invidition = async (r) => {
// If extension is disabled, do not redirect
if (!isEnabled) {
return {};
}
let url = new URL(r.url);
const options = await browser.storage.sync.get();
......@@ -6,7 +19,7 @@ const invidition = async (r) => {
if (url.pathname === '/iframe_api') {
url.href = browser.extension.getURL('/iframe_api.js');
} else {
if (url.pathname.indexOf('www-widgetapi.js') >= 0) {
if (url.pathname.indexOf('www-widgetapi.js') != -1) {
url.href = browser.extension.getURL('/www-widgetapi.js');
} else {
// If not using Iframe API, just redirect to invidio.us
......@@ -22,9 +35,57 @@ const invidition = async (r) => {
};
}
const toogleEnabled = async () => {
isEnabled = !isEnabled;
let iconsPaths = {};
if (isEnabled) {
iconsPaths = {
16: 'assets/img/logo-16.png',
32: 'assets/img/logo-32.png',
48: 'assets/img/logo-48.png',
96: 'assets/img/logo-96.png',
125: 'assets/img/logo-128.png'
};
reloadTab();
} else {
iconsPaths = {
16: 'assets/img/logo-16-disabled.png',
32: 'assets/img/logo-32-disabled.png',
48: 'assets/img/logo-48-disabled.png',
96: 'assets/img/logo-96-disabled.png',
125: 'assets/img/logo-128-disabled.png'
}
}
chrome.browserAction.setIcon({
path: iconsPaths
});
}
const reloadTab = async () => {
let activeTab = (await browser.tabs.query({currentWindow: true, active: true}))[0];
console.log(activeTab);
let activeTabHostname = new URL(activeTab.url).hostname;
if (blockedHostnames.indexOf(activeTabHostname) != -1) {
browser.tabs.reload();
}
};
const handleTabActivation = async (tab) => {
if(isEnabled) {
reloadTab();
}
}
browser.webRequest.onBeforeRequest.addListener(
invidition,
{ urls: ['*://*.youtube.com/*', '*://*.youtube-nocookie.com/*', '*://*.s.ytimg.com/*'] },
['blocking']
);
browser.browserAction.onClicked.addListener(toogleEnabled);
browser.tabs.onActivated.addListener(handleTabActivation);
......@@ -6,6 +6,7 @@
"homepage_url": "https://gitlab.com/Booteille/Invidition",
"permissions": [
"activeTab",
"tabs",
"<all_urls>",
"webRequest",
"webRequestBlocking",
......@@ -25,5 +26,14 @@
"gecko": {
"id": "{e824f0e4-72f7-4295-8879-d8ff4bf348d2}"
}
},
"browser_action": {
"default_icon": {
"16": "assets/img/logo-16.png",
"32": "assets/img/logo-32.png",
"48": "assets/img/logo-48.png",
"96": "assets/img/logo-96.png",
"128": "assets/img/logo-128.png"
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment