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/peertube-icon.svg51
-rw-r--r--src/assets/javascripts/helpers/general.js1
-rw-r--r--src/assets/javascripts/helpers/peertube.js207
-rw-r--r--src/assets/javascripts/helpers/sendTargets.js4
4 files changed, 260 insertions, 3 deletions
diff --git a/src/assets/images/peertube-icon.svg b/src/assets/images/peertube-icon.svg
new file mode 100644
index 00000000..a92d909e
--- /dev/null
+++ b/src/assets/images/peertube-icon.svg
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<svg
+   height="128"
+   viewBox="2799 -911 128 128"
+   width="128"
+   version="1.1"
+   id="svg10"
+   sodipodi:docname="peertube-icon.svg"
+   inkscape:version="1.1.1 (3bf5ae0d25, 2021-09-20)"
+   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="defs14" />
+  <sodipodi:namedview
+     id="namedview12"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageshadow="2"
+     inkscape:pageopacity="0.0"
+     inkscape:pagecheckerboard="0"
+     showgrid="false"
+     inkscape:zoom="2.6681399"
+     inkscape:cx="10.868995"
+     inkscape:cy="59.779474"
+     inkscape:window-width="1888"
+     inkscape:window-height="1060"
+     inkscape:window-x="32"
+     inkscape:window-y="0"
+     inkscape:window-maximized="1"
+     inkscape:current-layer="svg10" />
+  <g
+     stroke-width="32"
+     id="g8"
+     transform="matrix(0.15060053,0,0,0.15060053,2402.9154,-761.2095)">
+    <path
+       d="m 2799,-911 v 341.344 l 256,-170.656"
+       fill="#211f20"
+       id="path2" />
+    <path
+       d="m 2799,-569.656 v 341.344 l 256,-170.656"
+       fill="#737373"
+       id="path4" />
+    <path
+       d="M 3055,-740.344 V -399 l 256,-170.656"
+       fill="#f1680d"
+       id="path6" />
+  </g>
+</svg>
diff --git a/src/assets/javascripts/helpers/general.js b/src/assets/javascripts/helpers/general.js
index cc094bd7..c542d88b 100644
--- a/src/assets/javascripts/helpers/general.js
+++ b/src/assets/javascripts/helpers/general.js
@@ -117,6 +117,7 @@ let allPopupFrontends = [
     "maps",
     "wikipedia",
     "medium",
+    "peertube",
     "sendTargets"
 ];
 
diff --git a/src/assets/javascripts/helpers/peertube.js b/src/assets/javascripts/helpers/peertube.js
new file mode 100644
index 00000000..8254a382
--- /dev/null
+++ b/src/assets/javascripts/helpers/peertube.js
@@ -0,0 +1,207 @@
+window.browser = window.browser || window.chrome;
+
+import commonHelper from './common.js'
+
+let targets = [];
+
+let redirects = {
+    "simpleertube": {
+        "normal": [
+            "https://tube.simple-web.org",
+            "https://tube.fr.tild3.org",
+            "https://stube.alefvanoon.xyz",
+            "https://st.phreedom.club",
+        ],
+        "tor": []
+    }
+}
+
+const getRedirects = () => redirects;
+const getCustomRedirects = function () {
+    return {
+        "simpleertube": {
+            "normal": [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects]
+        },
+    };
+};
+
+function setRedirects(val) {
+    redirects.simpleertube = val;
+    browser.storage.local.set({ peertubeTargetsRedirects: redirects })
+    console.log("peertubeTargetsRedirects: ", val)
+    for (const item of simpleertubeNormalRedirectsChecks)
+        if (!redirects.simpleertube.normal.includes(item)) {
+            var index = simpleertubeNormalRedirectsChecks.indexOf(item);
+            if (index !== -1) simpleertubeNormalRedirectsChecks.splice(index, 1);
+        }
+    setSimpleertubeNormalRedirectsChecks(simpleertubeNormalRedirectsChecks);
+
+    for (const item of simpleertubeTorRedirectsChecks)
+        if (!redirects.simpleertube.normal.includes(item)) {
+            var index = simpleertubeTorRedirectsChecks.indexOf(item);
+            if (index !== -1) simpleertubeTorRedirectsChecks.splice(index, 1);
+        }
+    setSimpleertubeTorRedirectsChecks(simpleertubeTorRedirectsChecks);
+}
+
+let simpleertubeNormalRedirectsChecks;
+const getSimpleertubeNormalRedirectsChecks = () => simpleertubeNormalRedirectsChecks;
+function setSimpleertubeNormalRedirectsChecks(val) {
+    simpleertubeNormalRedirectsChecks = val;
+    browser.storage.local.set({ simpleertubeNormalRedirectsChecks })
+    console.log("simpleertubeNormalRedirectsChecks: ", val)
+}
+
+let simpleertubeTorRedirectsChecks;
+const getSimpleertubeTorRedirectsChecks = () => simpleertubeTorRedirectsChecks;
+function setSimpleertubeTorRedirectsChecks(val) {
+    simpleertubeTorRedirectsChecks = val;
+    browser.storage.local.set({ simpleertubeTorRedirectsChecks })
+    console.log("simpleertubeTorRedirectsChecks: ", val)
+}
+
+let simpleertubeNormalCustomRedirects = [];
+const getSimpleertubeNormalCustomRedirects = () => simpleertubeNormalCustomRedirects;
+function setSimpleertubeNormalCustomRedirects(val) {
+    simpleertubeNormalCustomRedirects = val;
+    browser.storage.local.set({ simpleertubeNormalCustomRedirects })
+    console.log("simpleertubeNormalCustomRedirects: ", val)
+}
+
+let simpleertubeTorCustomRedirects = [];
+const getSimpleertubeTorCustomRedirects = () => simpleertubeTorCustomRedirects;
+function setSimpleertubeTorCustomRedirects(val) {
+    simpleertubeTorCustomRedirects = val;
+    browser.storage.local.set({ simpleertubeTorCustomRedirects })
+    console.log("simpleertubeTorCustomRedirects: ", val)
+}
+
+let disable;
+const getDisable = () => disable;
+function setDisable(val) {
+    disable = val;
+    browser.storage.local.set({ disablePeertubeTargets: disable })
+}
+
+let protocol;
+const getProtocol = () => protocol;
+function setProtocol(val) {
+    protocol = val;
+    browser.storage.local.set({ peertubeTargetsProtocol: val })
+    console.log("peertubeTargetsProtocol: ", val)
+}
+
+function changeInstance(url) {
+    let protocolHost = `${url.protocol}//${url.host}`;
+
+    let simpleertubeList = [
+        ...redirects.simpleertube.normal,
+        ...redirects.simpleertube.tor,
+        ...simpleertubeNormalCustomRedirects,
+        ...simpleertubeTorCustomRedirects,
+    ];
+
+    if (!simpleertubeList.includes(protocolHost)) return;
+
+    let instancesList;
+    if (protocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects];
+    else if (protocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects];
+
+    console.log("instancesList", instancesList);
+    let index = instancesList.indexOf(protocolHost);
+    if (index > -1) instancesList.splice(index, 1);
+
+    if (instancesList.length === 0) return null;
+
+    let randomInstance = commonHelper.getRandomInstance(instancesList);
+    return `${randomInstance}${url.pathname}${url.search}`;
+}
+
+function redirect(url, type, initiator) {
+
+    let protocolHost = `${url.protocol}//${url.host}`;
+
+    if (disable) return null;
+    if (initiator && ([...redirects.simpleertube.normal, ...simpleertubeNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return null;
+    if (!targets.includes(protocolHost)) return null;
+
+    if (type != "main_frame") return null;
+
+    let instancesList;
+    if (protocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects];
+    if (protocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects];
+    if (instancesList.length === 0) return null;
+    let randomInstance = commonHelper.getRandomInstance(instancesList);
+
+    if (url.host == 'search.joinpeertube.org') return randomInstance;
+
+    return `${randomInstance}/${url.host}${url.pathname}${url.search}`;
+}
+
+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(
+                [
+                    "disablePeertubeTargets",
+                    "peertubeTargetsRedirects",
+
+                    "simpleertubeNormalRedirectsChecks",
+                    "simpleertubeNormalCustomRedirects",
+
+                    "simpleertubeTorRedirectsChecks",
+                    "simpleertubeTorCustomRedirects",
+
+                    "peertubeTargetsProtocol"
+                ],
+                r => {
+
+                    targets = ['https://search.joinpeertube.org', ...dataJson.peertube];
+
+                    disable = r.disablePeertubeTargets ?? true;
+
+                    protocol = r.peertubeTargetsProtocol ?? "normal";
+
+                    if (r.peertubeTargetsRedirects) redirects = r.peertubeTargetsRedirects;
+
+                    simpleertubeNormalRedirectsChecks = r.simpleertubeNormalRedirectsChecks ?? [...redirects.simpleertube.normal];
+                    simpleertubeNormalCustomRedirects = r.simpleertubeNormalCustomRedirects ?? [];
+
+                    simpleertubeTorRedirectsChecks = r.simpleertubeTorRedirectsChecks ?? [...redirects.simpleertube.tor];
+                    simpleertubeTorCustomRedirects = r.simpleertubeTorCustomRedirects ?? [];
+
+                    resolve();
+                }
+            )
+        });
+    });
+}
+
+export default {
+
+    getRedirects,
+    getCustomRedirects,
+    setRedirects,
+
+    getDisable,
+    setDisable,
+
+    getProtocol,
+    setProtocol,
+
+    getSimpleertubeNormalRedirectsChecks,
+    setSimpleertubeNormalRedirectsChecks,
+    getSimpleertubeTorRedirectsChecks,
+    setSimpleertubeTorRedirectsChecks,
+
+    getSimpleertubeTorCustomRedirects,
+    setSimpleertubeTorCustomRedirects,
+    getSimpleertubeNormalCustomRedirects,
+    setSimpleertubeNormalCustomRedirects,
+
+    changeInstance,
+
+    redirect,
+    init,
+};
diff --git a/src/assets/javascripts/helpers/sendTargets.js b/src/assets/javascripts/helpers/sendTargets.js
index 86e579be..4987b851 100644
--- a/src/assets/javascripts/helpers/sendTargets.js
+++ b/src/assets/javascripts/helpers/sendTargets.js
@@ -148,9 +148,7 @@ function redirect(url, type, initiator) {
     if (instancesList.length === 0) return null;
     let randomInstance = commonHelper.getRandomInstance(instancesList);
 
-    let pathName = url.pathname.replace(new RegExp(/@.*\/(?=video)/), "");
-
-    return `${randomInstance}${pathName}`;
+    return randomInstance;
 }
 
 async function init() {