about summary refs log tree commit diff stats
path: root/src/assets
diff options
context:
space:
mode:
Diffstat (limited to 'src/assets')
-rw-r--r--src/assets/images/librespeed-icon.svg497
-rw-r--r--src/assets/javascripts/helpers/speedtest.js173
-rw-r--r--src/assets/javascripts/helpers/twitter.js2
3 files changed, 670 insertions, 2 deletions
diff --git a/src/assets/images/librespeed-icon.svg b/src/assets/images/librespeed-icon.svg
new file mode 100644
index 00000000..8691d7a3
--- /dev/null
+++ b/src/assets/images/librespeed-icon.svg
@@ -0,0 +1,497 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Generator: Adobe Illustrator 23.0.6, SVG Export Plug-In . SVG Version: 6.00 Build 0)  -->
+
+<svg
+   version="1.1"
+   id="Layer_1"
+   x="0px"
+   y="0px"
+   viewBox="0 0 192.28403 192.28403"
+   xml:space="preserve"
+   sodipodi:docname="librespeed-icon.svg"
+   width="192.28403"
+   height="192.28403"
+   inkscape:version="1.1.2 (0a00cf5339, 2022-02-04)"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:svg="http://www.w3.org/2000/svg"><defs
+   id="defs3049" /><sodipodi:namedview
+   id="namedview3047"
+   pagecolor="#ffffff"
+   bordercolor="#666666"
+   borderopacity="1.0"
+   inkscape:pageshadow="2"
+   inkscape:pageopacity="0.0"
+   inkscape:pagecheckerboard="0"
+   showgrid="false"
+   inkscape:zoom="4.5997653"
+   inkscape:cx="151.96428"
+   inkscape:cy="68.590456"
+   inkscape:window-width="1888"
+   inkscape:window-height="1060"
+   inkscape:window-x="32"
+   inkscape:window-y="0"
+   inkscape:window-maximized="1"
+   inkscape:current-layer="g1581" />
+<style
+   type="text/css"
+   id="style2">
+	.st0{fill:none;stroke:#000000;stroke-miterlimit:10;}
+	.st1{fill:#E6E7E8;}
+	.st2{fill:#EF3828;}
+	.st3{fill:#F7941D;}
+	.st4{fill:#939598;}
+	.st5{fill:#BCBEC0;}
+	.st6{fill:#D1D3D4;}
+	.st7{fill:#ED1C24;}
+	.st8{fill:#BE1E2D;}
+	.st9{fill:#F15A29;}
+	.st10{fill:#2E3192;}
+	.st11{fill:url(#SVGID_1_);}
+	.st12{fill:url(#SVGID_2_);}
+	.st13{fill:#DBF1F9;}
+	.st14{fill:#EF4136;}
+	.st15{fill:url(#SVGID_3_);}
+	.st16{fill:url(#SVGID_4_);}
+	.st17{fill:url(#SVGID_5_);}
+	.st18{fill:url(#SVGID_6_);}
+	.st19{fill:url(#SVGID_7_);}
+	.st20{fill:url(#SVGID_8_);}
+	.st21{fill:#FFFFFF;}
+	.st22{fill:url(#SVGID_9_);}
+	.st23{fill:url(#SVGID_10_);}
+	.st24{fill:url(#SVGID_11_);}
+	.st25{fill:url(#SVGID_12_);}
+	.st26{fill:url(#SVGID_13_);}
+	.st27{fill:url(#SVGID_14_);}
+	.st28{fill:#00AEEF;}
+	.st29{fill:url(#SVGID_15_);}
+	.st30{fill:url(#SVGID_16_);}
+	.st31{fill:url(#SVGID_17_);}
+	.st32{fill:#00A79D;}
+	.st33{fill:url(#SVGID_18_);}
+	.st34{fill:url(#SVGID_19_);}
+	.st35{fill:url(#SVGID_20_);}
+	.st36{fill:url(#SVGID_21_);}
+	.st37{fill:#A97C50;}
+	.st38{fill:url(#SVGID_22_);}
+	.st39{fill:url(#SVGID_23_);}
+	.st40{fill:url(#SVGID_24_);}
+	.st41{fill:url(#SVGID_25_);}
+	.st42{fill:url(#SVGID_26_);}
+	.st43{fill:url(#SVGID_27_);}
+	.st44{fill:url(#SVGID_28_);}
+	.st45{fill:url(#SVGID_29_);}
+	.st46{fill:url(#SVGID_30_);}
+	.st47{fill:url(#SVGID_31_);}
+	.st48{fill:url(#SVGID_32_);}
+	.st49{font-family:'Roboto-Regular';}
+	.st50{font-size:45px;}
+</style>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<g
+   id="XMLID_24_"
+   transform="translate(3006.892,-1312.308)">
+	<g
+   id="g1581">
+		
+		<path
+   d="m -2814.7,1404.3 c 2.3,53 -38.8,97.9 -91.9,100.2 -53,2.3 -97.9,-38.8 -100.2,-91.9 -2.3,-53 38.8,-97.9 91.9,-100.2 53,-2.3 97.9,38.8 100.2,91.9 z m -92.5,83.8 c 44,-1.9 78.1,-39.1 76.2,-83.1 -1.9,-44 -39.1,-78.1 -83.1,-76.2 -44,1.9 -78.1,39.1 -76.2,83.1 1.8,44 39.1,78.1 83.1,76.2 z"
+   id="path1543" />
+		<path
+   d="m -2841.9,1398.6 c 0.8,6 0.8,12.1 0,18.1 l -10.7,-1.4 c 0.7,-5.1 0.7,-10.2 0,-15.3 z"
+   id="path1545" />
+		<path
+   d="m -2853.5,1420.3 10.5,2.3 c -1.3,5.9 -3.4,11.6 -6.2,17 l -9.6,-5 c 2.4,-4.5 4.2,-9.3 5.3,-14.3 z"
+   id="path1547" />
+		<path
+   d="m -2843,1392.6 -10.5,2.3 c -1.1,-5 -2.8,-9.8 -5.2,-14.4 l 9.6,-5 c 2.8,5.5 4.8,11.3 6.1,17.1 z"
+   id="path1549" />
+		<path
+   d="m -2852.2,1370.4 -9.1,5.8 c -2.7,-4.2 -6,-8.2 -9.8,-11.7 l 7.3,-8 c 4.5,4.2 8.4,8.9 11.6,13.9 z"
+   id="path1551" />
+		<path
+   d="m -2868.5,1352.6 -6.6,8.6 c -4.1,-3.2 -8.6,-5.7 -13.2,-7.7 l 4.1,-10 c 5.5,2.3 10.8,5.3 15.7,9.1 z"
+   id="path1553" />
+		<rect
+   x="-2890.3999"
+   y="1449.9"
+   width="8.1000004"
+   height="8.1000004"
+   id="rect1555" />
+		<path
+   d="m -2889.9,1341.5 -3.2,10.3 c -4.6,-1.4 -9.4,-2.3 -14.1,-2.6 l -0.7,-4.9 0.3,-5.9 c 5.9,0.2 11.9,1.2 17.7,3.1 z"
+   id="path1557" />
+		<rect
+   x="-2906.7"
+   y="1449.9"
+   width="8.1000004"
+   height="8.1000004"
+   id="rect1559" />
+		<path
+   d="m -2901.4,1401.6 0.9,6 c 0,8.1 -4.6,14.7 -10.2,14.7 -5.6,0 -10.2,-6.6 -10.2,-14.7 l 0.9,-5.9 9.3,-63.3 z"
+   id="path1561" />
+		
+		<path
+   d="m -2913.8,1338.3 0.3,6.2 -0.7,4.7 c -4.8,0.3 -9.6,1.2 -14.2,2.6 l -3.2,-10.3 c 5.8,-1.9 11.8,-2.9 17.8,-3.2 z"
+   id="path1565" />
+		<rect
+   x="-2922.8999"
+   y="1449.9"
+   width="8.1000004"
+   height="8.1000004"
+   id="rect1567" />
+		<rect
+   x="-2939.2"
+   y="1449.9"
+   width="8.1000004"
+   height="8.1000004"
+   id="rect1569" />
+		<path
+   d="m -2937.3,1343.5 4.1,10 c -4.7,1.9 -9.1,4.5 -13.2,7.7 l -6.6,-8.6 c 4.9,-3.8 10.2,-6.8 15.7,-9.1 z"
+   id="path1571" />
+		<path
+   d="m -2957.6,1356.5 7.3,8 c -1.3,1.1 -2.5,2.3 -3.6,3.6 -2.3,2.6 -4.4,5.3 -6.2,8.1 l -9.1,-5.8 c 2.1,-3.3 4.6,-6.6 7.4,-9.6 1.2,-1.5 2.7,-3 4.2,-4.3 z"
+   id="path1573" />
+		<path
+   d="m -2972.3,1375.6 9.6,5 c -2.4,4.6 -4.1,9.4 -5.2,14.4 l -10.5,-2.3 c 1.2,-5.9 3.2,-11.7 6.1,-17.1 z"
+   id="path1575" />
+		<path
+   d="m -2962.8,1434.7 -9.6,5 c -2.8,-5.4 -4.9,-11.2 -6.2,-17 l 10.5,-2.3 c 1.2,4.9 2.9,9.7 5.3,14.3 z"
+   id="path1577" />
+		<path
+   d="m -2979.6,1398.6 10.7,1.4 c -0.7,5.1 -0.7,10.2 0,15.3 l -10.7,1.4 c -0.8,-6 -0.8,-12.1 0,-18.1 z"
+   id="path1579" />
+	</g>
+	<g
+   id="g1583">
+	</g>
+</g>
+<path
+   class="st21"
+   d="m 100.69201,96.09201 c 0,2.5 -2,4.5 -4.5,4.5 -2.5,0 -4.5,-2 -4.5,-4.5 0,-2.5 2,-4.5 4.5,-4.5 2.5,0 4.5,2 4.5,4.5 z"
+   id="path1586" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+</svg>
diff --git a/src/assets/javascripts/helpers/speedtest.js b/src/assets/javascripts/helpers/speedtest.js
new file mode 100644
index 00000000..1e2fddeb
--- /dev/null
+++ b/src/assets/javascripts/helpers/speedtest.js
@@ -0,0 +1,173 @@
+window.browser = window.browser || window.chrome;
+
+import commonHelper from './common.js'
+
+const targets = [
+    /^https?:\/{2}(www\.|)speedtest\.net\/$/
+];
+
+let redirects = {
+    "librespeed": {
+        "normal": [
+            "https://librespeed.org"
+        ],
+        "tor": []
+    }
+}
+
+const getRedirects = () => redirects;
+const getCustomRedirects = function () {
+    return {
+        "librespeed": {
+            "normal": [...librespeedNormalRedirectsChecks, ...librespeedNormalCustomRedirects],
+            "tor": []
+        },
+    };
+};
+
+function setRedirects(val) {
+    redirects.librespeed = val;
+    browser.storage.local.set({ speedtestRedirects: redirects })
+    console.log("speedtestRedirects: ", val)
+    for (const item of librespeedNormalRedirectsChecks)
+        if (!redirects.librespeed.normal.includes(item)) {
+            var index = librespeedNormalRedirectsChecks.indexOf(item);
+            if (index !== -1) librespeedNormalRedirectsChecks.splice(index, 1);
+        }
+    setLibrespeedNormalRedirectsChecks(librespeedNormalRedirectsChecks);
+
+    for (const item of librespeedTorRedirectsChecks)
+        if (!redirects.librespeed.normal.includes(item)) {
+            var index = librespeedTorRedirectsChecks.indexOf(item);
+            if (index !== -1) librespeedTorRedirectsChecks.splice(index, 1);
+        }
+    setLibrespeedTorRedirectsChecks(librespeedTorRedirectsChecks);
+}
+
+let librespeedNormalRedirectsChecks;
+const getLibrespeedNormalRedirectsChecks = () => librespeedNormalRedirectsChecks;
+function setLibrespeedNormalRedirectsChecks(val) {
+    librespeedNormalRedirectsChecks = val;
+    browser.storage.local.set({ librespeedNormalRedirectsChecks })
+    console.log("librespeedNormalRedirectsChecks: ", val)
+}
+
+let librespeedTorRedirectsChecks;
+const getLibrespeedTorRedirectsChecks = () => librespeedTorRedirectsChecks;
+function setLibrespeedTorRedirectsChecks(val) {
+    librespeedTorRedirectsChecks = val;
+    browser.storage.local.set({ librespeedTorRedirectsChecks })
+    console.log("librespeedTorRedirectsChecks: ", val)
+}
+
+let librespeedNormalCustomRedirects = [];
+const getLibrespeedNormalCustomRedirects = () => librespeedNormalCustomRedirects;
+function setLibrespeedNormalCustomRedirects(val) {
+    librespeedNormalCustomRedirects = val;
+    browser.storage.local.set({ librespeedNormalCustomRedirects })
+    console.log("librespeedNormalCustomRedirects: ", val)
+}
+
+let librespeedTorCustomRedirects = [];
+const getLibrespeedTorCustomRedirects = () => librespeedTorCustomRedirects;
+function setLibrespeedTorCustomRedirects(val) {
+    librespeedTorCustomRedirects = val;
+    browser.storage.local.set({ librespeedTorCustomRedirects })
+    console.log("librespeedTorCustomRedirects: ", val)
+}
+
+let disable;
+const getDisable = () => disable;
+function setDisable(val) {
+    disable = val;
+    browser.storage.local.set({ disableSpeedtest: disable })
+    console.log("disableSpeedtest", val);
+}
+
+let protocol;
+const getProtocol = () => protocol;
+function setProtocol(val) {
+    protocol = val;
+    browser.storage.local.set({ speedtestProtocol: val })
+    console.log("speedtestProtocol: ", val)
+}
+
+function redirect(url, type, initiator) {
+    if (disable) return null;
+    if (initiator && ([...redirects.librespeed.normal, ...librespeedNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
+    if (!targets.some(rx => rx.test(url.href))) return null;
+    console.log("Librespeed!!");
+
+    if (type != "main_frame" && type != "sub_frame") return null;
+
+    let instancesList;
+    if (protocol == 'normal') instancesList = [...librespeedNormalRedirectsChecks, ...librespeedNormalCustomRedirects];
+    if (protocol == 'tor') instancesList = [...librespeedTorRedirectsChecks, ...librespeedTorCustomRedirects];
+    if (instancesList.length === 0) return null;
+    let randomInstance = commonHelper.getRandomInstance(instancesList);
+
+    return `${randomInstance}`;
+}
+
+async function init() {
+    return new Promise(resolve => {
+        fetch('/instances/data.json').then(response => response.text()).then(data => {
+            let dataJson = JSON.parse(data);
+            browser.storage.local.get(
+                [
+                    "disableSpeedtest",
+                    "speedtestRedirects",
+
+                    "librespeedNormalRedirectsChecks",
+                    "librespeedNormalCustomRedirects",
+
+                    "librespeedTorRedirectsChecks",
+                    "librespeedTorCustomRedirects",
+
+                    "speedtestProtocol"
+                ],
+                r => {
+                    disable = r.disableSpeedtest ?? true;
+
+                    protocol = r.speedtestProtocol ?? "normal";
+
+                    if (r.speedtestRedirects) redirects = r.speedtestRedirects;
+
+                    librespeedNormalRedirectsChecks = r.librespeedNormalRedirectsChecks ?? [...redirects.librespeed.normal];
+                    librespeedNormalCustomRedirects = r.librespeedNormalCustomRedirects ?? [];
+
+                    librespeedTorRedirectsChecks = r.librespeedTorRedirectsChecks ?? [...redirects.librespeed.tor];
+                    librespeedTorCustomRedirects = r.librespeedTorCustomRedirects ?? [];
+
+                    resolve();
+                }
+            )
+        });
+    });
+}
+
+export default {
+
+    getRedirects,
+    getCustomRedirects,
+    setRedirects,
+
+    getDisable,
+    setDisable,
+
+    getProtocol,
+    setProtocol,
+
+    getLibrespeedNormalRedirectsChecks,
+    setLibrespeedNormalRedirectsChecks,
+    getLibrespeedTorRedirectsChecks,
+    setLibrespeedTorRedirectsChecks,
+
+    getLibrespeedTorCustomRedirects,
+    setLibrespeedTorCustomRedirects,
+    getLibrespeedNormalCustomRedirects,
+    setLibrespeedNormalCustomRedirects,
+
+    redirect,
+    init,
+};
diff --git a/src/assets/javascripts/helpers/twitter.js b/src/assets/javascripts/helpers/twitter.js
index a333777d..e58af78b 100644
--- a/src/assets/javascripts/helpers/twitter.js
+++ b/src/assets/javascripts/helpers/twitter.js
@@ -277,7 +277,6 @@ function isNitter(url, type) {
   ].includes(protocolHost);
 }
 
-let applyThemeToSites;
 function initNitterCookies() {
   if (enableCustomSettings) {
     let allInstances = [...redirects.nitter.normal, ...redirects.nitter.tor, ...nitterNormalCustomRedirects, ...nitterTorCustomRedirects]
@@ -410,7 +409,6 @@ async function init() {
           alwaysUsePreferred = r.alwaysUsePreferred ?? false;
 
           theme = r.theme ?? 'DEFAULT';
-          applyThemeToSites = r.applyThemeToSites ?? false;
 
           redirects.nitter = dataJson.nitter;
           if (r.twitterRedirects) redirects = r.twitterRedirects;