From c5a6623e0f320b2a789e0d2667ccfe2e1bd4335f Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Mon, 30 May 2022 01:02:59 +0300 Subject: Fixed settings theme and translation flashing #286 --- src/_locales/ar/messages.json | 774 +++------ src/_locales/de/messages.json | 400 +---- src/_locales/en/messages.json | 392 +---- src/_locales/filter.py | 43 + src/assets/javascripts/general.js | 71 + src/assets/javascripts/helpers/general.js | 71 - src/assets/javascripts/helpers/imgur.js | 191 --- src/assets/javascripts/helpers/instagram.js | 166 -- src/assets/javascripts/helpers/lbry.js | 156 -- src/assets/javascripts/helpers/maps.js | 212 --- src/assets/javascripts/helpers/medium.js | 174 -- src/assets/javascripts/helpers/peertube.js | 155 -- src/assets/javascripts/helpers/reddit.js | 378 ----- src/assets/javascripts/helpers/search.js | 470 ------ src/assets/javascripts/helpers/sendTargets.js | 149 -- src/assets/javascripts/helpers/tiktok.js | 175 -- .../helpers/translate/get_lingva_preferences.js | 10 - .../helpers/translate/set_lingva_preferences.js | 19 - .../javascripts/helpers/translate/translate.js | 295 ---- src/assets/javascripts/helpers/twitter.js | 241 --- src/assets/javascripts/helpers/utils.js | 456 ------ src/assets/javascripts/helpers/wikipedia.js | 220 --- .../youtube/get_pipedMaterial_preferences.js | 7 - .../helpers/youtube/get_piped_preferences.js | 24 - .../youtube/set_pipedMaterial_preferences.js | 10 - .../helpers/youtube/set_piped_preferences.js | 44 - src/assets/javascripts/helpers/youtube/youtube.js | 453 ------ src/assets/javascripts/helpers/youtubeMusic.js | 97 -- src/assets/javascripts/imgur.js | 191 +++ src/assets/javascripts/instagram.js | 166 ++ src/assets/javascripts/lbry.js | 156 ++ src/assets/javascripts/localise.js | 34 +- src/assets/javascripts/maps.js | 212 +++ src/assets/javascripts/medium.js | 174 ++ src/assets/javascripts/peertube.js | 155 ++ src/assets/javascripts/reddit.js | 378 +++++ src/assets/javascripts/search.js | 470 ++++++ src/assets/javascripts/sendTargets.js | 149 ++ src/assets/javascripts/tiktok.js | 175 ++ .../translate/get_lingva_preferences.js | 10 + .../translate/set_lingva_preferences.js | 19 + src/assets/javascripts/translate/translate.js | 295 ++++ src/assets/javascripts/twitter.js | 241 +++ src/assets/javascripts/utils.js | 452 ++++++ src/assets/javascripts/wikipedia.js | 220 +++ .../youtube/get_pipedMaterial_preferences.js | 7 + .../javascripts/youtube/get_piped_preferences.js | 24 + .../youtube/set_pipedMaterial_preferences.js | 10 + .../javascripts/youtube/set_piped_preferences.js | 44 + src/assets/javascripts/youtube/youtube.js | 451 ++++++ src/assets/javascripts/youtubeMusic.js | 97 ++ src/manifest.json | 2 +- src/pages/background/background.js | 36 +- src/pages/background/incognito.js | 14 +- src/pages/options/general/general.html | 207 --- src/pages/options/general/general.js | 224 --- src/pages/options/general/general.pug | 176 -- src/pages/options/imgur/imgur.html | 150 -- src/pages/options/imgur/imgur.js | 52 - src/pages/options/imgur/imgur.pug | 44 - src/pages/options/index.html | 1712 ++++++++++++++++++++ src/pages/options/index.js | 24 + src/pages/options/index.pug | 32 + src/pages/options/init.js | 56 +- src/pages/options/instagram/instagram.html | 128 -- src/pages/options/instagram/instagram.js | 42 - src/pages/options/instagram/instagram.pug | 37 - src/pages/options/lbry/lbry.html | 128 -- src/pages/options/lbry/lbry.js | 43 - src/pages/options/lbry/lbry.pug | 36 - src/pages/options/maps/maps.html | 107 -- src/pages/options/maps/maps.js | 32 - src/pages/options/maps/maps.pug | 33 - src/pages/options/medium/medium.html | 128 -- src/pages/options/medium/medium.js | 42 - src/pages/options/medium/medium.pug | 36 - src/pages/options/peertube/peertube.html | 128 -- src/pages/options/peertube/peertube.js | 40 - src/pages/options/peertube/peertube.pug | 36 - src/pages/options/reddit/reddit.html | 187 --- src/pages/options/reddit/reddit.js | 90 - src/pages/options/reddit/reddit.pug | 52 - src/pages/options/search/search.html | 309 ---- src/pages/options/search/search.js | 142 -- src/pages/options/search/search.pug | 78 - src/pages/options/sendTargets/sendTargets.html | 128 -- src/pages/options/sendTargets/sendTargets.js | 43 - src/pages/options/sendTargets/sendTargets.pug | 36 - src/pages/options/tiktok/tiktok.html | 128 -- src/pages/options/tiktok/tiktok.js | 55 - src/pages/options/tiktok/tiktok.pug | 36 - src/pages/options/translate/translate.html | 186 --- src/pages/options/translate/translate.js | 75 - src/pages/options/translate/translate.pug | 50 - src/pages/options/twitter/twitter.html | 128 -- src/pages/options/twitter/twitter.js | 53 - src/pages/options/twitter/twitter.pug | 37 - src/pages/options/widgets/general.js | 225 +++ src/pages/options/widgets/general.pug | 167 ++ src/pages/options/widgets/imgur.js | 52 + src/pages/options/widgets/imgur.pug | 32 + src/pages/options/widgets/instagram.js | 42 + src/pages/options/widgets/instagram.pug | 27 + src/pages/options/widgets/lbry.js | 43 + src/pages/options/widgets/lbry.pug | 26 + src/pages/options/widgets/maps.js | 32 + src/pages/options/widgets/maps.pug | 23 + src/pages/options/widgets/medium.js | 42 + src/pages/options/widgets/medium.pug | 26 + src/pages/options/widgets/peertube.js | 40 + src/pages/options/widgets/peertube.pug | 26 + src/pages/options/widgets/reddit.js | 90 + src/pages/options/widgets/reddit.pug | 42 + src/pages/options/widgets/search.js | 142 ++ src/pages/options/widgets/search.pug | 69 + src/pages/options/widgets/sendTargets.js | 43 + src/pages/options/widgets/sendTargets.pug | 26 + src/pages/options/widgets/tiktok.js | 53 + src/pages/options/widgets/tiktok.pug | 26 + src/pages/options/widgets/translate.js | 75 + src/pages/options/widgets/translate.pug | 40 + src/pages/options/widgets/twitter.js | 53 + src/pages/options/widgets/twitter.pug | 26 + src/pages/options/widgets/wikipedia.js | 51 + src/pages/options/widgets/wikipedia.pug | 32 + src/pages/options/widgets/youtube.js | 161 ++ src/pages/options/widgets/youtube.pug | 73 + src/pages/options/widgets/youtubeMusic.js | 23 + src/pages/options/widgets/youtubeMusic.pug | 17 + src/pages/options/wikipedia/wikipedia.html | 150 -- src/pages/options/wikipedia/wikipedia.js | 53 - src/pages/options/wikipedia/wikipedia.pug | 41 - src/pages/options/youtube/youtube.html | 263 --- src/pages/options/youtube/youtube.js | 161 -- src/pages/options/youtube/youtube.pug | 83 - src/pages/options/youtubeMusic/youtubeMusic.html | 100 -- src/pages/options/youtubeMusic/youtubeMusic.js | 23 - src/pages/options/youtubeMusic/youtubeMusic.pug | 27 - src/pages/popup/popup.html | 38 +- src/pages/popup/popup.js | 93 +- src/pages/popup/popup.pug | 41 +- src/pages/stylesheets/styles.css | 10 +- src/pages/widgets/icons.pug | 1 - src/pages/widgets/links.pug | 34 +- 144 files changed, 8279 insertions(+), 10205 deletions(-) create mode 100644 src/_locales/filter.py create mode 100644 src/assets/javascripts/general.js delete mode 100644 src/assets/javascripts/helpers/general.js delete mode 100644 src/assets/javascripts/helpers/imgur.js delete mode 100644 src/assets/javascripts/helpers/instagram.js delete mode 100644 src/assets/javascripts/helpers/lbry.js delete mode 100644 src/assets/javascripts/helpers/maps.js delete mode 100644 src/assets/javascripts/helpers/medium.js delete mode 100644 src/assets/javascripts/helpers/peertube.js delete mode 100644 src/assets/javascripts/helpers/reddit.js delete mode 100644 src/assets/javascripts/helpers/search.js delete mode 100644 src/assets/javascripts/helpers/sendTargets.js delete mode 100644 src/assets/javascripts/helpers/tiktok.js delete mode 100644 src/assets/javascripts/helpers/translate/get_lingva_preferences.js delete mode 100644 src/assets/javascripts/helpers/translate/set_lingva_preferences.js delete mode 100644 src/assets/javascripts/helpers/translate/translate.js delete mode 100644 src/assets/javascripts/helpers/twitter.js delete mode 100644 src/assets/javascripts/helpers/utils.js delete mode 100644 src/assets/javascripts/helpers/wikipedia.js delete mode 100644 src/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js delete mode 100644 src/assets/javascripts/helpers/youtube/get_piped_preferences.js delete mode 100644 src/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js delete mode 100644 src/assets/javascripts/helpers/youtube/set_piped_preferences.js delete mode 100644 src/assets/javascripts/helpers/youtube/youtube.js delete mode 100644 src/assets/javascripts/helpers/youtubeMusic.js create mode 100644 src/assets/javascripts/imgur.js create mode 100644 src/assets/javascripts/instagram.js create mode 100644 src/assets/javascripts/lbry.js create mode 100644 src/assets/javascripts/maps.js create mode 100644 src/assets/javascripts/medium.js create mode 100644 src/assets/javascripts/peertube.js create mode 100644 src/assets/javascripts/reddit.js create mode 100644 src/assets/javascripts/search.js create mode 100644 src/assets/javascripts/sendTargets.js create mode 100644 src/assets/javascripts/tiktok.js create mode 100644 src/assets/javascripts/translate/get_lingva_preferences.js create mode 100644 src/assets/javascripts/translate/set_lingva_preferences.js create mode 100644 src/assets/javascripts/translate/translate.js create mode 100644 src/assets/javascripts/twitter.js create mode 100644 src/assets/javascripts/utils.js create mode 100644 src/assets/javascripts/wikipedia.js create mode 100644 src/assets/javascripts/youtube/get_pipedMaterial_preferences.js create mode 100644 src/assets/javascripts/youtube/get_piped_preferences.js create mode 100644 src/assets/javascripts/youtube/set_pipedMaterial_preferences.js create mode 100644 src/assets/javascripts/youtube/set_piped_preferences.js create mode 100644 src/assets/javascripts/youtube/youtube.js create mode 100644 src/assets/javascripts/youtubeMusic.js delete mode 100644 src/pages/options/general/general.html delete mode 100644 src/pages/options/general/general.js delete mode 100644 src/pages/options/general/general.pug delete mode 100644 src/pages/options/imgur/imgur.html delete mode 100644 src/pages/options/imgur/imgur.js delete mode 100644 src/pages/options/imgur/imgur.pug create mode 100644 src/pages/options/index.html create mode 100644 src/pages/options/index.js create mode 100644 src/pages/options/index.pug delete mode 100644 src/pages/options/instagram/instagram.html delete mode 100644 src/pages/options/instagram/instagram.js delete mode 100644 src/pages/options/instagram/instagram.pug delete mode 100644 src/pages/options/lbry/lbry.html delete mode 100644 src/pages/options/lbry/lbry.js delete mode 100644 src/pages/options/lbry/lbry.pug delete mode 100644 src/pages/options/maps/maps.html delete mode 100644 src/pages/options/maps/maps.js delete mode 100644 src/pages/options/maps/maps.pug delete mode 100644 src/pages/options/medium/medium.html delete mode 100644 src/pages/options/medium/medium.js delete mode 100644 src/pages/options/medium/medium.pug delete mode 100644 src/pages/options/peertube/peertube.html delete mode 100644 src/pages/options/peertube/peertube.js delete mode 100644 src/pages/options/peertube/peertube.pug delete mode 100644 src/pages/options/reddit/reddit.html delete mode 100644 src/pages/options/reddit/reddit.js delete mode 100644 src/pages/options/reddit/reddit.pug delete mode 100644 src/pages/options/search/search.html delete mode 100644 src/pages/options/search/search.js delete mode 100644 src/pages/options/search/search.pug delete mode 100644 src/pages/options/sendTargets/sendTargets.html delete mode 100644 src/pages/options/sendTargets/sendTargets.js delete mode 100644 src/pages/options/sendTargets/sendTargets.pug delete mode 100644 src/pages/options/tiktok/tiktok.html delete mode 100644 src/pages/options/tiktok/tiktok.js delete mode 100644 src/pages/options/tiktok/tiktok.pug delete mode 100644 src/pages/options/translate/translate.html delete mode 100644 src/pages/options/translate/translate.js delete mode 100644 src/pages/options/translate/translate.pug delete mode 100644 src/pages/options/twitter/twitter.html delete mode 100644 src/pages/options/twitter/twitter.js delete mode 100644 src/pages/options/twitter/twitter.pug create mode 100644 src/pages/options/widgets/general.js create mode 100644 src/pages/options/widgets/general.pug create mode 100644 src/pages/options/widgets/imgur.js create mode 100644 src/pages/options/widgets/imgur.pug create mode 100644 src/pages/options/widgets/instagram.js create mode 100644 src/pages/options/widgets/instagram.pug create mode 100644 src/pages/options/widgets/lbry.js create mode 100644 src/pages/options/widgets/lbry.pug create mode 100644 src/pages/options/widgets/maps.js create mode 100644 src/pages/options/widgets/maps.pug create mode 100644 src/pages/options/widgets/medium.js create mode 100644 src/pages/options/widgets/medium.pug create mode 100644 src/pages/options/widgets/peertube.js create mode 100644 src/pages/options/widgets/peertube.pug create mode 100644 src/pages/options/widgets/reddit.js create mode 100644 src/pages/options/widgets/reddit.pug create mode 100644 src/pages/options/widgets/search.js create mode 100644 src/pages/options/widgets/search.pug create mode 100644 src/pages/options/widgets/sendTargets.js create mode 100644 src/pages/options/widgets/sendTargets.pug create mode 100644 src/pages/options/widgets/tiktok.js create mode 100644 src/pages/options/widgets/tiktok.pug create mode 100644 src/pages/options/widgets/translate.js create mode 100644 src/pages/options/widgets/translate.pug create mode 100644 src/pages/options/widgets/twitter.js create mode 100644 src/pages/options/widgets/twitter.pug create mode 100644 src/pages/options/widgets/wikipedia.js create mode 100644 src/pages/options/widgets/wikipedia.pug create mode 100644 src/pages/options/widgets/youtube.js create mode 100644 src/pages/options/widgets/youtube.pug create mode 100644 src/pages/options/widgets/youtubeMusic.js create mode 100644 src/pages/options/widgets/youtubeMusic.pug delete mode 100644 src/pages/options/wikipedia/wikipedia.html delete mode 100644 src/pages/options/wikipedia/wikipedia.js delete mode 100644 src/pages/options/wikipedia/wikipedia.pug delete mode 100644 src/pages/options/youtube/youtube.html delete mode 100644 src/pages/options/youtube/youtube.js delete mode 100644 src/pages/options/youtube/youtube.pug delete mode 100644 src/pages/options/youtubeMusic/youtubeMusic.html delete mode 100644 src/pages/options/youtubeMusic/youtubeMusic.js delete mode 100644 src/pages/options/youtubeMusic/youtubeMusic.pug (limited to 'src') diff --git a/src/_locales/ar/messages.json b/src/_locales/ar/messages.json index f407c964..a8bd46e4 100644 --- a/src/_locales/ar/messages.json +++ b/src/_locales/ar/messages.json @@ -1,556 +1,222 @@ { - "extensionName": { - "message": "LibRedirect", - "description": "name of the extension" - }, - - "extensionDescription": { - "message": "إضافة متصفح تعيد توجيه مواقع مشهورة إلى واجهات أمامية ذات تحترم الخصوصية", - "description": "description of the extension" - }, - - "switchInstance": { - "message": "تبديل المَثيل", - "description": "used in manifest.json as shortcut description" - }, - - "instance": { - "message": "المَثيل", - "description": "used in popup.html" - }, - - "settings": { - "message": "الإعدادات", - "description": "used in popup.html" - }, - - "libOptions": { - "message": "LibRedirect إعدادات", - "description": "used in general.html" - }, - - "general": { - "message": "العامة", - "description": "used in general.html" - }, - - "search": { - "message": "البحث", - "description": "used in general.html" - }, - - "translate": { - "message": "الترجمة", - "description": "used in general.html" - }, - - "maps": { - "message": "الخرائط", - "description": "used in general.html" - }, - - "sendFiles": { - "message": "إرسال الملفات", - "description": "used in general.html" - }, - - "youtube": { - "message": "يوتيوب", - "description": "used in general.html" - }, - - "instagram": { - "message": "إنستغرام", - "description": "used in general.html" - }, - - "twitter": { - "message": "تويتر", - "description": "used in general.html" - }, - - "reddit": { - "message": "ريديت", - "description": "used in general.html" - }, - - "tiktok": { - "message": "تيك توك", - "description": "used in general.html" - }, - - "ytmusic": { - "message": "يوتيوب ميوزيك", - "description": "used in general.html" - }, - - "imgur": { - "message": "إمجور", - "description": "used in general.html" - }, - - "wikipedia": { - "message": "ويكيبيديا", - "description": "used in general.html" - }, - - "peertube": { - "message": "PeerTube", - "description": "used in general.html" - }, - - "medium": { - "message": "ميديام", - "description": "used in general.html" - }, - - "tor": { - "message": "تور", - "description": "used in imgur.html" - }, - - "theme": { - "message": "السمة", - "description": "used in general.html" - }, - - "system": { - "message": "النظام", - "description": "used in general.html" - }, - - "light": { - "message": "فاتح", - "description": "used in general.html" - }, - - "dark": { - "message": "داكن", - "description": "used in general.html" - }, - - "applyTheme": { - "message": "تطبيق السمة على الواجهات", - "description": "used in general.html" - }, - - "alwaysPref": { - "message": "استخدم المُثلاء المفضلين دائماً", - "description": "used in general.html" - }, - - "autoRedirect": { - "message": "إعادة التوجيه تلقائياً من المُثلاء الذين لا يعملون", - "description": "used in general.html" - }, - - "exceptions": { - "message": "الاستثناءات", - "description": "used in general.html" - }, - - "updateInstances": { - "message": "تحديث قائمة المُثلاء", - "description": "used in general.html" - }, - - "importSettings": { - "message": "استيراد الإعدادات", - "description": "used in general.html" - }, - - "exportSettings": { - "message": "تصدير الإعدادات", - "description": "used in general.html" - }, - - "resetSettings": { - "message": "إعادة تعيين الإعدادات", - "description": "used in general.html" - }, - - "customPopup": { - "message": "تخصيص النافذة المنبثقة", - "description": "used in general.html" - }, - - "enable": { - "message": "تفعيل", - "description": "used in imgur.html" - }, - - "protocol": { - "message": "البروتوكول", - "description": "used in imgur.html" - }, - - "normal": { - "message": "العادي", - "description": "used in imgur.html" - }, - - "defaultInstances": { - "message": "المُثلاء الافتراضيين", - "description": "used in imgur.html" - }, - - "customInstances": { - "message": "المُثلاء المخصصين", - "description": "used in imgur.html" - }, - - "toggleAll": { - "message": "تبديل الكل", - "description": "used in utils.js" - }, - - "frontend": { - "message": "الواجهة الأمامية", - "description": "used in maps.html" - }, - - "notFullyPrivate": { - "message": "هذه الواجهة لا تحترم الخصوصية تماماً", - "description": "" - }, - - "oldReddit": { - "message": "ريديت القديم", - "description": "used in reddit.html" - }, - - "searchNote": { - "message": "ملاحظة: لاستعمال \"البحث\" بكامل إمكانيته، اجعل LibRedirect محرك البحث الافتراضي", - "description": "used in search.html" - }, - - "libSendFiles": { - "message": "LibRedirect: إرسال الملفات", - "description": "used in sendTargets.html" - }, - - "from": { - "message": "من", - "description": "used in translate.html" - }, - - "to": { - "message": "إلى", - "description": "used in translate.html" - }, - - "default": { - "message": "الافتراضي", - "description": "used in translate.html" - }, - - "auto": { - "message": "تلقائي", - "description": "used in translate.html" - }, - - "engine": { - "message": "محرك البحث", - "description": "used in translate.html" - }, - - "libTranslate": { - "message": "LibRedirect: الترجمة", - "description": "used in translate.html" - }, - - "embeddedVids": { - "message": "واجهة الفيديوهات المضمنة", - "description": "used in youtube.html" - }, - - "redirectType": { - "message": "نوع إعادة التوجيه", - "description": "used in youtube.html" - }, - - "both": { - "message": "الإثنين", - "description": "used in youtube.html" - }, - - "onlyEmbedded": { - "message": "فقط للتضمينات", - "description": "used in youtube.html" - }, - - "onlyNotEmbedded": { - "message": "فقط لغير التضمينات", - "description": "used in youtube.html" - }, - - "enableCustom": { - "message": "تمكين الإعدادات الخاصة (ستُستخدم ملفات تعريف الارتباط والـlocalStorage)", - "description": "used in youtube.html" - }, - - "autoplayVid": { - "message": "تشغيل الفيديوهات التلقائي", - "description": "used in youtube.html" - }, - - "volume": { - "message": "الصوت: ", - "description": "used in youtube.html" - }, - - "playerStyle": { - "message": "شكل مشغل الفيديو", - "description": "used in youtube.html" - }, - - "alwaysLoop": { - "message": "إعادة تشغيل الفيديو تلقائياً", - "description": "used in youtube.html" - }, - - "playNext": { - "message": "تشغيل التالي افتراضياً", - "description": "used in youtube.html" - }, - - "autoplayNext": { - "message": "تشغيل الفيديو التالي تلقائياً", - "description": "used in youtube.html" - }, - - "alwaysProxy": { - "message": "بروكسي المقاطع المرئيّة", - "description": "used in youtube.html" - }, - - "listenByDefault": { - "message": "تشغيل النسخة السمعية تلقائيًا", - "description": "used in youtube.html" - }, - - "defaultSpeed": { - "message": "السرعة الافتراضية", - "description": "used in youtube.html" - }, - - "prefQuality": { - "message": "الجودة المفضلة للمقاطع", - "description": "used in youtube.html" - }, - - "dash": { - "message": "DASH (جودة تكيُّفية)", - "description": "used in youtube.html" - }, - - "prefDashQuality": { - "message": "جودة فيديو DASH المفضلة", - "description": "used in youtube.html" - }, - - "best": { - "message": "الأفضل", - "description": "used in youtube.html" - }, - - "worst": { - "message": "الأسوء", - "description": "used in youtube.html" - }, - - "defaultComments": { - "message": "التعليقات الافتراضية", - "description": "used in youtube.html" - }, - - "none": { - "message": "لا شيء", - "description": "used in youtube.html" - }, - - "defaultCaptions": { - "message": "التسميات التوضيحية الاتفراضية", - "description": "used in youtube.html" - }, - - "showRelated": { - "message": "اعرض الفيديوهات ذات الصلة", - "description": "used in youtube.html" - }, - - "showAnnotations": { - "message": "إظهار الـAnnotation بشكل افتراضي", - "description": "used in youtube.html" - }, - - "autoExtendDesc": { - "message": "توسيع وصف الفيديو تلقائيا", - "description": "used in youtube.html" - }, - - "interactive360": { - "message": "مقاطع فيديو تفاعلية بزاوية 360 درجة (تتطلب WebGL)", - "description": "used in youtube.html" - }, - - "savePlaybackPos": { - "message": "حفظ موضع التشغيل", - "description": "used in youtube.html" - }, - - "enableSponsorBlock": { - "message": "Enable SponsorBlock", - "description": "used in youtube.html" - }, - - "skipSponsors": { - "message": "Skip sponsors", - "description": "used in youtube.html" - }, - - "skipIntermission": { - "message": "Skip Intermission/Intro Animation", - "description": "used in youtube.html" - }, - - "skipEndcards": { - "message": "Skip Endcards/Credits", - "description": "used in youtube.html" - }, - - "skipPreview": { - "message": "Skip Preview/Recap", - "description": "used in youtube.html" - }, - - "skipReminder": { - "message": "Skip interaction reminder (subscribe)", - "description": "used in youtube.html" - }, - - "skipUnpaidPromo": { - "message": "Skip Unpaid/Self Promotion", - "description": "used in youtube.html" - }, - - "skipMusic": { - "message": "Skip Music: Non-Music Section", - "description": "used in youtube.html" - }, - - "skipHighlights": { - "message": "Skip highlights", - "description": "used in youtube.html" - }, - - "skipFiller": { - "message": "Skip Filler Tangent", - "description": "used in youtube.html" - }, - - "audioOnly": { - "message": "Audio only", - "description": "used in youtube.html" - }, - - "defaultQuality": { - "message": "Default quality", - "description": "used in youtube.html" - }, - - "bufferingGoal": { - "message": "Buffering Goal (in seconds)", - "description": "used in youtube.html" - }, - - "countrySelection": { - "message": "Country selection", - "description": "used in youtube.html" - }, - - "defaultHomepage": { - "message": "Default homepage", - "description": "used in youtube.html" - }, - - "trending": { - "message": "Trending", - "description": "used in youtube.html" - }, - - "feed": { - "message": "Feed", - "description": "used in youtube.html" - }, - - "showComments": { - "message": "Show comments", - "description": "used in youtube.html" - }, - - "minimizeDesc": { - "message": "Minimize description by default", - "description": "used in youtube.html" - }, - - "storeHistory": { - "message": "Store watch history", - "description": "used in youtube.html" - }, - - "enabledCodecs": { - "message": "Enabled codecs (multiple)", - "description": "used in youtube.html" - }, - - "disableLBRY": { - "message": "Disable LBRY for streaming", - "description": "used in youtube.html" - }, - - "enableProxyLBRY": { - "message": "Enable proxy for LBRY", - "description": "used in youtube.html" - }, - - "proxyLBRY": { - "message": "Proxy LBRY videos", - "description": "used in youtube.html" - }, - - "skipNote": { - "message": "Skip to the last watched point when encountering a video already seen", - "description": "used in youtube.html" - }, - - "embedExceptions": { - "message": "Embed exceptions", - "description": "used in youtube.html" - }, - - "instanceOffline": { - "message": "This instance is offline, you'll be redirected after ", - "description": "used in instance_offline.html" - }, - - "sec": { - "message": "الثواني", - "description": "used in instance_offline.html" - }, - - "cancel": { - "message": "إلغاء", - "description": "used in instance_offline.html" - }, - - "instanceIsOff": { - "message": "المَثيل غير متصل على النت", - "description": "used in instance_offline.html" - }, - - "redirectionCanceled": { - "message": "تم إلغاء إعادة التوجيه", - "description": "used in instance_offline.js" - } + "extensionName": { + "message": "LibRedirect", + "description": "extension name" + }, + "extensionDescription": { + "message": "إضافة متصفح تعيد توجيه مواقع مشهورة إلى واجهات أمامية تحترم الخصوصية", + "description": "extension description" + }, + "switchInstance": { + "message": "تبديل النظير", + "description": "used in the popup" + }, + "settings": { + "message": "الإعدادات", + "description": "used in the popup" + }, + "copyRaw": { + "message": "الرابط الأصلي", + "description": "used in the popup" + }, + "copied": { + "message": "تم النسخ", + "description": "used in the popup" + }, + "unifySettings": { + "message": "توحيد الإعدادات", + "description": "used in the popup" + }, + "unified": { + "message": "تم التوحيد", + "description": "used in the popup" + }, + "general": { + "message": "العامة", + "description": "used in the settings page" + }, + "youtube": { + "message": "يوتيوب", + "description": "" + }, + "ytmusic": { + "message": "يوتيوب ميوزيك", + "description": "" + }, + "instagram": { + "message": "إنستغرام", + "description": "" + }, + "twitter": { + "message": "تويتر", + "description": "" + }, + "reddit": { + "message": "ريديت", + "description": "" + }, + "tiktok": { + "message": "تيك توك", + "description": "" + }, + "lbry": { + "message": "LBRY", + "description": "" + }, + "imgur": { + "message": "إمجور", + "description": "" + }, + "wikipedia": { + "message": "ويكيبيديا", + "description": "" + }, + "peertube": { + "message": "PeerTube", + "description": "" + }, + "medium": { + "message": "ميديام", + "description": "" + }, + "search": { + "message": "البحث", + "description": "" + }, + "translate": { + "message": "الترجمة", + "description": "" + }, + "maps": { + "message": "الخرائط", + "description": "" + }, + "sendFiles": { + "message": "إرسال الملفات", + "description": "" + }, + "theme": { + "message": "السمة", + "description": "used in the settings page" + }, + "system": { + "message": "النظام", + "description": "used in the settings page" + }, + "light": { + "message": "فاتح", + "description": "used in the settings page" + }, + "dark": { + "message": "داكن", + "description": "used in the settings page" + }, + "autoRedirect": { + "message": "إعادة التوجيه تلقائياً من النظراء الذين لا يعملون", + "description": "used in the settings page" + }, + "exceptions": { + "message": "الاستثناءات", + "description": "used in the settings page" + }, + "updateInstances": { + "message": "تحديث قائمة النظراء", + "description": "used in the settings page" + }, + "importSettings": { + "message": "استيراد الإعدادات", + "description": "used in the settings page" + }, + "exportSettings": { + "message": "تصدير الإعدادات", + "description": "used in the settings page" + }, + "resetSettings": { + "message": "إعادة تعيين الإعدادات", + "description": "used in the settings page" + }, + "customPopup": { + "message": "تخصيص النافذة المنبثقة", + "description": "used in the settings page" + }, + "enable": { + "message": "تفعيل", + "description": "used in the settings page" + }, + "protocol": { + "message": "البروتوكول", + "description": "used in the settings page" + }, + "normal": { + "message": "العادي", + "description": "used in the settings page" + }, + "tor": { + "message": "تور", + "description": "used in the settings page" + }, + "i2p": { + "message": "i2p", + "description": "used in the settings page" + }, + "defaultInstances": { + "message": "النظراء الافتراضيين", + "description": "used in the settings page" + }, + "customInstances": { + "message": "النظراء المخصصين", + "description": "used in the settings page" + }, + "toggleAll": { + "message": "تبديل الكل", + "description": "used in the settings page" + }, + "frontend": { + "message": "الواجهة الأمامية", + "description": "used in the settings page" + }, + "notFullyPrivate": { + "message": "هذه الواجهة لا تحترم الخصوصية تماماً", + "description": "used in the settings page" + }, + "instanceOffline": { + "message": "هذا النظير غير متصل بالإنترنت، سيتم إعادة توجيهك بعد ", + "description": "used in instance_offline.html" + }, + "cancel": { + "message": "إلغاء", + "description": "used in instance_offline.html" + }, + "instanceIsOff": { + "message": "النظير غير متصل على النت", + "description": "used in instance_offline.html" + }, + "redirectionCanceled": { + "message": "تم إلغاء إعادة التوجيه", + "description": "used in instance_offline.html" + }, + "testInstancesLatency": { + "message": "تجربة سرعة استجابة النظراء", + "description": "used in the settings page" + }, + "redirectType": { + "message": "نوع التوجيه", + "description": "used in the settings page" + }, + "both": { + "message": "الإثنين", + "description": "used in the settings page" + }, + "onlyEmbedded": { + "message": "فقط المضمنة", + "description": "used in the settings page" + }, + "onlyNotEmbedded": { + "message": "فقط الغير مضمنة", + "description": "used in the settings page" + }, + "searchNote": { + "message": "ملاحظة: لاستعمال خاصية البحث بإماكنيتها الكاملة، اجعل LibRedirect محرك البحث الافتراضي في إعدادات متصفحك.", + "description": "used in the settings page" } +} \ No newline at end of file diff --git a/src/_locales/de/messages.json b/src/_locales/de/messages.json index 50e9f247..ebd87e7d 100644 --- a/src/_locales/de/messages.json +++ b/src/_locales/de/messages.json @@ -3,554 +3,220 @@ "message": "LibRedirect", "description": "name of the extension" }, - "extensionDescription": { "message": "Eine Erweiterung, die beliebte Websites zu alternativen datenschutzfreundlichen Frontends und Backends weiterleitet.", "description": "description of the extension" }, - "switchInstance": { "message": "Instanz wechseln", "description": "used in manifest.json as shortcut description" }, - - "instance": { - "message": "Instanz", - "description": "used in popup.html" - }, - "settings": { "message": "Optionen", "description": "used in popup.html" }, - - "libOptions": { - "message": "LibRedirect-Optionen", - "description": "used in general.html" - }, - "general": { "message": "Allgemein", "description": "used in general.html" }, - "search": { "message": "Suche", "description": "used in general.html" }, - "translate": { "message": "Übersetzen", "description": "used in general.html" }, - "maps": { "message": "Karten", "description": "used in general.html" }, - "sendFiles": { "message": "Dateien senden", "description": "used in general.html" }, - "youtube": { "message": "YouTube", "description": "used in general.html" }, - "instagram": { "message": "Instagram", "description": "used in general.html" }, - "twitter": { "message": "Twitter", "description": "used in general.html" }, - "reddit": { "message": "Reddit", "description": "used in general.html" }, - "tiktok": { "message": "TikTok", "description": "used in general.html" }, - "ytmusic": { "message": "YT Music", "description": "used in general.html" }, - "imgur": { "message": "Imgur", "description": "used in general.html" }, - "wikipedia": { "message": "Wikipedia", "description": "used in general.html" }, - "peertube": { "message": "PeerTube", "description": "used in general.html" }, - "medium": { "message": "Medium", "description": "used in general.html" }, - "tor": { "message": "Tor", "description": "used in imgur.html" }, - "theme": { "message": "Thema", "description": "used in general.html" }, - "system": { "message": "System", "description": "used in general.html" }, - "light": { "message": "Hell", "description": "used in general.html" }, - "dark": { "message": "Dunkel", "description": "used in general.html" }, - - "applyTheme": { - "message": "Thema auf Seiten anwenden", - "description": "used in general.html" - }, - - "alwaysPref": { - "message": "Immer bevorzugte Instanzen verwenden", - "description": "used in general.html" - }, - "autoRedirect": { "message": "Instanzen automatisch weiterleiten, die offline sind", "description": "used in general.html" }, - "exceptions": { "message": "Ausnahmen", "description": "used in general.html" }, - "updateInstances": { "message": "Instanzen aktualisieren", "description": "used in general.html" }, - "importSettings": { "message": "Einstellungen importieren", "description": "used in general.html" }, - "exportSettings": { "message": "Einstellungen exportieren", "description": "used in general.html" }, - "resetSettings": { "message": "Einstellungen zurücksetzen", "description": "used in general.html" }, - "customPopup": { "message": "Popup personalisieren", "description": "used in general.html" }, - "enable": { "message": "Aktivieren", "description": "used in imgur.html" }, - "protocol": { "message": "Protokoll", "description": "used in imgur.html" }, - "normal": { "message": "Normal", "description": "used in imgur.html" }, - "defaultInstances": { "message": "Standard-Instanzen", "description": "used in imgur.html" }, - "customInstances": { "message": "Eigene Instanzen", "description": "used in imgur.html" }, - "toggleAll": { "message": "Alle umschalten", "description": "used in utils.js" }, - "frontend": { "message": "Frontend", "description": "used in maps.html" }, - "notFullyPrivate": { "message": "Das ist kein völlig privates Frontend.", "description": "" }, - - "oldReddit": { - "message": "Altes Reddit", - "description": "used in reddit.html" - }, - "searchNote": { "message": "Hinweis: Um das volle Potenzial der Suchweiterleitung auszunutzen, lege LibRedirect als Standardsuchmaschine fest.", "description": "used in search.html" }, - - "libSendFiles": { - "message": "LibRedirect: Dateien senden", - "description": "used in sendTargets.html" - }, - - "from": { - "message": "Von", - "description": "used in translate.html" - }, - - "to": { - "message": "Nach", - "description": "used in translate.html" - }, - - "default": { - "message": "Standard", - "description": "used in translate.html" - }, - - "auto": { - "message": "Auto", - "description": "used in translate.html" - }, - - "engine": { - "message": "Übersetzer", - "description": "used in translate.html" - }, - - "libTranslate": { - "message": "LibRedirect: Übersetzen", - "description": "used in translate.html" - }, - - "invidious": { - "message": "Invidious", - "description": "used in youtube.html" - }, - - "embeddedVids": { - "message": "Frontend für eingebettete Videos", - "description": "used in youtube.html" - }, - "redirectType": { "message": "Art der Weiterleitung", "description": "used in youtube.html" }, - "both": { "message": "beides", "description": "used in youtube.html" }, - "onlyEmbedded": { "message": "nur eingebettet", "description": "used in youtube.html" }, - "onlyNotEmbedded": { "message": "nur nicht-eingebunden", "description": "used in youtube.html" }, - - "enableCustom": { - "message": "Aktiviere benutzerdefinierte Einstellungen (verwendet Cookies und localStorage)", - "description": "used in youtube.html" - }, - - "autoplayVid": { - "message": "Video automatisch abspielen", - "description": "used in youtube.html" - }, - - "volume": { - "message": "Lautstärke: ", - "description": "used in youtube.html" - }, - - "playerStyle": { - "message": "Player-Stil", - "description": "used in youtube.html" - }, - - "alwaysLoop": { - "message": "Immer wiederholen", - "description": "used in youtube.html" - }, - - "playNext": { - "message": "Immer automatisch nächstes Video abspielen", - "description": "used in youtube.html" - }, - - "autoplayNext": { - "message": "Nächstes Video automatisch abspielen", - "description": "used in youtube.html" - }, - - "alwaysProxy": { - "message": "Videos immer durch Proxy leiten", - "description": "used in youtube.html" - }, - - "listenByDefault": { - "message": "Nur Ton als Standard", - "description": "used in youtube.html" - }, - - "defaultSpeed": { - "message": "Standardgeschwindigkeit", - "description": "used in youtube.html" - }, - - "prefQuality": { - "message": "Bevorzugte Videoqualität", - "description": "used in youtube.html" - }, - - "dash": { - "message": "DASH (automatische Qualität)", - "description": "used in youtube.html" - }, - - "prefDashQuality": { - "message": "Bevorzugte DASH-Videoqualität", - "description": "used in youtube.html" - }, - - "best": { - "message": "Höchste", - "description": "used in youtube.html" - }, - - "worst": { - "message": "Niedrigste", - "description": "used in youtube.html" - }, - - "defaultComments": { - "message": "Standardkommentare", - "description": "used in youtube.html" - }, - - "none": { - "message": "keine", - "description": "used in youtube.html" - }, - - "defaultCaptions": { - "message": "Standarduntertitel", - "description": "used in youtube.html" - }, - - "showRelated": { - "message": "Ähnliche Videos anzeigen", - "description": "used in youtube.html" - }, - - "showAnnotations": { - "message": "Anmerkungen standardmäßig anzeigen", - "description": "used in youtube.html" - }, - - "autoExtendDesc": { - "message": "Videobeschreibung automatisch erweitern", - "description": "used in youtube.html" - }, - - "interactive360": { - "message": "Interaktive 360-Grad-Videos (erfordert WebGL)", - "description": "used in youtube.html" - }, - - "savePlaybackPos": { - "message": "Wiedergabeposition speichern", - "description": "used in youtube.html" - }, - - "enableSponsorBlock": { - "message": "SponsorBlock einschalten", - "description": "used in youtube.html" - }, - - "skipSponsors": { - "message": "Sponsoren überspringen", - "description": "used in youtube.html" - }, - - "skipIntermission": { - "message": "Pausen-/Intro-Animation überspringen", - "description": "used in youtube.html" - }, - - "skipEndcards": { - "message": "Abspann überspringen", - "description": "used in youtube.html" - }, - - "skipPreview": { - "message": "Vorschau/Rückschau überspringen", - "description": "used in youtube.html" - }, - - "skipReminder": { - "message": "Interaktionserinnerung überspringen (Abonnieren)", - "description": "used in youtube.html" - }, - - "skipUnpaidPromo": { - "message": "Unbezahlte Werbung/Eigenwerbung überspringen", - "description": "used in youtube.html" - }, - - "skipMusic": { - "message": "Musik überspringen: Nicht-Musik-Bereich", - "description": "used in youtube.html" - }, - - "skipHighlight": { - "message": "Höhepunkt überspringen", - "description": "used in youtube.html" - }, - - "skipFiller": { - "message": "Lückenfüller überspringen", - "description": "used in youtube.html" - }, - - "audioOnly": { - "message": "Nur Audio", - "description": "used in youtube.html" - }, - - "defaultQuality": { - "message": "Standardqualität", - "description": "used in youtube.html" - }, - - "bufferingGoal": { - "message": "Pufferungsziel (in Sekunden)", - "description": "used in youtube.html" - }, - - "countrySelection": { - "message": "Länderauswahl", - "description": "used in youtube.html" - }, - - "defaultHomepage": { - "message": "Standard-Startseite", - "description": "used in youtube.html" - }, - - "trending": { - "message": "Trends", - "description": "used in youtube.html" - }, - - "feed": { - "message": "Abonnements", - "description": "used in youtube.html" - }, - - "showComments": { - "message": "Kommentare anzeigen", - "description": "used in youtube.html" - }, - - "minimizeDesc": { - "message": "Beschreibung standardmäßig minimieren", - "description": "used in youtube.html" - }, - - "storeHistory": { - "message": "Wiedergabeverlauf speichern", - "description": "used in youtube.html" - }, - - "enabledCodecs": { - "message": "Aktivierte Codecs (mehrere)", - "description": "used in youtube.html" - }, - - "disableLBRY": { - "message": "LBRY für Streaming deaktivieren", - "description": "used in youtube.html" - }, - - "enableProxyLBRY": { - "message": "Proxy für LBRY einschalten", - "description": "used in youtube.html" - }, - - "proxyLBRY": { - "message": "LBRY-Videos durch Proxy leiten", - "description": "used in youtube.html" - }, - - "skipNote": { - "message": "Springe zum letzten Wiedergabezeitpunkt bei bereits angesehenen Videos", - "description": "used in youtube.html" - }, - - "embedExceptions": { - "message": "Ausnahmen einbetten", - "description": "used in youtube.html" - }, - - "sec": { - "message": "Sekunden", - "description": "used in instance_offline.html" - }, - "cancel": { "message": "Abbrechen", "description": "used in instance_offline.html" }, - "instanceIsOff": { "message": "Instanz ist offline", "description": "used in instance_offline.html" }, - "redirectionCanceled": { "message": "Weiterleitung abgebrochen", "description": "used in instance_offline.js" + }, + "copyRaw": { + "message": "", + "description": "" + }, + "copied": { + "message": "", + "description": "" + }, + "unifySettings": { + "message": "", + "description": "" + }, + "unified": { + "message": "", + "description": "" + }, + "lbry": { + "message": "", + "description": "" + }, + "i2p": { + "message": "", + "description": "" + }, + "instanceOffline": { + "message": "", + "description": "" + }, + "testInstancesLatency": { + "message": "", + "description": "" } -} +} \ No newline at end of file diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index daeff4b7..c7cd3768 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -3,554 +3,220 @@ "message": "LibRedirect", "description": "name of the extension" }, - "extensionDescription": { "message": "A web extension that redirects popular sites to alternative privacy-friendly frontends and backends", "description": "description of the extension" }, - "switchInstance": { "message": "Switch Instance", "description": "used in manifest.json as shortcut description" }, - - "instance": { - "message": "Instance", - "description": "used in popup.html" - }, - "settings": { "message": "Settings", "description": "used in popup.html" }, - - "libOptions": { - "message": "LibRedirect Options", - "description": "used in general.html" - }, - "general": { "message": "General", "description": "used in general.html" }, - "search": { "message": "Search", "description": "used in general.html" }, - "translate": { "message": "Translate", "description": "used in general.html" }, - "maps": { "message": "Maps", "description": "used in general.html" }, - "sendFiles": { "message": "Send Files", "description": "used in general.html" }, - "youtube": { "message": "YouTube", "description": "used in general.html" }, - "instagram": { "message": "Instagram", "description": "used in general.html" }, - "twitter": { "message": "Twitter", "description": "used in general.html" }, - "reddit": { "message": "Reddit", "description": "used in general.html" }, - "tiktok": { "message": "TikTok", "description": "used in general.html" }, - "ytmusic": { "message": "YT Music", "description": "used in general.html" }, - "imgur": { "message": "Imgur", "description": "used in general.html" }, - "wikipedia": { "message": "Wikipedia", "description": "used in general.html" }, - "peertube": { "message": "PeerTube", "description": "used in general.html" }, - "medium": { "message": "Medium", "description": "used in general.html" }, - "tor": { "message": "Tor", "description": "used in imgur.html" }, - "theme": { "message": "Theme", "description": "used in general.html" }, - "system": { "message": "System", "description": "used in general.html" }, - "light": { "message": "Light", "description": "used in general.html" }, - "dark": { "message": "Dark", "description": "used in general.html" }, - - "alwaysPref": { - "message": "Always use Preferred Instances", - "description": "used in general.html" - }, - "autoRedirect": { "message": "Auto Redirect of offline instances", "description": "used in general.html" }, - "exceptions": { "message": "Exceptions", "description": "used in general.html" }, - "updateInstances": { "message": "Update Instances", "description": "used in general.html" }, - "importSettings": { "message": "Import Settings", "description": "used in general.html" }, - "exportSettings": { "message": "Export Settings", "description": "used in general.html" }, - "resetSettings": { "message": "Reset Settings", "description": "used in general.html" }, - "customPopup": { "message": "Customize Popup", "description": "used in general.html" }, - "enable": { "message": "Enable", "description": "used in imgur.html" }, - "protocol": { "message": "Protocol", "description": "used in imgur.html" }, - "normal": { "message": "Normal", "description": "used in imgur.html" }, - "defaultInstances": { "message": "Default Instances", "description": "used in imgur.html" }, - "customInstances": { "message": "Custom Instances", "description": "used in imgur.html" }, - "toggleAll": { "message": "Toggle all", "description": "used in utils.js" }, - "frontend": { "message": "Frontend", "description": "used in maps.html" }, - "notFullyPrivate": { "message": "This isn't a fully private frontend.", "description": "" }, - - "oldReddit": { - "message": "Old Reddit", - "description": "used in reddit.html" - }, - "searchNote": { "message": "Note: To use Search to its full potential, make LibRedirect as the Default Search Engine", "description": "used in search.html" }, - - "libSendFiles": { - "message": "LibRedirect: Send Files", - "description": "used in sendTargets.html" - }, - - "from": { - "message": "From", - "description": "used in translate.html" - }, - - "to": { - "message": "To", - "description": "used in translate.html" - }, - - "default": { - "message": "Default", - "description": "used in translate.html" - }, - - "auto": { - "message": "Auto", - "description": "used in translate.html" - }, - - "engine": { - "message": "Engine", - "description": "used in translate.html" - }, - - "libTranslate": { - "message": "LibRedirect: Translate", - "description": "used in translate.html" - }, - - "invidious": { - "message": "Invidious", - "description": "used in youtube.html" - }, - - "embeddedVids": { - "message": "Embedded Videos Frontend", - "description": "used in youtube.html" - }, - "redirectType": { "message": "Redirect Type", "description": "used in youtube.html" }, - "both": { "message": "both", "description": "used in youtube.html" }, - "onlyEmbedded": { "message": "only embedded", "description": "used in youtube.html" }, - "onlyNotEmbedded": { "message": "only not embedded", "description": "used in youtube.html" }, - - "enableCustom": { - "message": "Enable Custom Settings (will use cookies and localStorage)", - "description": "used in youtube.html" - }, - - "autoplayVid": { - "message": "Autoplay Video", - "description": "used in youtube.html" - }, - - "volume": { - "message": "Volume: ", - "description": "used in youtube.html" - }, - - "playerStyle": { - "message": "Player Style", - "description": "used in youtube.html" - }, - - "alwaysLoop": { - "message": "Always loop", - "description": "used in youtube.html" - }, - - "playNext": { - "message": "Play next by default", - "description": "used in youtube.html" - }, - - "autoplayNext": { - "message": "Autoplay next video", - "description": "used in youtube.html" - }, - - "alwaysProxy": { - "message": "Always proxy videos", - "description": "used in youtube.html" - }, - - "listenByDefault": { - "message": "Listen by default", - "description": "used in youtube.html" - }, - - "defaultSpeed": { - "message": "Default speed", - "description": "used in youtube.html" - }, - - "prefQuality": { - "message": "Preferred video quality", - "description": "used in youtube.html" - }, - - "dash": { - "message": "DASH (adaptive quality)", - "description": "used in youtube.html" - }, - - "prefDashQuality": { - "message": "Preferred DASH video quality", - "description": "used in youtube.html" - }, - - "best": { - "message": "Best", - "description": "used in youtube.html" - }, - - "worst": { - "message": "Worst", - "description": "used in youtube.html" - }, - - "defaultComments": { - "message": "Default comments", - "description": "used in youtube.html" - }, - - "none": { - "message": "None", - "description": "used in youtube.html" - }, - - "defaultCaptions": { - "message": "Default captions", - "description": "used in youtube.html" - }, - - "showRelated": { - "message": "Show related videos", - "description": "used in youtube.html" - }, - - "showAnnotations": { - "message": "Show annotations by default", - "description": "used in youtube.html" - }, - - "autoExtendDesc": { - "message": "Automatically extend video description", - "description": "used in youtube.html" - }, - - "interactive360": { - "message": "Interactive 360 degree videos (requires WebGL)", - "description": "used in youtube.html" - }, - - "savePlaybackPos": { - "message": "Save playback position", - "description": "used in youtube.html" - }, - - "enableSponsorBlock": { - "message": "Enable SponsorBlock", - "description": "used in youtube.html" - }, - - "skipSponsors": { - "message": "Skip sponsors", - "description": "used in youtube.html" - }, - - "skipIntermission": { - "message": "Skip Intermission/Intro Animation", - "description": "used in youtube.html" - }, - - "skipEndcards": { - "message": "Skip Endcards/Credits", - "description": "used in youtube.html" - }, - - "skipPreview": { - "message": "Skip Preview/Recap", - "description": "used in youtube.html" - }, - - "skipReminder": { - "message": "Skip interaction reminder (subscribe)", - "description": "used in youtube.html" - }, - - "skipUnpaidPromo": { - "message": "Skip Unpaid/Self Promotion", - "description": "used in youtube.html" - }, - - "skipMusic": { - "message": "Skip Music: Non-Music Section", - "description": "used in youtube.html" - }, - - "skipHighlight": { - "message": "Skip Highlight", - "description": "used in youtube.html" - }, - - "skipFiller": { - "message": "Skip Filler Tangent", - "description": "used in youtube.html" - }, - - "audioOnly": { - "message": "Audio only", - "description": "used in youtube.html" - }, - - "defaultQuality": { - "message": "Default quality", - "description": "used in youtube.html" - }, - - "bufferingGoal": { - "message": "Buffering Goal (in seconds)", - "description": "used in youtube.html" - }, - - "countrySelection": { - "message": "Country selection", - "description": "used in youtube.html" - }, - - "defaultHomepage": { - "message": "Default homepage", - "description": "used in youtube.html" - }, - - "trending": { - "message": "Trending", - "description": "used in youtube.html" - }, - - "feed": { - "message": "Feed", - "description": "used in youtube.html" - }, - - "showComments": { - "message": "Show comments", - "description": "used in youtube.html" - }, - - "minimizeDesc": { - "message": "Minimize description by default", - "description": "used in youtube.html" - }, - - "storeHistory": { - "message": "Store watch history", - "description": "used in youtube.html" - }, - - "enabledCodecs": { - "message": "Enabled codecs (multiple)", - "description": "used in youtube.html" - }, - - "disableLBRY": { - "message": "Disable LBRY for streaming", - "description": "used in youtube.html" - }, - - "enableProxyLBRY": { - "message": "Enable proxy for LBRY", - "description": "used in youtube.html" - }, - - "proxyLBRY": { - "message": "Proxy LBRY videos", - "description": "used in youtube.html" - }, - - "skipNote": { - "message": "Skip to the last watched point when encountering a video already seen", - "description": "used in youtube.html" - }, - - "embedExceptions": { - "message": "Embed exceptions", - "description": "used in youtube.html" - }, - "instanceOffline": { "message": "This instance is offline, you'll be redirected after ", "description": "used in instance_offline.html" }, - - "sec": { - "message": "seconds", - "description": "used in instance_offline.html" - }, - "cancel": { "message": "Cancel", "description": "used in instance_offline.html" }, - "instanceIsOff": { "message": "Instance is offline", "description": "used in instance_offline.html" }, - "redirectionCanceled": { "message": "Redirection canceled", "description": "used in instance_offline.js" + }, + "copyRaw": { + "message": "Copy Raw", + "description": "" + }, + "copied": { + "message": "Copied", + "description": "" + }, + "unifySettings": { + "message": "Unify Settings", + "description": "" + }, + "unified": { + "message": "Unified", + "description": "" + }, + "lbry": { + "message": "LBRY", + "description": "" + }, + "i2p": { + "message": "I2P", + "description": "" + }, + "testInstancesLatency": { + "message": "Test Instances Latency", + "description": "" } -} +} \ No newline at end of file diff --git a/src/_locales/filter.py b/src/_locales/filter.py new file mode 100644 index 00000000..1576b1fb --- /dev/null +++ b/src/_locales/filter.py @@ -0,0 +1,43 @@ +import requests +import json +from urllib.parse import urlparse +from bs4 import BeautifulSoup +import re +from colorama import Fore, Back, Style +from urllib.parse import urlparse +import socket +import subprocess + + +ar_json = {} +with open('ar/messages.json') as data: + ar_json = json.load(data) + + +en_json = {} +with open('en/messages.json') as data: + en_json = json.load(data) + + +remove_keys = [] +for item in en_json.keys(): + if item not in ar_json.keys(): + remove_keys.append(item) + +for item in remove_keys: + en_json.pop(item) + +add_keys = [] +for item in ar_json.keys(): + if item not in en_json.keys(): + print(item) + add_keys.append(item) + +for item in add_keys: + en_json[item] = { + "message": "", + "description": "" + } + +with open('en/messages.json', 'w') as outfile: + outfile.write(json.dumps(en_json, ensure_ascii=False, indent=2)) diff --git a/src/assets/javascripts/general.js b/src/assets/javascripts/general.js new file mode 100644 index 00000000..199d884c --- /dev/null +++ b/src/assets/javascripts/general.js @@ -0,0 +1,71 @@ +"use strict"; +window.browser = window.browser || window.chrome; + +function isException(url) { + for (const item of exceptions.url) + if (item == `${url.protocol}//${url.host}`) return true; + for (const item of exceptions.regex) + if (new RegExp(item).test(url.href)) return true; + return false; +} + +let exceptions; + +function init() { + browser.storage.local.get( + 'exceptions', + r => { + exceptions = r.exceptions; + } + ) +} + +init(); +browser.storage.onChanged.addListener(init) + +async function initDefaults() { + await browser.storage.local.set({ + exceptions: { + "url": [], + "regex": [], + }, + theme: "DEFAULT", + popupFrontends: [ + "youtube", + "twitter", + "instagram", + "tikTok", + "imgur", + "reddit", + "search", + "medium", + "translate", + "maps", + ], + autoRedirect: false, + }) +} + +const allPopupFrontends = [ + "youtube", + "youtubeMusic", + "twitter", + "instagram", + "tikTok", + "imgur", + "reddit", + "search", + "translate", + "maps", + "wikipedia", + "medium", + "peertube", + "lbry", + "sendTargets" +]; + +export default { + isException, + initDefaults, + allPopupFrontends, +} diff --git a/src/assets/javascripts/helpers/general.js b/src/assets/javascripts/helpers/general.js deleted file mode 100644 index 199d884c..00000000 --- a/src/assets/javascripts/helpers/general.js +++ /dev/null @@ -1,71 +0,0 @@ -"use strict"; -window.browser = window.browser || window.chrome; - -function isException(url) { - for (const item of exceptions.url) - if (item == `${url.protocol}//${url.host}`) return true; - for (const item of exceptions.regex) - if (new RegExp(item).test(url.href)) return true; - return false; -} - -let exceptions; - -function init() { - browser.storage.local.get( - 'exceptions', - r => { - exceptions = r.exceptions; - } - ) -} - -init(); -browser.storage.onChanged.addListener(init) - -async function initDefaults() { - await browser.storage.local.set({ - exceptions: { - "url": [], - "regex": [], - }, - theme: "DEFAULT", - popupFrontends: [ - "youtube", - "twitter", - "instagram", - "tikTok", - "imgur", - "reddit", - "search", - "medium", - "translate", - "maps", - ], - autoRedirect: false, - }) -} - -const allPopupFrontends = [ - "youtube", - "youtubeMusic", - "twitter", - "instagram", - "tikTok", - "imgur", - "reddit", - "search", - "translate", - "maps", - "wikipedia", - "medium", - "peertube", - "lbry", - "sendTargets" -]; - -export default { - isException, - initDefaults, - allPopupFrontends, -} diff --git a/src/assets/javascripts/helpers/imgur.js b/src/assets/javascripts/helpers/imgur.js deleted file mode 100644 index 9f93f362..00000000 --- a/src/assets/javascripts/helpers/imgur.js +++ /dev/null @@ -1,191 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = /^https?:\/{2}([im]\.)?imgur\.com(\/|$)/ - -let redirects = { - "rimgo": { - "normal": [], - "tor": [], - "i2p": [] - } -} -function setRedirects() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.rimgo = dataJson.rimgo; - - rimgoNormalRedirectsChecks = [...redirects.rimgo.normal]; - rimgoTorRedirectsChecks = [...redirects.rimgo.tor]; - rimgoI2pRedirectsChecks = [...redirects.rimgo.i2p]; - - for (const instance of r.cloudflareList) { - const a = rimgoNormalRedirectsChecks.indexOf(instance); - if (a > -1) rimgoNormalRedirectsChecks.splice(a, 1); - - const b = rimgoTorRedirectsChecks.indexOf(instance); - if (b > -1) rimgoTorRedirectsChecks.splice(b, 1); - - const c = rimgoI2pRedirectsChecks.indexOf(instance); - if (c > -1) rimgoI2pRedirectsChecks.splice(c, 1); - } - - await browser.storage.local.set({ - imgurRedirects: redirects, - rimgoNormalRedirectsChecks, - rimgoTorRedirectsChecks, - rimgoI2pRedirectsChecks, - }); - - resolve(); - }) - }) -} - -let - disableImgur, - imgurRedirects, - imgurProtocol, - rimgoNormalRedirectsChecks, - rimgoNormalCustomRedirects, - rimgoTorRedirectsChecks, - rimgoTorCustomRedirects, - rimgoI2pRedirectsChecks, - rimgoI2pCustomRedirects; - -function init() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - "disableImgur", - "imgurRedirects", - "imgurProtocol", - "rimgoNormalRedirectsChecks", - "rimgoNormalCustomRedirects", - "rimgoTorRedirectsChecks", - "rimgoTorCustomRedirects", - "rimgoI2pRedirectsChecks", - "rimgoI2pCustomRedirects", - ], - r => { - disableImgur = r.disableImgur; - imgurRedirects = r.imgurRedirects; - imgurProtocol = r.imgurProtocol; - rimgoNormalRedirectsChecks = r.rimgoNormalRedirectsChecks; - rimgoNormalCustomRedirects = r.rimgoNormalCustomRedirects; - rimgoTorRedirectsChecks = r.rimgoTorRedirectsChecks; - rimgoTorCustomRedirects = r.rimgoTorCustomRedirects; - rimgoI2pRedirectsChecks = r.rimgoI2pRedirectsChecks; - rimgoI2pCustomRedirects = r.rimgoI2pCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -// https://imgur.com/gallery/s4WXQmn -// https://imgur.com/a/H8M4rcp -// https://imgur.com/gallery/gYiQLWy -// https://imgur.com/gallery/cTRwaJU -// https://i.imgur.com/CFSQArP.jpeg - -function all() { - return [ - ...imgurRedirects.rimgo.normal, - ...imgurRedirects.rimgo.tor, - ...imgurRedirects.rimgo.i2p, - ...rimgoNormalCustomRedirects, - ...rimgoTorCustomRedirects, - ...rimgoI2pCustomRedirects, - ]; -} - -function redirect(url, type, initiator) { - if (disableImgur) return; - if (url.pathname == "/") return; - if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media",].includes(type)) return; - if (initiator && (all().includes(initiator.origin) || targets.test(initiator.host))) return; - if (!targets.test(url.href)) return; - if (url.pathname.includes("delete/")) return; - - let instancesList; - if (imgurProtocol == 'normal') instancesList = [...rimgoNormalRedirectsChecks, ...rimgoNormalCustomRedirects]; - if (imgurProtocol == 'tor') instancesList = [...rimgoTorRedirectsChecks, ...rimgoTorCustomRedirects]; - if (imgurProtocol == 'i2p') instancesList = [...rimgoI2pRedirectsChecks, ...rimgoI2pCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - return `${randomInstance}${url.pathname}${url.search}`; -} - -function reverse(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - resolve(`https://imgur.com${url.pathname}${url.search}`); - }) -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - let instancesList; - if (imgurProtocol == 'normal') instancesList = [...rimgoNormalCustomRedirects, ...rimgoNormalRedirectsChecks]; - else if (imgurProtocol == 'tor') instancesList = [...rimgoTorCustomRedirects, ...rimgoTorRedirectsChecks]; - else if (imgurProtocol == 'i2p') instancesList = [...rimgoI2pCustomRedirects, ...rimgoI2pRedirectsChecks]; - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.rimgo = dataJson.rimgo; - browser.storage.local.get('cloudflareList', async r => { - rimgoNormalRedirectsChecks = [...redirects.rimgo.normal]; - for (const instance of r.cloudflareList) { - const i = rimgoNormalRedirectsChecks.indexOf(instance); - if (i > -1) rimgoNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableImgur: false, - imgurProtocol: 'normal', - imgurRedirects: redirects, - - rimgoNormalRedirectsChecks: rimgoNormalRedirectsChecks, - rimgoNormalCustomRedirects: [], - - rimgoTorRedirectsChecks: [...redirects.rimgo.tor], - rimgoTorCustomRedirects: [], - - rimgoI2pRedirectsChecks: [...redirects.rimgo.i2p], - rimgoI2pCustomRedirects: [], - }); - resolve(); - }); - }); - }); -} - -export default { - setRedirects, - redirect, - reverse, - initDefaults, - switchInstance, -}; diff --git a/src/assets/javascripts/helpers/instagram.js b/src/assets/javascripts/helpers/instagram.js deleted file mode 100644 index f5c54b3a..00000000 --- a/src/assets/javascripts/helpers/instagram.js +++ /dev/null @@ -1,166 +0,0 @@ -window.browser = window.browser || window.chrome; -import utils from './utils.js' - -const targets = [ - "instagram.com", - "www.instagram.com", -]; -let redirects = { - "bibliogram": { - "normal": [], - "tor": [] - } -}; -function setRedirects(val) { - browser.storage.local.get('cloudflareList', async r => { - redirects.bibliogram = val; - bibliogramNormalRedirectsChecks = [...redirects.bibliogram.normal]; - for (const instance of r.cloudflareList) { - const a = bibliogramNormalRedirectsChecks.indexOf(instance); - if (a > -1) bibliogramNormalRedirectsChecks.splice(a, 1); - } - browser.storage.local.set({ - instagramRedirects: redirects, - bibliogramNormalRedirectsChecks - }) - }) -} - -let - disableInstagram, - instagramProtocol, - instagramRedirects, - bibliogramNormalRedirectsChecks, - bibliogramTorRedirectsChecks, - bibliogramNormalCustomRedirects, - bibliogramTorCustomRedirects; - -function init() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - "disableInstagram", - "instagramProtocol", - "instagramRedirects", - "bibliogramNormalRedirectsChecks", - "bibliogramTorRedirectsChecks", - "bibliogramNormalCustomRedirects", - "bibliogramTorCustomRedirects", - ], - r => { - disableInstagram = r.disableInstagram; - instagramProtocol = r.instagramProtocol; - instagramRedirects = r.instagramRedirects; - bibliogramNormalRedirectsChecks = r.bibliogramNormalRedirectsChecks; - bibliogramTorRedirectsChecks = r.bibliogramTorRedirectsChecks; - bibliogramNormalCustomRedirects = r.bibliogramNormalCustomRedirects; - bibliogramTorCustomRedirects = r.bibliogramTorCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function all() { - return [ - ...instagramRedirects.bibliogram.normal, - ...instagramRedirects.bibliogram.tor, - ...bibliogramNormalCustomRedirects, - ...bibliogramTorCustomRedirects, - ] -} - -function redirect(url, type, initiator) { - if (disableInstagram) return; - if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; - if (!targets.includes(url.host)) return; - if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media"].includes(type)) return; - - const bypassPaths = [/about/, /explore/, /support/, /press/, /api/, /privacy/, /safety/, /admin/, /\/(accounts\/|embeds?.js)/]; - if (bypassPaths.some(rx => rx.test(url.pathname))) return; - - let instancesList; - if (instagramProtocol == 'normal') instancesList = [...bibliogramNormalRedirectsChecks, ...bibliogramNormalCustomRedirects]; - else if (instagramProtocol == 'tor') instancesList = [...bibliogramTorRedirectsChecks, ...bibliogramTorCustomRedirects]; - if (instancesList.length === 0) return; - let randomInstance = utils.getRandomInstance(instancesList) - - const reservedPaths = ["u", "p", "privacy",]; - if (url.pathname === "/" || reservedPaths.includes(url.pathname.split("/")[1])) - return `${randomInstance}${url.pathname}${url.search}`; - if (url.pathname.startsWith("/reel") || url.pathname.startsWith("/tv")) - return `${randomInstance}/p${url.pathname.replace(/\/reel|\/tv/i, '')}${url.search}`; - else - return `${randomInstance}/u${url.pathname}${url.search}`; // Likely a user profile, redirect to '/u/...' -} - -function reverse(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - - if (url.pathname.startsWith('/p')) resolve(`https://instagram.com${url.pathname.replace('/p', '')}${url.search}`); - if (url.pathname.startsWith('/u')) resolve(`https://instagram.com${url.pathname.replace('/u', '')}${url.search}`); - resolve(`https://instagram.com${url.pathname}${url.search}`); - }) -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (instagramProtocol == 'normal') instancesList = [...bibliogramNormalCustomRedirects, ...bibliogramNormalRedirectsChecks]; - else if (instagramProtocol == 'tor') instancesList = [...bibliogramTorCustomRedirects, ...bibliogramTorRedirectsChecks]; - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(data => { - let dataJson = JSON.parse(data); - redirects.bibliogram = dataJson.bibliogram; - browser.storage.local.get('cloudflareList', r => { - bibliogramNormalRedirectsChecks = [...redirects.bibliogram.normal]; - for (const instance of r.cloudflareList) { - const i = bibliogramNormalRedirectsChecks.indexOf(instance); - if (i > -1) bibliogramNormalRedirectsChecks.splice(i, 1); - } - browser.storage.local.set({ - disableInstagram: false, - instagramRedirects: redirects, - - bibliogramNormalRedirectsChecks: bibliogramNormalRedirectsChecks, - bibliogramTorRedirectsChecks: [], - - bibliogramNormalCustomRedirects: [...redirects.bibliogram.tor], - bibliogramTorCustomRedirects: [], - instagramProtocol: "normal", - }) - resolve(); - } - ) - }) - }) -} - -export default { - setRedirects, - reverse, - redirect, - initDefaults, - switchInstance, -}; diff --git a/src/assets/javascripts/helpers/lbry.js b/src/assets/javascripts/helpers/lbry.js deleted file mode 100644 index b44cc738..00000000 --- a/src/assets/javascripts/helpers/lbry.js +++ /dev/null @@ -1,156 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -let targets = ["odysee.com"]; - -let redirects = { - "librarian": { - "normal": [ - "https://lbry.bcow.xyz", - "https://odysee.076.ne.jp", - "https://lbry.ix.tc", - "https://librarian.pussthecat.org", - "https://lbry.mutahar.rocks", - "https://librarian.esmailelbob.xyz", - ], - "tor": [ - "http://ecc5mi5ncdw6mxhjz6re6g2uevtpbzxjvxgrxia2gyvrlnil3srbnhyd.onion", - "http://vrmbc4brkgkaysmi3fenbzkayobxjh24slmhtocambn3ewe62iuqt3yd.onion", - ] - } -} - -function setRedirects(val) { - redirects.librarian = val; - browser.storage.local.set({ lbryTargetsRedirects: redirects }) - for (const item of librarianNormalRedirectsChecks) - if (!redirects.librarian.normal.includes(item)) { - var index = librarianNormalRedirectsChecks.indexOf(item); - if (index !== -1) librarianNormalRedirectsChecks.splice(index, 1); - } - browser.storage.local.set(librarianNormalRedirectsChecks); - - for (const item of librarianTorRedirectsChecks) - if (!redirects.librarian.normal.includes(item)) { - var index = librarianTorRedirectsChecks.indexOf(item); - if (index !== -1) librarianTorRedirectsChecks.splice(index, 1); - } - browser.storage.local.set(librarianTorRedirectsChecks) -} - -let - disableLbryTargets, - lbryTargetsProtocol, - lbryTargetsRedirects, - librarianNormalRedirectsChecks, - librarianNormalCustomRedirects, - librarianTorRedirectsChecks, - librarianTorCustomRedirects; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "disableLbryTargets", - "lbryTargetsProtocol", - "lbryTargetsRedirects", - "librarianNormalRedirectsChecks", - "librarianNormalCustomRedirects", - "librarianTorRedirectsChecks", - "librarianTorCustomRedirects", - ], - r => { - disableLbryTargets = r.disableLbryTargets; - lbryTargetsProtocol = r.lbryTargetsProtocol; - lbryTargetsRedirects = r.lbryTargetsRedirects; - librarianNormalRedirectsChecks = r.librarianNormalRedirectsChecks; - librarianNormalCustomRedirects = r.librarianNormalCustomRedirects; - librarianTorRedirectsChecks = r.librarianTorRedirectsChecks; - librarianTorCustomRedirects = r.librarianTorCustomRedirects; - resolve(); - } - ) - }) -} -init(); -browser.storage.onChanged.addListener(init) - -function all() { - return [ - ...redirects.librarian.normal, - ...redirects.librarian.tor, - ...librarianNormalCustomRedirects, - ...librarianTorCustomRedirects, - ]; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (lbryTargetsProtocol == 'normal') instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]; - else if (lbryTargetsProtocol == 'tor') instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]; - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function redirect(url, type, initiator) { - if (disableLbryTargets) return; - if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return; - if (!targets.includes(url.host)) return; - if (type != "main_frame") return; - - let instancesList; - if (lbryTargetsProtocol == 'normal') instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]; - if (lbryTargetsProtocol == 'tor') instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - return `${randomInstance}${url.pathname}${url.search}`; -} - -function initDefaults() { - return new Promise(resolve => { - browser.storage.local.get('cloudflareList', async r => { - librarianNormalRedirectsChecks = [...redirects.librarian.normal]; - for (const instance of r.cloudflareList) { - let i; - - i = librarianNormalRedirectsChecks.indexOf(instance); - if (i > -1) librarianNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableLbryTargets: true, - lbryTargetsRedirects: { - 'librarian': redirects.librarian - }, - - librarianNormalRedirectsChecks: librarianNormalRedirectsChecks, - librarianNormalCustomRedirects: [], - - librarianTorRedirectsChecks: [...redirects.librarian.tor], - librarianTorCustomRedirects: [], - - lbryTargetsProtocol: "normal", - }) - resolve(); - }) - }) -} - -export default { - setRedirects, - switchInstance, - redirect, - initDefaults, -}; diff --git a/src/assets/javascripts/helpers/maps.js b/src/assets/javascripts/helpers/maps.js deleted file mode 100644 index 3ab5e2b6..00000000 --- a/src/assets/javascripts/helpers/maps.js +++ /dev/null @@ -1,212 +0,0 @@ -"use strict"; - -window.browser = window.browser || window.chrome; -import utils from './utils.js' - -const targets = /^https?:\/{2}(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/; - -let redirects = { - 'osm': { - "normal": [ - "https://openstreetmap.org" - ] - }, - 'facil': { - "normal": [ - "https://facilmap.org" - ] - } -}; - - -let - disableMaps, - mapsFrontend, - facilNormalRedirectsChecks, - facilNormalCustomRedirects; - -function init() { - browser.storage.local.get( - [ - "disableMaps", - "mapsFrontend", - "facilNormalRedirectsChecks", - "facilNormalCustomRedirects", - ], - r => { - disableMaps = r.disableMaps; - mapsFrontend = r.mapsFrontend; - facilNormalRedirectsChecks = r.facilNormalRedirectsChecks; - facilNormalCustomRedirects = r.facilNormalCustomRedirects; - } - ) -} - -init(); -browser.storage.onChanged.addListener(init) - -function redirect(url, initiator) { - const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; - const dataLatLngRegex = /!3d(-?[0-9]{1,}.[0-9]{1,})!4d(-?[0-9]{1,}.[0-9]{1,})/; - const placeRegex = /\/place\/(.*)\//; - const travelModes = { - driving: "fossgis_osrm_car", - walking: "fossgis_osrm_foot", - bicycling: "fossgis_osrm_bike", - transit: "fossgis_osrm_car", // not implemented on OSM, default to car. - }; - const travelModesFacil = { - driving: "car", - walking: "pedestrian", - bicycling: "bicycle", - transit: "car", // not implemented on Facil, default to car. - }; - const osmLayers = { - none: "S", - transit: "T", - traffic: "S", // not implemented on OSM, default to standard. - bicycling: "C", - }; - - function addressToLatLng(address) { - const xmlhttp = new XMLHttpRequest(); - xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false); - xmlhttp.send(); - if (xmlhttp.status === 200) { - const json = JSON.parse(xmlhttp.responseText)[0]; - if (json) { - console.log('json', json) - return [ - `${json.lat},${json.lon}`, - `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`, - ]; - } - } - console.info("Error: Status is " + xmlhttp.status); - } - - if (disableMaps) return; - if (initiator && initiator.host === "earth.google.com") return; - if (!url.href.match(targets)) return; - - let randomInstance; - if (mapsFrontend == 'osm') randomInstance = utils.getRandomInstance(redirects.osm.normal); - if (mapsFrontend == 'facil') randomInstance = utils.getRandomInstance([...facilNormalRedirectsChecks, ...facilNormalCustomRedirects]); - - let mapCentre = "#"; - let prefs = {}; - - if (url.pathname.match(mapCentreRegex)) { // Set map centre if present - var [, lat, lon, zoom] = url.pathname.match(mapCentreRegex); - } else if (url.searchParams.has("center")) { - var [lat, lon] = url.searchParams.get("center").split(","); - var zoom = url.searchParams.get("zoom") ?? "17"; - } - - if (lat && lon && zoom) { - if (mapsFrontend == 'osm') mapCentre = `#map=${zoom}/${lat}/${lon}`; - if (mapsFrontend == 'facil') mapCentre = `#${zoom}/${lat}/${lon}`; - } - - if (url.searchParams.get("layer")) prefs.layers = osmLayers[url.searchParams.get("layer")]; - - if (url.pathname.includes("/embed")) { // Handle Google Maps Embed API - // https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Eiffel+Tower,Paris+France - console.log("embed life"); - - let query = ""; - if (url.searchParams.has("q")) query = url.searchParams.get("q"); - else if (url.searchParams.has("query")) query = url.searchParams.has("query"); - - else if (url.searchParams.has("pb")) - try { query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1]; } - catch (error) { console.error(error); } // Unable to find map marker in URL. - - let [coords, boundingbox] = addressToLatLng(query); - prefs.bbox = boundingbox; - prefs.marker = coords; - prefs.layer = "mapnik"; - let prefsEncoded = new URLSearchParams(prefs).toString(); - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/export/embed.html?${prefsEncoded}`); return; } - - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${query}`); return; } - - } else if (url.pathname.includes("/dir")) { // Handle Google Maps Directions - // https://www.google.com/maps/dir/?api=1&origin=Space+Needle+Seattle+WA&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling - - let travMod = url.searchParams.get("travelmode"); - if (url.searchParams.has("travelmode")) prefs.engine = travelModes[travMod]; - - let orgVal = url.searchParams.get("origin"); - let destVal = url.searchParams.get("destination"); - - let org; addressToLatLng(orgVal, a => org = a); - let dest; addressToLatLng(destVal, a => dest = a); - prefs.route = `${org};${dest}`; - - let prefsEncoded = new URLSearchParams(prefs).toString(); - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/directions?${prefsEncoded}${mapCentre}`); return; } - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${orgVal}%20to%20${destVal}%20by%20${travelModesFacil[travMod]}`); return; } - - } else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { // Get marker from data attribute - // https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948 - console.log("data life"); - - let [, mlat, mlon] = url.pathname.match(dataLatLngRegex); - - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; } - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; } - - } else if (url.searchParams.has("ll")) { // Get marker from ll param - // https://maps.google.com/?ll=38.882147,-76.99017 - console.log("ll life"); - - const [mlat, mlon] = url.searchParams.get("ll").split(","); - - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; } - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; } - } else if (url.searchParams.has("viewpoint")) { // Get marker from viewpoint param. - // https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80 - console.log("viewpoint life"); - - const [mlat, mlon] = url.searchParams.get("viewpoint").split(","); - - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; } - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; } - } else { // Use query as search if present. - console.log("normal life"); - - let query; - if (url.searchParams.has("q")) query = url.searchParams.get("q"); - else if (url.searchParams.has("query")) query = url.searchParams.get("query"); - else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1]; - - let prefsEncoded = new URLSearchParams(prefs).toString(); - if (query) { - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query="${query}${mapCentre}&${prefsEncoded}`); return; } - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk/${query}`); return; } - } - } - - let prefsEncoded = new URLSearchParams(prefs).toString(); - console.log("mapCentre", mapCentre); - console.log("prefs", prefs); - console.log("prefsEncoded", prefsEncoded); - if (mapsFrontend == 'osm') { resolve(`${randomInstance}/${mapCentre}&${prefsEncoded}`); return; } - if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk`); return; } -} - -async function initDefaults() { - await browser.storage.local.set({ - disableMaps: false, - mapsFrontend: 'osm', - mapsRedirects: redirects, - facilNormalRedirectsChecks: [...redirects.facil.normal], - facilNormalCustomRedirects: [], - }) -} - -export default { - redirect, - initDefaults, -}; diff --git a/src/assets/javascripts/helpers/medium.js b/src/assets/javascripts/helpers/medium.js deleted file mode 100644 index 7be6b0d1..00000000 --- a/src/assets/javascripts/helpers/medium.js +++ /dev/null @@ -1,174 +0,0 @@ -window.browser = window.browser || window.chrome; -import utils from './utils.js' - - -const targets = [ - // /(?:.*\.)*(? { - redirects.scribe = val; - scribeNormalRedirectsChecks = [...redirects.scribe.normal]; - for (const instance of r.cloudflareList) { - const a = scribeNormalRedirectsChecks.indexOf(instance); - if (a > -1) scribeNormalRedirectsChecks.splice(a, 1); - } - browser.storage.local.set({ - mediumRedirects: redirects, - scribeNormalRedirectsChecks - }) - }) -} - -let - disableMedium, - mediumRedirects, - scribeNormalRedirectsChecks, - scribeNormalCustomRedirects, - scribeTorRedirectsChecks, - scribeTorCustomRedirects, - mediumProtocol; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "disableMedium", - "mediumRedirects", - "scribeNormalRedirectsChecks", - "scribeNormalCustomRedirects", - "scribeTorRedirectsChecks", - "scribeTorCustomRedirects", - "mediumProtocol" - ], - r => { - disableMedium = r.disableMedium; - mediumRedirects = r.mediumRedirects; - scribeNormalRedirectsChecks = r.scribeNormalRedirectsChecks; - scribeNormalCustomRedirects = r.scribeNormalCustomRedirects; - scribeTorRedirectsChecks = r.scribeTorRedirectsChecks; - scribeTorCustomRedirects = r.scribeTorCustomRedirects; - mediumProtocol = r.mediumProtocol; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function redirect(url, type, initiator) { - if (disableMedium) return; - if (type != "main_frame" && "sub_frame" && "xmlhttprequest" && "other") return; - if (initiator && ( - [ - ...mediumRedirects.scribe.normal, - ...mediumRedirects.scribe.tor, - ...scribeNormalCustomRedirects, - ...scribeTorCustomRedirects, - ].includes(initiator.origin))) return; - - if (!targets.some(rx => rx.test(url.host))) return; - if (/^\/($|@[a-zA-Z.]{0,}(\/|)$)/.test(url.pathname)) return; - - let instancesList; - if (mediumProtocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects]; - else if (mediumProtocol == 'tor') instancesList = [...scribeTorRedirectsChecks, ...scribeTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList) - return `${randomInstance}${url.pathname}${url.search}`; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(url); - const all = [ - ...mediumRedirects.scribe.tor, - ...mediumRedirects.scribe.normal, - - ...scribeNormalCustomRedirects, - ...scribeTorCustomRedirects, - ]; - if (!all.includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (mediumProtocol == 'normal') instancesList = [...scribeNormalCustomRedirects, ...scribeNormalRedirectsChecks]; - else if (mediumProtocol == 'tor') instancesList = [...scribeTorCustomRedirects, ...scribeTorRedirectsChecks]; - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(data => { - let dataJson = JSON.parse(data); - redirects.scribe = dataJson.scribe; - browser.storage.local.get('cloudflareList', - async r => { - scribeNormalRedirectsChecks = [...redirects.scribe.normal]; - for (const instance of r.cloudflareList) { - let i = scribeNormalRedirectsChecks.indexOf(instance); - if (i > -1) scribeNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableMedium: false, - mediumRedirects: redirects, - - scribeNormalRedirectsChecks: scribeNormalRedirectsChecks, - scribeNormalCustomRedirects: [], - - scribeTorRedirectsChecks: [...redirects.scribe.tor], - scribeTorCustomRedirects: [], - - mediumProtocol: "normal", - }) - resolve(); - }) - }) - }) -} - -export default { - setRedirects, - redirect, - switchInstance, - initDefaults, -}; diff --git a/src/assets/javascripts/helpers/peertube.js b/src/assets/javascripts/helpers/peertube.js deleted file mode 100644 index ed15bce9..00000000 --- a/src/assets/javascripts/helpers/peertube.js +++ /dev/null @@ -1,155 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -let redirects = { - "simpleertube": { - "normal": [ - "https://tube.simple-web.org", - "https://tube.ftild3.org", - "https://stube.alefvanoon.xyz", - "https://st.phreedom.club", - "https://simpleertube.esmailelbob.xyz", - ], - "tor": [] - } -} -function setRedirects(val) { - redirects.simpleertube = val; - browser.storage.local.set({ peertubeTargetsRedirects: redirects }) - for (const item of simpleertubeNormalRedirectsChecks) - if (!redirects.simpleertube.normal.includes(item)) { - var index = simpleertubeNormalRedirectsChecks.indexOf(item); - if (index !== -1) simpleertubeNormalRedirectsChecks.splice(index, 1); - } - browser.storage.local.set({ simpleertubeNormalRedirectsChecks }) - - for (const item of simpleertubeTorRedirectsChecks) - if (!redirects.simpleertube.normal.includes(item)) { - var index = simpleertubeTorRedirectsChecks.indexOf(item); - if (index !== -1) simpleertubeTorRedirectsChecks.splice(index, 1); - } - browser.storage.local.set({ simpleertubeTorRedirectsChecks }) -} - -let - disablePeertubeTargets, - peertubeRedirects, - simpleertubeNormalRedirectsChecks, - simpleertubeNormalCustomRedirects, - simpleertubeTorRedirectsChecks, - simpleertubeTorCustomRedirects, - peerTubeTargets, - peertubeTargetsProtocol; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "disablePeertubeTargets", - "peertubeRedirects", - "simpleertubeNormalRedirectsChecks", - "simpleertubeNormalCustomRedirects", - "simpleertubeTorRedirectsChecks", - "simpleertubeTorCustomRedirects", - "peerTubeTargets", - "peertubeTargetsProtocol" - ], - r => { - disablePeertubeTargets = r.disablePeertubeTargets; - peertubeRedirects = r.peertubeRedirects; - simpleertubeNormalRedirectsChecks = r.simpleertubeNormalRedirectsChecks; - simpleertubeNormalCustomRedirects = r.simpleertubeNormalCustomRedirects; - simpleertubeTorRedirectsChecks = r.simpleertubeTorRedirectsChecks; - simpleertubeTorCustomRedirects = r.simpleertubeTorCustomRedirects; - peerTubeTargets = r.peerTubeTargets; - peertubeTargetsProtocol = r.peertubeTargetsProtocol; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function all() { - return [ - ...redirects.simpleertube.normal, - ...redirects.simpleertube.tor, - ...simpleertubeNormalCustomRedirects, - ...simpleertubeTorCustomRedirects, - ]; -} - -function redirect(url, type, initiator) { - if (disablePeertubeTargets) return; - if (initiator && (all().includes(initiator.origin) || peerTubeTargets.includes(initiator.host))) return; - let protocolHost = utils.protocolHost(url); - if (!peerTubeTargets.includes(protocolHost)) return; - if (type != "main_frame") return; - - let instancesList; - if (peertubeTargetsProtocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects]; - if (peertubeTargetsProtocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - if (url.host == 'search.joinpeertube.org' || url.host == 'sepiasearch.org') return randomInstance; - return `${randomInstance}/${url.host}${url.pathname}${url.search}`; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (peertubeTargetsProtocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects]; - else if (peertubeTargetsProtocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects]; - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - browser.storage.local.get('cloudflareList', async r => { - simpleertubeNormalRedirectsChecks = [...redirects.simpleertube.normal]; - for (const instance of r.cloudflareList) { - let i = simpleertubeNormalRedirectsChecks.indexOf(instance); - if (i > -1) simpleertubeNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - peerTubeTargets: ['https://search.joinpeertube.org', ...dataJson.peertube], - disablePeertubeTargets: true, - peertubeRedirects: redirects, - - simpleertubeNormalRedirectsChecks: simpleertubeNormalRedirectsChecks, - simpleertubeNormalCustomRedirects: [], - - simpleertubeTorRedirectsChecks: [...redirects.simpleertube.tor], - simpleertubeTorCustomRedirects: [], - - peertubeTargetsProtocol: "normal", - }) - resolve(); - }) - }) - }) -} - -export default { - setRedirects, - switchInstance, - redirect, - initDefaults, -}; diff --git a/src/assets/javascripts/helpers/reddit.js b/src/assets/javascripts/helpers/reddit.js deleted file mode 100644 index 0735ba64..00000000 --- a/src/assets/javascripts/helpers/reddit.js +++ /dev/null @@ -1,378 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = [ - /^https?:\/{2}(www\.|old\.|np\.|new\.|amp\.|)reddit\.com/, - /^https?:\/{2}(i\.|preview\.)redd\.it/, -]; -let redirects = { - "libreddit": { - "normal": [], - "tor": [] - }, - "teddit": { - "normal": [], - "tor": [] - }, -}; -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects = val; - libredditNormalRedirectsChecks = [...redirects.libreddit.normal]; - tedditNormalRedirectsChecks = [...redirects.teddit.normal] - for (const instance of r.cloudflareList) { - const a = libredditNormalRedirectsChecks.indexOf(instance); - if (a > -1) libredditNormalRedirectsChecks.splice(a, 1); - - const b = tedditNormalRedirectsChecks.indexOf(instance); - if (b > -1) tedditNormalRedirectsChecks.splice(b, 1); - } - browser.storage.local.set({ - redditRedirects: redirects, - libredditNormalRedirectsChecks, - tedditNormalRedirectsChecks - }) - }) -} - -let - disableReddit, - redditFrontend, - redditRedirects, - redditProtocol, - libredditNormalRedirectsChecks, - libredditNormalCustomRedirects, - libredditTorRedirectsChecks, - libredditTorCustomRedirects, - tedditNormalRedirectsChecks, - tedditNormalCustomRedirects, - tedditTorRedirectsChecks, - tedditTorCustomRedirects; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "disableReddit", - "redditFrontend", - "redditRedirects", - "redditProtocol", - "libredditNormalRedirectsChecks", - "libredditNormalCustomRedirects", - "libredditTorRedirectsChecks", - "libredditTorCustomRedirects", - "tedditNormalRedirectsChecks", - "tedditNormalCustomRedirects", - "tedditTorRedirectsChecks", - "tedditTorCustomRedirects", - ], - r => { - disableReddit = r.disableReddit; - redditFrontend = r.redditFrontend; - redditRedirects = r.redditRedirects; - redditProtocol = r.redditProtocol; - libredditNormalRedirectsChecks = r.libredditNormalRedirectsChecks; - libredditNormalCustomRedirects = r.libredditNormalCustomRedirects; - libredditTorRedirectsChecks = r.libredditTorRedirectsChecks; - libredditTorCustomRedirects = r.libredditTorCustomRedirects; - tedditNormalRedirectsChecks = r.tedditNormalRedirectsChecks; - tedditNormalCustomRedirects = r.tedditNormalCustomRedirects; - tedditTorRedirectsChecks = r.tedditTorRedirectsChecks; - tedditTorCustomRedirects = r.tedditTorCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function initLibredditCookies(test, from) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(from); - if (![ - ...libredditNormalRedirectsChecks, - ...libredditTorRedirectsChecks, - ...libredditNormalCustomRedirects, - ...libredditTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - if (!test) { - let checkedInstances; - if (redditProtocol == 'normal') checkedInstances = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]; - else if (redditProtocol == 'tor') checkedInstances = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]; - for (const to of checkedInstances) { - utils.copyCookie('libreddit', from, to, "theme"); - utils.copyCookie('libreddit', from, to, "front_page"); - utils.copyCookie('libreddit', from, to, "layout"); - utils.copyCookie('libreddit', from, to, "wide"); - utils.copyCookie('libreddit', from, to, "post_sort"); - utils.copyCookie('libreddit', from, to, "comment_sort"); - utils.copyCookie('libreddit', from, to, "show_nsfw"); - utils.copyCookie('libreddit', from, to, "autoplay_videos"); - utils.copyCookie('libreddit', from, to, "use_hls"); - utils.copyCookie('libreddit', from, to, "hide_hls_notification"); - } - } - resolve(true); - }) -} - -function setLibredditCookies() { - return new Promise(async resolve => { - await init(); - if (disableReddit || redditFrontend != 'libreddit' || redditProtocol === undefined) { resolve(); return; } - let checkedInstances; - if (redditProtocol == 'normal') checkedInstances = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects] - else if (redditProtocol == 'tor') checkedInstances = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('libreddit', to, "theme"); - utils.getCookiesFromStorage('libreddit', to, "front_page"); - utils.getCookiesFromStorage('libreddit', to, "layout"); - utils.getCookiesFromStorage('libreddit', to, "wide"); - utils.getCookiesFromStorage('libreddit', to, "post_sort"); - utils.getCookiesFromStorage('libreddit', to, "comment_sort"); - utils.getCookiesFromStorage('libreddit', to, "show_nsfw"); - utils.getCookiesFromStorage('libreddit', to, "autoplay_videos"); - utils.getCookiesFromStorage('libreddit', to, "use_hls"); - utils.getCookiesFromStorage('libreddit', to, "hide_hls_notification"); - } - resolve(); - }) -} - -function initTedditCookies(test, from) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(from); - if (![ - ...tedditNormalRedirectsChecks, - ...tedditTorRedirectsChecks, - ...tedditNormalCustomRedirects, - ...tedditTorCustomRedirects, - ].includes(protocolHost)) resolve(); - - if (!test) { - let checkedInstances; - if (redditProtocol == 'normal') checkedInstances = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects] - else if (redditProtocol == 'tor') checkedInstances = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects] - for (const to of checkedInstances) { - utils.copyCookie('teddit', from, to, 'collapse_child_comments') - utils.copyCookie('teddit', from, to, 'domain_instagram') - utils.copyCookie('teddit', from, to, 'domain_twitter') - utils.copyCookie('teddit', from, to, 'domain_youtube') - utils.copyCookie('teddit', from, to, 'flairs') - utils.copyCookie('teddit', from, to, 'highlight_controversial') - utils.copyCookie('teddit', from, to, 'nsfw_enabled') - utils.copyCookie('teddit', from, to, 'post_media_max_height') - utils.copyCookie('teddit', from, to, 'show_upvoted_percentage') - utils.copyCookie('teddit', from, to, 'show_upvotes') - utils.copyCookie('teddit', from, to, 'theme') - utils.copyCookie('teddit', from, to, 'videos_muted') - } - } - resolve(true); - }) -} - -function setTedditCookies() { - return new Promise(async resolve => { - await init(); - if (disableReddit || redditFrontend != 'teddit' || redditProtocol === undefined) { resolve(); return; } - let checkedInstances; - if (redditProtocol == 'normal') checkedInstances = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects] - else if (redditProtocol == 'tor') checkedInstances = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('teddit', to, 'collapse_child_comments') - utils.getCookiesFromStorage('teddit', to, 'domain_instagram') - utils.getCookiesFromStorage('teddit', to, 'domain_twitter') - utils.getCookiesFromStorage('teddit', to, 'domain_youtube') - utils.getCookiesFromStorage('teddit', to, 'flairs') - utils.getCookiesFromStorage('teddit', to, 'highlight_controversial') - utils.getCookiesFromStorage('teddit', to, 'nsfw_enabled') - utils.getCookiesFromStorage('teddit', to, 'post_media_max_height') - utils.getCookiesFromStorage('teddit', to, 'show_upvoted_percentage') - utils.getCookiesFromStorage('teddit', to, 'show_upvotes') - utils.getCookiesFromStorage('teddit', to, 'theme') - utils.getCookiesFromStorage('teddit', to, 'videos_muted') - } - resolve(); - }) -} - -function all() { - return [ - ...redditRedirects.libreddit.normal, - ...redditRedirects.libreddit.tor, - ...redditRedirects.teddit.normal, - ...redditRedirects.teddit.tor, - ...libredditNormalCustomRedirects, - ...libredditTorCustomRedirects, - ...tedditNormalCustomRedirects, - ...tedditTorCustomRedirects, - ]; -} - -// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4 -// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png - -// https://teddit.net/vids/1mq8d0ma3yk81.mp4 -// https://teddit.net/pics/w:null_4v3t1vgvrzk81.png - - -// redd.it/t5379n -// https://v.redd.it/z08avb339n801/DASH_1_2_M -// https://i.redd.it/bfkhs659tzk81.jpg -function redirect(url, type, initiator) { - if (disableReddit) return; - if (!targets.some(rx => rx.test(url.href))) return; - if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; - const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/; - if (type !== "main_frame" || url.pathname.match(bypassPaths)) return; - - let libredditInstancesList; - let tedditInstancesList; - if (redditProtocol == 'normal') { - libredditInstancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]; - tedditInstancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects]; - } else if (redditProtocol == 'tor') { - libredditInstancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]; - tedditInstancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects]; - } - - if (url.host === "i.redd.it") { - if (redditFrontend == 'teddit') { - if (tedditInstancesList.length === 0) return; - let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList); - return `${tedditRandomInstance}/pics/w:null_${url.pathname.substring(1)}${url.reddit}`; - } - if (redditFrontend == 'libreddit') { - if (libredditInstancesList.length === 0) return; - let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList); - return `${libredditRandomInstance}/img${url.pathname}${url.reddit}` - } - } - else if (url.host === "redd.it") { - if (redditFrontend == 'libreddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) { - if (libredditInstancesList.length === 0) return; - let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList); - // https://redd.it/foo => https://libredd.it/comments/foo - return `${libredditRandomInstance}/comments${url.pathname}${url.reddit}`; - } - if (redditFrontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) { - if (tedditInstancesList.length === 0) return; - let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList); - // https://redd.it/foo => https://teddit.net/comments/foo - return `${tedditRandomInstance}/comments${url.pathname}${url.reddit}` - } - } - else if (url.host === 'preview.redd.it') { - if (redditFrontend == 'teddit') return; - if (redditFrontend == 'libreddit') { - if (libredditInstancesList.length === 0) return; - const libredditRandomInstance = utils.getRandomInstance(libredditInstancesList); - return `${libredditRandomInstance}/preview/pre${url.pathname}${url.reddit}`; - } - } - - let randomInstance; - if (redditFrontend == 'libreddit') { - if (libredditInstancesList.length === 0) return; - randomInstance = utils.getRandomInstance(libredditInstancesList); - } - if (redditFrontend == 'teddit') { - if (tedditInstancesList.length === 0) return; - randomInstance = utils.getRandomInstance(tedditInstancesList); - } - return `${randomInstance}${url.pathname}${url.search}`; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - let instancesList; - if (redditFrontend == 'libreddit') { - if (redditProtocol == 'normal') instancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]; - else if (redditProtocol == 'tor') instancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]; - if ([ - ...redditRedirects.teddit.normal, - ...redditRedirects.teddit.tor - ].includes(protocolHost)) url.pathname = url.pathname.replace("/pics/w:null_", "/img/"); - } - else if (redditFrontend == 'teddit') { - if (redditProtocol == 'normal') instancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects]; - else if (redditProtocol == 'tor') instancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects]; - if ([ - ...redditRedirects.libreddit.normal, - ...redditRedirects.libreddit.tor - ].includes(protocolHost) - ) url.pathname = url.pathname.replace("/img/", "/pics/w:null_"); - } - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.reddit}`); - }) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.teddit = dataJson.teddit; - redirects.libreddit = dataJson.libreddit; - browser.storage.local.get('cloudflareList', async r => { - libredditNormalRedirectsChecks = [...redirects.libreddit.normal]; - tedditNormalRedirectsChecks = [...redirects.teddit.normal] - for (const instance of r.cloudflareList) { - let i; - - i = libredditNormalRedirectsChecks.indexOf(instance); - if (i > -1) libredditNormalRedirectsChecks.splice(i, 1); - - i = tedditNormalRedirectsChecks.indexOf(instance); - if (i > -1) tedditNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableReddit: false, - redditProtocol: 'normal', - redditFrontend: 'libreddit', - redditRedirects: redirects, - - libredditNormalRedirectsChecks: libredditNormalRedirectsChecks, - libredditNormalCustomRedirects: [], - - libredditTorRedirectsChecks: [...redirects.libreddit.tor], - libredditTorCustomRedirects: [], - - tedditNormalRedirectsChecks: tedditNormalRedirectsChecks, - tedditNormalCustomRedirects: [], - - tedditTorRedirectsChecks: [...redirects.teddit.tor], - tedditTorCustomRedirects: [], - }); - resolve(); - }); - }); - }); -} - -export default { - setRedirects, - initLibredditCookies, - setLibredditCookies, - initTedditCookies, - setTedditCookies, - - redirect, - initDefaults, - switchInstance, -}; diff --git a/src/assets/javascripts/helpers/search.js b/src/assets/javascripts/helpers/search.js deleted file mode 100644 index b32a8141..00000000 --- a/src/assets/javascripts/helpers/search.js +++ /dev/null @@ -1,470 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = [ - /^https?:\/{2}(www\.|search\.|)google(\.[a-z]{2,3}){1,2}(\/search(\?.*|$)|\/$)/, - /^https?:\/{2}(www\.|www2\.|)bing\.com/, - /^https?:\/{2}yandex(\.[a-z]{2,3}){1,2}/, - /^https?:\/{2}search\.libredirect\.invalid/, -]; - -let redirects = { - "searx": { - "normal": [], - "tor": [], - "i2p": [] - }, - "searxng": { - "normal": [], - "tor": [], - "i2p": [] - }, - "whoogle": { - "normal": [], - "tor": [], - "i2p": [] - } -}; - -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects = val; - searxNormalRedirectsChecks = [...redirects.searx.normal]; - searxngNormalRedirectsChecks = [...redirects.searxng.normal]; - whoogleNormalRedirectsChecks = [...redirects.whoogle.normal]; - for (const instance of r.cloudflareList) { - const a = searxNormalRedirectsChecks.indexOf(instance); - if (a > -1) searxNormalRedirectsChecks.splice(a, 1); - - const b = searxngNormalRedirectsChecks.indexOf(instance); - if (b > -1) searxngNormalRedirectsChecks.splice(b, 1); - - const c = whoogleNormalRedirectsChecks.indexOf(instance); - if (c > -1) whoogleNormalRedirectsChecks.splice(c, 1); - } - browser.storage.local.set({ - searchRedirects: redirects, - searxNormalRedirectsChecks, - searxngNormalRedirectsChecks, - whoogleNormalRedirectsChecks, - }); - }) -} - -let - disableSearch, - searchFrontend, - searchRedirects, - searchProtocol, - whoogleNormalRedirectsChecks, - whoogleNormalCustomRedirects, - whoogleTorRedirectsChecks, - whoogleTorCustomRedirects, - whoogleI2pRedirectsChecks, - whoogleI2pCustomRedirects, - searxNormalRedirectsChecks, - searxNormalCustomRedirects, - searxTorRedirectsChecks, - searxTorCustomRedirects, - searxI2pRedirectsChecks, - searxI2pCustomRedirects, - searxngNormalRedirectsChecks, - searxngNormalCustomRedirects, - searxngTorRedirectsChecks, - searxngTorCustomRedirects, - searxngI2pRedirectsChecks, - searxngI2pCustomRedirects; - -function init() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - "disableSearch", - "searchFrontend", - "searchRedirects", - "searchProtocol", - "whoogleNormalRedirectsChecks", - "whoogleNormalCustomRedirects", - "whoogleTorRedirectsChecks", - "whoogleTorCustomRedirects", - "whoogleI2pRedirectsChecks", - "whoogleI2pCustomRedirects", - "searxNormalRedirectsChecks", - "searxNormalCustomRedirects", - "searxTorRedirectsChecks", - "searxTorCustomRedirects", - "searxI2pRedirectsChecks", - "searxI2pCustomRedirects", - "searxngNormalRedirectsChecks", - "searxngNormalCustomRedirects", - "searxngTorRedirectsChecks", - "searxngTorCustomRedirects", - "searxngI2pRedirectsChecks", - "searxngI2pCustomRedirects", - ], - r => { - disableSearch = r.disableSearch; - searchFrontend = r.searchFrontend; - searchRedirects = r.searchRedirects; - searchProtocol = r.searchProtocol; - whoogleNormalRedirectsChecks = r.whoogleNormalRedirectsChecks; - whoogleNormalCustomRedirects = r.whoogleNormalCustomRedirects; - whoogleTorRedirectsChecks = r.whoogleTorRedirectsChecks; - whoogleTorCustomRedirects = r.whoogleTorCustomRedirects; - whoogleI2pRedirectsChecks = r.whoogleI2pRedirectsChecks; - whoogleI2pCustomRedirects = r.whoogleI2pCustomRedirects; - searxNormalRedirectsChecks = r.searxNormalRedirectsChecks; - searxNormalCustomRedirects = r.searxNormalCustomRedirects; - searxTorRedirectsChecks = r.searxTorRedirectsChecks; - searxTorCustomRedirects = r.searxTorCustomRedirects; - searxI2pRedirectsChecks = r.searxI2pRedirectsChecks; - searxI2pCustomRedirects = r.searxI2pCustomRedirects; - searxngNormalRedirectsChecks = r.searxngNormalRedirectsChecks; - searxngNormalCustomRedirects = r.searxngNormalCustomRedirects; - searxngTorRedirectsChecks = r.searxngTorRedirectsChecks; - searxngTorCustomRedirects = r.searxngTorCustomRedirects; - searxngI2pRedirectsChecks = r.searxngI2pRedirectsChecks; - searxngI2pCustomRedirects = r.searxngI2pCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function initSearxCookies(test, from) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(from); - if (![ - ...searxNormalRedirectsChecks, - ...searxNormalCustomRedirects, - ...searxTorRedirectsChecks, - ...searxTorCustomRedirects, - ...searxI2pRedirectsChecks, - ...searxI2pCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - if (!test) { - let checkedInstances; - if (searchProtocol == 'normal') checkedInstances = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; - else if (searchProtocol == 'tor') checkedInstances = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; - else if (searchProtocol == 'i2p') checkedInstances = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; - for (const to of checkedInstances) { - utils.copyCookie('searx', from, to, 'advanced_search'); - utils.copyCookie('searx', from, to, 'autocomplete'); - utils.copyCookie('searx', from, to, 'categories'); - utils.copyCookie('searx', from, to, 'disabled_engines'); - utils.copyCookie('searx', from, to, 'disabled_plugins'); - utils.copyCookie('searx', from, to, 'doi_resolver'); - utils.copyCookie('searx', from, to, 'enabled_engines'); - utils.copyCookie('searx', from, to, 'enabled_plugins'); - utils.copyCookie('searx', from, to, 'image_proxy'); - utils.copyCookie('searx', from, to, 'language'); - utils.copyCookie('searx', from, to, 'locale'); - utils.copyCookie('searx', from, to, 'method'); - utils.copyCookie('searx', from, to, 'oscar-style'); - utils.copyCookie('searx', from, to, 'results_on_new_tab'); - utils.copyCookie('searx', from, to, 'safesearch'); - utils.copyCookie('searx', from, to, 'theme'); - utils.copyCookie('searx', from, to, 'tokens'); - } - } - resolve(true); - }) -} - -function setSearxCookies() { - return new Promise(async resolve => { - await init(); - if (disableSearch || searchFrontend != 'searx') { resolve(); return; } - let checkedInstances; - if (searchProtocol == 'normal') checkedInstances = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects] - else if (searchProtocol == 'tor') checkedInstances = [...searxTorRedirectsChecks, ...searxTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('searx', to, 'advanced_search'); - utils.getCookiesFromStorage('searx', to, 'autocomplete'); - utils.getCookiesFromStorage('searx', to, 'categories'); - utils.getCookiesFromStorage('searx', to, 'disabled_engines'); - utils.getCookiesFromStorage('searx', to, 'disabled_plugins'); - utils.getCookiesFromStorage('searx', to, 'doi_resolver'); - utils.getCookiesFromStorage('searx', to, 'enabled_engines'); - utils.getCookiesFromStorage('searx', to, 'enabled_plugins'); - utils.getCookiesFromStorage('searx', to, 'image_proxy'); - utils.getCookiesFromStorage('searx', to, 'language'); - utils.getCookiesFromStorage('searx', to, 'locale'); - utils.getCookiesFromStorage('searx', to, 'method'); - utils.getCookiesFromStorage('searx', to, 'oscar-style'); - utils.getCookiesFromStorage('searx', to, 'results_on_new_tab'); - utils.getCookiesFromStorage('searx', to, 'safesearch'); - utils.getCookiesFromStorage('searx', to, 'theme'); - utils.getCookiesFromStorage('searx', to, 'tokens'); - } - resolve(); - }) -} - -function initSearxngCookies(test, from) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(from); - if (![ - ...searxngNormalRedirectsChecks, - ...searxngNormalCustomRedirects, - ...searxngTorRedirectsChecks, - ...searxngTorCustomRedirects, - ...searxngI2pRedirectsChecks, - ...searxngI2pCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - if (!test) { - let checkedInstances; - if (searchProtocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; - else if (searchProtocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; - else if (searchProtocol == 'i2p') checkedInstances = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; - for (const to of checkedInstances) { - utils.copyCookie('searxng', from, to, 'autocomplete'); - utils.copyCookie('searxng', from, to, 'categories'); - utils.copyCookie('searxng', from, to, 'disabled_engines'); - utils.copyCookie('searxng', from, to, 'disabled_plugins'); - utils.copyCookie('searxng', from, to, 'doi_resolver'); - utils.copyCookie('searxng', from, to, 'enabled_plugins'); - utils.copyCookie('searxng', from, to, 'enabled_engines'); - utils.copyCookie('searxng', from, to, 'image_proxy'); - utils.copyCookie('searxng', from, to, 'infinite_scroll'); - utils.copyCookie('searxng', from, to, 'language'); - utils.copyCookie('searxng', from, to, 'locale'); - utils.copyCookie('searxng', from, to, 'maintab'); - utils.copyCookie('searxng', from, to, 'method'); - utils.copyCookie('searxng', from, to, 'query_in_title'); - utils.copyCookie('searxng', from, to, 'results_on_new_tab'); - utils.copyCookie('searxng', from, to, 'safesearch'); - utils.copyCookie('searxng', from, to, 'simple_style'); - utils.copyCookie('searxng', from, to, 'theme'); - utils.copyCookie('searxng', from, to, 'tokens'); - } - } - resolve(true); - }) -} - -function setSearxngCookies() { - return new Promise(async resolve => { - await init(); - if (disableSearch || searchFrontend != 'searxng', searchProtocol === undefined) { resolve(); return; } - let checkedInstances; - if (searchProtocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects] - else if (searchProtocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('searxng', to, 'autocomplete'); - utils.getCookiesFromStorage('searxng', to, 'categories'); - utils.getCookiesFromStorage('searxng', to, 'disabled_engines'); - utils.getCookiesFromStorage('searxng', to, 'disabled_plugins'); - utils.getCookiesFromStorage('searxng', to, 'doi_resolver'); - utils.getCookiesFromStorage('searxng', to, 'enabled_plugins'); - utils.getCookiesFromStorage('searxng', to, 'enabled_engines'); - utils.getCookiesFromStorage('searxng', to, 'image_proxy'); - utils.getCookiesFromStorage('searxng', to, 'infinite_scroll'); - utils.getCookiesFromStorage('searxng', to, 'language'); - utils.getCookiesFromStorage('searxng', to, 'locale'); - utils.getCookiesFromStorage('searxng', to, 'maintab'); - utils.getCookiesFromStorage('searxng', to, 'method'); - utils.getCookiesFromStorage('searxng', to, 'query_in_title'); - utils.getCookiesFromStorage('searxng', to, 'results_on_new_tab'); - utils.getCookiesFromStorage('searxng', to, 'safesearch'); - utils.getCookiesFromStorage('searxng', to, 'simple_style'); - utils.getCookiesFromStorage('searxng', to, 'theme'); - utils.getCookiesFromStorage('searxng', to, 'tokens'); - } - resolve(); - }) -} - - -function redirect(url) { - if (disableSearch) return; - if (!targets.some(rx => rx.test(url.href))) return; - if (url.searchParams.has('tbm')) return; - if (url.hostname.includes('google') && !url.searchParams.has('q') && url.pathname != '/') return; - let randomInstance; - let path; - if (searchFrontend == 'searx') { - let instancesList; - if (searchProtocol == 'normal') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; - else if (searchProtocol == 'tor') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; - else if (searchProtocol == 'i2p') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; - if (instancesList.length === 0) return; - randomInstance = utils.getRandomInstance(instancesList) - path = "/"; - } - else if (searchFrontend == 'searxng') { - let instancesList; - if (searchProtocol == 'normal') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; - else if (searchProtocol == 'tor') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; - else if (searchProtocol == 'i2p') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; - if (instancesList.length === 0) return; - randomInstance = utils.getRandomInstance(instancesList) - path = "/"; - } - else if (searchFrontend == 'whoogle') { - let instancesList; - if (searchProtocol == 'normal') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects]; - if (searchProtocol == 'tor') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]; - if (searchProtocol == 'i2p') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects]; - if (instancesList.length === 0) return; - randomInstance = utils.getRandomInstance(instancesList) - path = "/search"; - } - - if ( - ((url.hostname.includes('google') || url.hostname.includes('bing')) && !url.searchParams.has('q')) || - (url.hostname.includes('yandex') && !url.searchParams.has('text')) - ) path = '/'; - - let searchQuery = ""; - if ( - ( - url.hostname.includes('google') || - url.hostname.includes('bing') || - url.hostname.includes('search.libredirect.invalid') - ) && - url.searchParams.has('q') - ) searchQuery = `?q=${url.searchParams.get('q')}`; - if (url.hostname.includes('yandex') && url.searchParams.has('text')) searchQuery = `?q=${url.searchParams.get('text')}`; - - return `${randomInstance}${path}${searchQuery}`; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(url); - if (![ - ...searchRedirects.searx.normal, - ...searchRedirects.searx.tor, - ...searchRedirects.searx.i2p, - - ...searchRedirects.searxng.normal, - ...searchRedirects.searxng.tor, - ...searchRedirects.searxng.i2p, - - ...searchRedirects.whoogle.normal, - ...searchRedirects.whoogle.tor, - ...searchRedirects.whoogle.i2p, - - ...searxNormalCustomRedirects, - ...searxTorCustomRedirects, - ...searxI2pCustomRedirects, - - ...searxngNormalCustomRedirects, - ...searxngTorCustomRedirects, - ...searxngI2pCustomRedirects, - - ...whoogleNormalCustomRedirects, - ...whoogleTorCustomRedirects, - ...whoogleI2pCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (searchProtocol == 'normal') { - if (searchFrontend == 'searx') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; - else if (searchFrontend == 'searxng') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; - else if (searchFrontend == 'whoogle') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects]; - } - else if (searchProtocol == 'tor') { - if (searchFrontend == 'searx') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; - else if (searchFrontend == 'searxng') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; - else if (searchFrontend == 'whoogle') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]; - } - else if (searchProtocol == 'i2p') { - if (searchFrontend == 'searx') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; - else if (searchFrontend == 'searxng') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; - else if (searchFrontend == 'whoogle') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects]; - } - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(async resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.searx = dataJson.searx; - redirects.searxng = dataJson.searxng; - redirects.whoogle = dataJson.whoogle; - - browser.storage.local.get('cloudflareList', async r => { - whoogleNormalRedirectsChecks = [...redirects.whoogle.normal]; - searxNormalRedirectsChecks = [...redirects.searx.normal]; - searxngNormalRedirectsChecks = [...redirects.searxng.normal]; - for (const instance of r.cloudflareList) { - let i; - - i = whoogleNormalRedirectsChecks.indexOf(instance); - if (i > -1) whoogleNormalRedirectsChecks.splice(i, 1); - - i = searxNormalRedirectsChecks.indexOf(instance); - if (i > -1) searxNormalRedirectsChecks.splice(i, 1); - - i = searxngNormalRedirectsChecks.indexOf(instance); - if (i > -1) searxngNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableSearch: false, - searchFrontend: 'searxng', - searchRedirects: redirects, - searxngCustomSettings: false, - searchProtocol: 'normal', - - whoogleNormalRedirectsChecks: whoogleNormalRedirectsChecks, - whoogleNormalCustomRedirects: [], - - whoogleTorRedirectsChecks: [...redirects.whoogle.tor], - whoogleTorCustomRedirects: [], - - whoogleI2pRedirectsChecks: [...redirects.whoogle.i2p], - whoogleI2pCustomRedirects: [], - - searxNormalRedirectsChecks: searxNormalRedirectsChecks, - searxNormalCustomRedirects: [], - - searxTorRedirectsChecks: [...redirects.searx.tor], - searxTorCustomRedirects: [], - - searxI2pRedirectsChecks: [...redirects.searx.i2p], - searxI2pCustomRedirects: [], - - searxngNormalRedirectsChecks: searxngNormalRedirectsChecks, - searxngNormalCustomRedirects: [], - - searxngTorRedirectsChecks: [...redirects.searxng.tor], - searxngTorCustomRedirects: [], - - searxngI2pRedirectsChecks: [...redirects.searxng.i2p], - searxngI2pCustomRedirects: [], - }) - resolve(); - }) - }) - }) -} - -export default { - setRedirects, - initSearxCookies, - setSearxCookies, - initSearxngCookies, - setSearxngCookies, - redirect, - initDefaults, - switchInstance, -}; diff --git a/src/assets/javascripts/helpers/sendTargets.js b/src/assets/javascripts/helpers/sendTargets.js deleted file mode 100644 index a3e87268..00000000 --- a/src/assets/javascripts/helpers/sendTargets.js +++ /dev/null @@ -1,149 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = [ - /^https?:\/{2}send\.libredirect\.invalid\/$/, - /^ https ?: \/\/send\.firefox\.com\/$/, - /^https?:\/{2}sendfiles\.online\/$/ -]; - -let redirects = { - "send": { - "normal": [], - "tor": [] - } -} -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects.send = val; - sendNormalRedirectsChecks = [...redirects.send.normal]; - for (const instance of r.cloudflareList) { - const a = sendNormalRedirectsChecks.indexOf(instance); - if (a > -1) sendNormalRedirectsChecks.splice(a, 1); - } - browser.storage.local.set({ - sendTargetsRedirects: redirects, - sendNormalRedirectsChecks, - }) - }) -} - -let - disableSendTarget, - sendTargetsRedirects, - sendNormalRedirectsChecks, - sendNormalCustomRedirects, - sendTorRedirectsChecks, - sendTorCustomRedirects, - sendTargetsProtocol; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "disableSendTarget", - "sendTargetsRedirects", - "sendTargetsProtocol", - "sendNormalRedirectsChecks", - "sendNormalCustomRedirects", - "sendTorRedirectsChecks", - "sendTorCustomRedirects", - ], - r => { - disableSendTarget = r.disableSendTarget; - sendTargetsRedirects = r.sendTargetsRedirects; - sendNormalRedirectsChecks = r.sendNormalRedirectsChecks; - sendNormalCustomRedirects = r.sendNormalCustomRedirects; - sendTorRedirectsChecks = r.sendTorRedirectsChecks; - sendTorCustomRedirects = r.sendTorCustomRedirects; - sendTargetsProtocol = r.sendTargetsProtocol; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function all() { - return [ - ...sendTargetsRedirects.send.normal, - ...sendTargetsRedirects.send.tor, - ...sendNormalCustomRedirects, - ...sendTorRedirectsChecks, - ...sendTorCustomRedirects, - ]; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - if (url.pathname != '/') { resolve(); return; } - - let instancesList; - if (sendTargetsProtocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects]; - else if (sendTargetsProtocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects]; - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function redirect(url, type, initiator) { - if (disableSendTarget) return; - if (type != "main_frame") return; - if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return; - if (!targets.some(rx => rx.test(url.href))) return; - - let instancesList; - if (sendTargetsProtocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects]; - if (sendTargetsProtocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - return randomInstance; -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.send = dataJson.send; - browser.storage.local.get('cloudflareList', async r => { - sendNormalRedirectsChecks = [...redirects.send.normal]; - for (const instance of r.cloudflareList) { - let i = sendNormalRedirectsChecks.indexOf(instance); - if (i > -1) sendNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableSendTarget: false, - sendTargetsRedirects: redirects, - - sendNormalRedirectsChecks: sendNormalRedirectsChecks, - sendNormalCustomRedirects: [], - - sendTorRedirectsChecks: [...redirects.send.tor], - sendTorCustomRedirects: [], - - sendTargetsProtocol: "normal", - }) - resolve(); - }) - }) - }) -} - -export default { - setRedirects, - redirect, - switchInstance, - initDefaults, -}; diff --git a/src/assets/javascripts/helpers/tiktok.js b/src/assets/javascripts/helpers/tiktok.js deleted file mode 100644 index 750744e6..00000000 --- a/src/assets/javascripts/helpers/tiktok.js +++ /dev/null @@ -1,175 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = [ - /^https?:\/{2}(www\.|)tiktok\.com.*/ -]; - -let redirects = { - "proxiTok": { - "normal": [], - "tor": [] - } -} -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects.proxiTok = val; - proxiTokNormalRedirectsChecks = [...redirects.proxiTok.normal]; - for (const instance of r.cloudflareList) { - const a = proxiTokNormalRedirectsChecks.indexOf(instance); - if (a > -1) proxiTokNormalRedirectsChecks.splice(a, 1); - } - browser.storage.local.set({ - tiktokRedirects: redirects, - proxiTokNormalRedirectsChecks - }) - }) -} - -function initProxiTokCookies(test, from) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(from); - if (![ - ...proxiTokNormalRedirectsChecks, - ...proxiTokNormalCustomRedirects, - ...proxiTokTorRedirectsChecks, - ...proxiTokTorCustomRedirects, - ].includes(protocolHost)) resolve(); - - if (!test) { - let checkedInstances; - if (tiktokProtocol == 'normal') checkedInstances = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects] - else if (tiktokProtocol == 'tor') checkedInstances = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects] - for (const to of checkedInstances) { - utils.copyCookie('proxitok', from, to, 'theme'); - utils.copyCookie('proxitok', from, to, 'api-legacy'); - } - } - resolve(true); - }) -} - -function setProxiTokCookies() { - return new Promise(resolve => { - if (disableTiktok || tiktokProtocol === undefined) { resolve(); return; } - let checkedInstances; - if (tiktokProtocol == 'normal') checkedInstances = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects] - else if (tiktokProtocol == 'tor') checkedInstances = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('proxitok', to, 'theme'); - utils.getCookiesFromStorage('proxitok', to, 'api-legacy'); - } - resolve(); - }) -} - -let - disableTiktok, - tiktokProtocol, - tiktokRedirects, - proxiTokNormalRedirectsChecks, - proxiTokNormalCustomRedirects, - proxiTokTorRedirectsChecks, - proxiTokTorCustomRedirects; - -function init() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - "disableTiktok", - "tiktokProtocol", - "tiktokRedirects", - "proxiTokNormalRedirectsChecks", - "proxiTokNormalCustomRedirects", - "proxiTokTorRedirectsChecks", - "proxiTokTorCustomRedirects", - ], - r => { - disableTiktok = r.disableTiktok; - tiktokProtocol = r.tiktokProtocol; - tiktokRedirects = r.tiktokRedirects; - proxiTokNormalRedirectsChecks = r.proxiTokNormalRedirectsChecks; - proxiTokNormalCustomRedirects = r.proxiTokNormalCustomRedirects; - proxiTokTorRedirectsChecks = r.proxiTokTorRedirectsChecks; - proxiTokTorCustomRedirects = r.proxiTokTorCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -// https://www.tiktok.com/@keysikaspol/video/7061265241887345946 -// https://www.tiktok.com/@keysikaspol -function redirect(url, type, initiator) { - if (disableTiktok) return; - if (type != "main_frame") return; - const all = [ - ...tiktokRedirects.proxiTok.normal, - ...proxiTokNormalCustomRedirects - ]; - if (initiator && (all.includes(initiator.origin) || targets.includes(initiator.host))) return; - if (!targets.some(rx => rx.test(url.href))) return; - - let instancesList; - if (tiktokProtocol == 'normal') instancesList = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects]; - if (tiktokProtocol == 'tor') instancesList = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - return `${randomInstance}${url.pathname}`; -} - -function reverse(url) { - return new Promise(async resolve => { - await init(); - let protocolHost = utils.protocolHost(url); - const all = [ - ...tiktokRedirects.proxiTok.normal, - ...tiktokRedirects.proxiTok.tor, - ...proxiTokNormalCustomRedirects, - ...proxiTokTorCustomRedirects - ]; - if (!all.includes(protocolHost)) { resolve(); return; } - - resolve(`https://tiktok.com${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(async resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.proxiTok = dataJson.proxiTok; - await browser.storage.local.set({ - disableTiktok: false, - tiktokProtocol: "normal", - - tiktokRedirects: redirects, - - proxiTokNormalRedirectsChecks: [...redirects.proxiTok.normal], - proxiTokNormalCustomRedirects: [], - - proxiTokTorRedirectsChecks: [...redirects.proxiTok.tor], - proxiTokTorCustomRedirects: [], - }); - resolve(); - }); - }) -} - -export default { - setRedirects, - - redirect, - reverse, - - initProxiTokCookies, - setProxiTokCookies, - - initDefaults -}; diff --git a/src/assets/javascripts/helpers/translate/get_lingva_preferences.js b/src/assets/javascripts/helpers/translate/get_lingva_preferences.js deleted file mode 100644 index f04ea3dc..00000000 --- a/src/assets/javascripts/helpers/translate/get_lingva_preferences.js +++ /dev/null @@ -1,10 +0,0 @@ -window.browser = window.browser || window.chrome; - -browser.storage.local.set( - { - ['lingva_lingva_chakra-ui-color-mode']: localStorage.getItem('chakra-ui-color-mode'), - lingva_lingva_isauto: localStorage.getItem('isauto'), - lingva_lingva_source: localStorage.getItem('source'), - lingva_lingva_target: localStorage.getItem('target'), - } -) diff --git a/src/assets/javascripts/helpers/translate/set_lingva_preferences.js b/src/assets/javascripts/helpers/translate/set_lingva_preferences.js deleted file mode 100644 index 01a3b85e..00000000 --- a/src/assets/javascripts/helpers/translate/set_lingva_preferences.js +++ /dev/null @@ -1,19 +0,0 @@ -window.browser = window.browser || window.chrome; - -browser.storage.local.get( - [ - "lingva_chakra-ui-color-mode", - "lingva_isauto", - "lingva_source", - "lingva_target", - ], - r => { - if (r['lingva_chakra-ui-color-mode'] !== undefined) localStorage.setItem('chakra-ui-color-mode', r['lingva_chakra-ui-color-mode']); - if (r.lingva_isauto !== undefined) localStorage.setItem('isauto', r.lingva_isauto); - console.log('r.lingva_isauto', r.lingva_isauto, localStorage.getItem('isauto')) - if (r.lingva_source !== undefined) localStorage.setItem('source', r.lingva_source); - if (r.lingva_target !== undefined) localStorage.setItem('target', r.lingva_target); - - window.close(); - } -) diff --git a/src/assets/javascripts/helpers/translate/translate.js b/src/assets/javascripts/helpers/translate/translate.js deleted file mode 100644 index 74400040..00000000 --- a/src/assets/javascripts/helpers/translate/translate.js +++ /dev/null @@ -1,295 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from '../utils.js' - -const targets = [ - /^https?:\/{2}translate\.google(\.[a-z]{2,3}){1,2}\//, -]; - -let redirects = { - "simplyTranslate": { - "normal": [], - "tor": [] - }, - "lingva": { - "normal": [], - "tor": [] - } -}; - -let - translateDisable, - translateFrontend, - translateProtocol, - translateRedirects, - simplyTranslateNormalRedirectsChecks, - simplyTranslateNormalCustomRedirects, - simplyTranslateTorRedirectsChecks, - simplyTranslateTorCustomRedirects, - lingvaNormalRedirectsChecks, - lingvaNormalCustomRedirects, - lingvaTorRedirectsChecks, - lingvaTorCustomRedirects; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "translateDisable", - "translateFrontend", - "translateProtocol", - "translateRedirects", - - "simplyTranslateNormalRedirectsChecks", - "simplyTranslateNormalCustomRedirects", - "simplyTranslateTorRedirectsChecks", - "simplyTranslateTorCustomRedirects", - - "lingvaNormalRedirectsChecks", - "lingvaNormalCustomRedirects", - "lingvaTorRedirectsChecks", - "lingvaTorCustomRedirects", - ], - r => { - translateDisable = r.translateDisable; - translateFrontend = r.translateFrontend; - translateProtocol = r.translateProtocol; - translateRedirects = r.translateRedirects; - simplyTranslateNormalRedirectsChecks = r.simplyTranslateNormalRedirectsChecks; - simplyTranslateNormalCustomRedirects = r.simplyTranslateNormalCustomRedirects; - simplyTranslateTorRedirectsChecks = r.simplyTranslateTorRedirectsChecks; - simplyTranslateTorCustomRedirects = r.simplyTranslateTorCustomRedirects; - lingvaNormalRedirectsChecks = r.lingvaNormalRedirectsChecks; - lingvaNormalCustomRedirects = r.lingvaNormalCustomRedirects; - lingvaTorRedirectsChecks = r.lingvaTorRedirectsChecks; - lingvaTorCustomRedirects = r.lingvaTorCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects = val; - simplyTranslateNormalRedirectsChecks = [...redirects.simplyTranslate.normal]; - lingvaNormalRedirectsChecks = [...redirects.lingva.normal] - for (const instance of r.cloudflareList) { - const a = simplyTranslateNormalRedirectsChecks.indexOf(instance); - if (a > -1) simplyTranslateNormalRedirectsChecks.splice(a, 1); - - const b = lingvaNormalRedirectsChecks.indexOf(instance); - if (b > -1) lingvaNormalRedirectsChecks.splice(b, 1); - } - browser.storage.local.set({ - translateRedirects: redirects, - simplyTranslateNormalRedirectsChecks, - simplyTranslateTorRedirectsChecks: redirects.simplyTranslate.tor, - lingvaNormalRedirectsChecks, - lingvaTorRedirectsChecks: redirects.lingva.tor, - }) - }) -} - -function initLingvaLocalStorage(test, url, tabId) { - return new Promise(async resolve => { - await init(); - if (translateDisable || translateFrontend != 'lingva') { resolve(); return; } - const protocolHost = utils.protocolHost(url); - if (![ - ...lingvaNormalRedirectsChecks, - ...lingvaNormalCustomRedirects, - ...lingvaTorRedirectsChecks, - ...lingvaTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - if (!test) { - browser.tabs.executeScript( - tabId, - { file: "/assets/javascripts/helpers/translate/get_lingva_preferences.js", runAt: "document_start" } - ); - - let checkedInstances; - if (translateProtocol == 'normal') checkedInstances = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]; - if (translateProtocol == 'tor') checkedInstances = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]; - const i = checkedInstances.indexOf(protocolHost); - if (i !== -1) checkedInstances.splice(i, 1); - if (checkedInstances.length === 0) { resolve(); return; } - for (const to of checkedInstances) - browser.tabs.create( - { url: to }, - tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/translate/set_lingva_preferences.js", runAt: "document_start" }) - ); - } - resolve(true); - } - ) -} - -function initSimplyTranslateCookies(test, from) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(from); - if (![ - ...simplyTranslateNormalRedirectsChecks, - ...simplyTranslateNormalCustomRedirects, - ...simplyTranslateTorRedirectsChecks, - ...simplyTranslateTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - if (!test) { - let checkedInstances; - if (translateProtocol == 'normal') checkedInstances = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects] - else if (translateProtocol == 'tor') checkedInstances = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects] - for (const to of checkedInstances) { - utils.copyCookie('simplyTranslate', from, to, 'from_lang'); - utils.copyCookie('simplyTranslate', from, to, 'to_lang'); - utils.copyCookie('simplyTranslate', from, to, 'tts_enabled'); - utils.copyCookie('simplyTranslate', from, to, 'use_text_fields'); - } - } - resolve(true); - } - ) -} - -function setSimplyTranslateCookies() { - return new Promise(async resolve => { - await init(); - if (translateDisable || translateFrontend != 'simplyTranslate') { resolve(); return; } - let checkedInstances; - if (translateProtocol == 'normal') checkedInstances = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects] - else if (translateProtocol == 'tor') checkedInstances = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('simplyTranslate', to, 'from_lang'); - utils.getCookiesFromStorage('simplyTranslate', to, 'to_lang'); - utils.getCookiesFromStorage('simplyTranslate', to, 'tts_enabled'); - utils.getCookiesFromStorage('simplyTranslate', to, 'use_text_fields'); - } - resolve(); - } - ) -} - -function redirect(url) { - if (translateDisable) return; - if (!targets.some(rx => rx.test(url.href))) return; - - if (translateFrontend == 'simplyTranslate') { - let instancesList; - if (translateProtocol == 'normal') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]; - if (translateProtocol == 'tor') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList) - return `${randomInstance}/${url.search}`; - } - else if (translateFrontend == 'lingva') { - let params_arr = url.search.split('&'); - params_arr[0] = params_arr[0].substring(1); - let params = {}; - for (let i = 0; i < params_arr.length; i++) { - let pair = params_arr[i].split('='); - params[pair[0]] = pair[1]; - } - let instancesList; - if (translateProtocol == 'normal') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]; - if (translateProtocol == 'tor') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList) - if (params.sl && params.tl && params.text) { - return `${randomInstance}/${params.sl}/${params.tl}/${params.text}` - } - return randomInstance; - } -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - if (translateDisable) { resolve(); return; } - const protocolHost = utils.protocolHost(url); - if (![ - ...translateRedirects.simplyTranslate.normal, - ...translateRedirects.simplyTranslate.tor, - - ...simplyTranslateNormalCustomRedirects, - ...simplyTranslateTorCustomRedirects, - - ...translateRedirects.lingva.normal, - ...translateRedirects.lingva.tor, - - ...lingvaNormalCustomRedirects, - ...lingvaTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (translateProtocol == 'normal') { - if (translateFrontend == 'simplyTranslate') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]; - else if (translateFrontend == 'lingva') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]; - } - else if (translateProtocol == 'tor') { - if (translateFrontend == 'simplyTranslate') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]; - else if (translateFrontend == 'lingva') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]; - } - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(async resolve => { - fetch('/instances/data.json').then(response => response.text()).then(data => { - let dataJson = JSON.parse(data); - redirects.simplyTranslate = dataJson.simplyTranslate; - redirects.lingva = dataJson.lingva; - browser.storage.local.get('cloudflareList', - async r => { - simplyTranslateNormalRedirectsChecks = [...redirects.simplyTranslate.normal]; - lingvaNormalRedirectsChecks = [...redirects.lingva.normal] - for (const instance of r.cloudflareList) { - const a = simplyTranslateNormalRedirectsChecks.indexOf(instance); - if (a > -1) simplyTranslateNormalRedirectsChecks.splice(a, 1); - - const b = lingvaNormalRedirectsChecks.indexOf(instance); - if (b > -1) lingvaNormalRedirectsChecks.splice(b, 1); - } - await browser.storage.local.set({ - translateDisable: false, - translateFrontend: "simplyTranslate", - translateProtocol: 'normal', - translateRedirects: redirects, - - simplyTranslateNormalRedirectsChecks: simplyTranslateNormalRedirectsChecks, - simplyTranslateNormalCustomRedirects: [], - simplyTranslateTorRedirectsChecks: [...redirects.simplyTranslate.tor], - simplyTranslateTorCustomRedirects: [], - - lingvaNormalRedirectsChecks: lingvaNormalRedirectsChecks, - lingvaNormalCustomRedirects: [], - lingvaTorRedirectsChecks: [...redirects.lingva.tor], - lingvaTorCustomRedirects: [], - }) - resolve(); - }) - }) - }) -} - -export default { - initSimplyTranslateCookies, - setSimplyTranslateCookies, - initLingvaLocalStorage, - setRedirects, - redirect, - initDefaults, - switchInstance, -}; diff --git a/src/assets/javascripts/helpers/twitter.js b/src/assets/javascripts/helpers/twitter.js deleted file mode 100644 index dc48f9b1..00000000 --- a/src/assets/javascripts/helpers/twitter.js +++ /dev/null @@ -1,241 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = [ - /^https?:\/{2}(www\.|mobile\.|)twitter\.com/, - /^https?:\/{2}(pbs\.|video\.|)twimg\.com/, - /^https?:\/{2}platform\.twitter\.com\/embed/, - /^https?:\/{2}t\.co/ -]; - -let redirects = { - "nitter": { - "normal": [], - "tor": [] - }, -}; - -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects.nitter = val; - nitterNormalRedirectsChecks = [...redirects.nitter.normal]; - for (const instance of r.cloudflareList) { - let i = nitterNormalRedirectsChecks.indexOf(instance); - if (i > -1) nitterNormalRedirectsChecks.splice(i, 1); - } - browser.storage.local.set({ - twitterRedirects: redirects, - nitterNormalRedirectsChecks, - nitterTorRedirectsChecks: [...redirects.nitter.tor] - }) - }) -} - -let - disableTwitter, - twitterProtocol, - twitterRedirects, - nitterNormalRedirectsChecks, - nitterNormalCustomRedirects, - nitterTorRedirectsChecks, - nitterTorCustomRedirects; - -function init() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - "disableTwitter", - "twitterProtocol", - "twitterRedirects", - "nitterNormalRedirectsChecks", - "nitterNormalCustomRedirects", - "nitterTorRedirectsChecks", - "nitterTorCustomRedirects", - ], - r => { - disableTwitter = r.disableTwitter; - twitterProtocol = r.twitterProtocol; - twitterRedirects = r.twitterRedirects; - nitterNormalRedirectsChecks = r.nitterNormalRedirectsChecks; - nitterNormalCustomRedirects = r.nitterNormalCustomRedirects; - nitterTorRedirectsChecks = r.nitterTorRedirectsChecks; - nitterTorCustomRedirects = r.nitterTorCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function all() { - return [ - ...nitterNormalRedirectsChecks, - ...nitterTorRedirectsChecks, - ...nitterNormalCustomRedirects, - ...nitterTorCustomRedirects, - ]; -} - -function redirect(url, initiator) { - if (disableTwitter) return; - if (!targets.some(rx => rx.test(url.href))) return; - if (url.pathname.split("/").includes("home")) return; - if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; - - let instancesList; - if (twitterProtocol == 'normal') instancesList = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects]; - else if (twitterProtocol == 'tor') instancesList = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - // https://pbs.twimg.com/profile_images/648888480974508032/66_cUYfj_400x400.jpg - if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") - return `${randomInstance}/pic/${encodeURIComponent(`${url.host}${url.pathname}`)}`; - else if (url.pathname.split("/").includes("tweets")) - return `${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}`; - else if (url.host == 't.co') - return `${randomInstance}/t.co${url.pathname}`; - else - return `${randomInstance}${url.pathname}${url.search}`; -} - -function reverse(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve; return; } - resolve(`https://twitter.com${url.pathname}${url.search}`); - }) -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost)) { resolve(); return; } - let instancesList; - if (twitterProtocol == 'normal') instancesList = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects]; - else if (twitterProtocol == 'tor') instancesList = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]; - - let index = instancesList.indexOf(protocolHost); - if (index > -1) instancesList.splice(index, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function removeXFrameOptions(e) { - let url = new URL(e.url); - let protocolHost = utils.protocolHost(url); - if (!all().includes(protocolHost) || e.type != 'sub_frame') return; - let isChanged = false; - for (const i in e.responseHeaders) if (e.responseHeaders[i].name == 'x-frame-options') { - e.responseHeaders.splice(i, 1); - isChanged = true; - } - if (isChanged) return { responseHeaders: e.responseHeaders }; -} - -function initNitterCookies(test, from) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(from); - if (!all().includes(protocolHost) - ) { resolve(); return; } - - if (!test) { - let checkedInstances; - if (twitterProtocol == 'normal') checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects] - else if (twitterProtocol == 'tor') checkedInstances = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects] - for (const to of checkedInstances) { - utils.copyCookie('nitter', from, to, 'theme'); - utils.copyCookie('nitter', from, to, 'infiniteScroll'); - utils.copyCookie('nitter', from, to, 'stickyProfile'); - utils.copyCookie('nitter', from, to, 'bidiSupport'); - utils.copyCookie('nitter', from, to, 'hideTweetStats'); - utils.copyCookie('nitter', from, to, 'hideBanner'); - utils.copyCookie('nitter', from, to, 'hidePins'); - utils.copyCookie('nitter', from, to, 'hideReplies'); - utils.copyCookie('nitter', from, to, 'squareAvatars'); - utils.copyCookie('nitter', from, to, 'mp4Playback'); - utils.copyCookie('nitter', from, to, 'hlsPlayback'); - utils.copyCookie('nitter', from, to, 'proxyVideos'); - utils.copyCookie('nitter', from, to, 'muteVideos'); - utils.copyCookie('nitter', from, to, 'autoplayGifs'); - } - } - resolve(true); - }) -} - -function setNitterCookies() { - return new Promise(async resolve => { - await init(); - if (disableTwitter || twitterProtocol === undefined) { resolve(); return; } - let checkedInstances; - if (twitterProtocol == 'normal') checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects] - else if (twitterProtocol == 'tor') checkedInstances = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('nitter', to, 'theme'); - utils.getCookiesFromStorage('nitter', to, 'infiniteScroll'); - utils.getCookiesFromStorage('nitter', to, 'stickyProfile'); - utils.getCookiesFromStorage('nitter', to, 'bidiSupport'); - utils.getCookiesFromStorage('nitter', to, 'hideTweetStats'); - utils.getCookiesFromStorage('nitter', to, 'hideBanner'); - utils.getCookiesFromStorage('nitter', to, 'hidePins'); - utils.getCookiesFromStorage('nitter', to, 'hideReplies'); - utils.getCookiesFromStorage('nitter', to, 'squareAvatars'); - utils.getCookiesFromStorage('nitter', to, 'mp4Playback'); - utils.getCookiesFromStorage('nitter', to, 'hlsPlayback'); - utils.getCookiesFromStorage('nitter', to, 'proxyVideos'); - utils.getCookiesFromStorage('nitter', to, 'muteVideos'); - utils.getCookiesFromStorage('nitter', to, 'autoplayGifs'); - } - resolve(); - } - ) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(data => { - let dataJson = JSON.parse(data); - redirects.nitter = dataJson.nitter; - browser.storage.local.get('cloudflareList', async r => { - nitterNormalRedirectsChecks = [...redirects.nitter.normal]; - for (const instance of r.cloudflareList) { - let i = nitterNormalRedirectsChecks.indexOf(instance); - if (i > -1) nitterNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableTwitter: false, - twitterRedirects: redirects, - twitterProtocol: "normal", - - nitterNormalRedirectsChecks, - nitterNormalCustomRedirects: [], - - nitterTorRedirectsChecks: [...redirects.nitter.tor], - nitterTorCustomRedirects: [], - }) - resolve(); - }) - }) - }) -} - -export default { - setRedirects, - redirect, - switchInstance, - reverse, - removeXFrameOptions, - initNitterCookies, - setNitterCookies, - initDefaults, -}; diff --git a/src/assets/javascripts/helpers/utils.js b/src/assets/javascripts/helpers/utils.js deleted file mode 100644 index 16fdaae7..00000000 --- a/src/assets/javascripts/helpers/utils.js +++ /dev/null @@ -1,456 +0,0 @@ -window.browser = window.browser || window.chrome; -import twitterHelper from "./twitter.js"; -import youtubeHelper from "./youtube/youtube.js"; -import instagramHelper from "./instagram.js"; -import mediumHelper from "./medium.js"; -import redditHelper from "./reddit.js"; -import searchHelper from "./search.js"; -import translateHelper from "./translate/translate.js"; -import wikipediaHelper from "./wikipedia.js"; -import peertubeHelper from "./peertube.js"; -import lbryHelper from "./lbry.js"; -import sendTargetsHelper from "./sendTargets.js"; -import tiktokHelper from "./tiktok.js"; -import imgurHelper from "./imgur.js"; -import localise from '../localise.js' - -function getRandomInstance(instances) { - return instances[~~(instances.length * Math.random())]; -} - -let cloudflareList = []; -async function initCloudflareList() { - return new Promise(resolve => { - fetch('/instances/blocklist.json').then(response => response.text()).then(data => { - cloudflareList = JSON.parse(data); - resolve(); - }) - }); -} - -function updateInstances() { - return new Promise(async resolve => { - let http = new XMLHttpRequest(); - http.open('GET', 'https://raw.githubusercontent.com/libredirect/libredirect/master/src/instances/data.json', false); - http.send(null); - if (http.status === 200) { - await initCloudflareList(); - const instances = JSON.parse(http.responseText); - - youtubeHelper.setRedirects({ 'invidious': instances.invidious, 'piped': instances.piped, }) - twitterHelper.setRedirects(instances.nitter); - instagramHelper.setRedirects(instances.bibliogram); - redditHelper.setRedirects({ 'libreddit': instances.libreddit, 'teddit': instances.teddit }); - translateHelper.setRedirects({ "simplyTranslate": instances.simplyTranslate, "lingva": instances.lingva }); - searchHelper.setRedirects({ 'searx': instances.searx, 'searxng': instances.searxng, 'whoogle': instances.whoogle }); - wikipediaHelper.setRedirects(instances.wikiless); - mediumHelper.setRedirects(instances.scribe); - sendTargetsHelper.setRedirects(instances.send); - tiktokHelper.setRedirects(instances.proxiTok); - - console.info("Successfully updated Instances"); - resolve(true); return; - } - resolve() - }) -} - -function protocolHost(url) { - if (url.username && url.password) return `${url.protocol}//${url.username}:${url.password}@${url.host}`; - return `${url.protocol}//${url.host}`; -} - -async function processDefaultCustomInstances(target, name, protocol, document) { - - function camelCase(str) { - return str.charAt(0).toUpperCase() + str.slice(1); - } - let latencyKey = `${name}Latency`; - let instancesLatency; - await browser.storage.local.get(latencyKey, r => instancesLatency = r[latencyKey] ?? []); - let nameProtocolElement = document.getElementById(name).getElementsByClassName(protocol)[0]; - - let nameCustomInstances = []; - let nameCheckListElement = nameProtocolElement.getElementsByClassName('checklist')[0]; - - await initCloudflareList(); - - - let nameDefaultRedirects; - - let redirectsChecks = `${name}${camelCase(protocol)}RedirectsChecks`; - let customRedirects = `${name}${camelCase(protocol)}CustomRedirects`; - let redirectsKey = `${target}Redirects`; - - let redirects; - - async function getFromStorage() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - redirectsChecks, - customRedirects, - redirectsKey - ], - r => { - nameDefaultRedirects = r[redirectsChecks]; - nameCustomInstances = r[customRedirects]; - redirects = r[redirectsKey]; - resolve(); - } - ) - }) - } - await getFromStorage(); - - function calcNameCheckBoxes() { - let isTrue = true; - for (const item of redirects[name][protocol]) - if (!nameDefaultRedirects.includes(item)) { - isTrue = false; - break; - } - for (const element of nameCheckListElement.getElementsByTagName('input')) - element.checked = nameDefaultRedirects.includes(element.className) - if (nameDefaultRedirects.length == 0) isTrue = false; - nameProtocolElement.getElementsByClassName('toogle-all')[0].checked = isTrue; - } - nameCheckListElement.innerHTML = - [ - `
- Toggle All - -
`, - ...redirects[name][protocol].map( - x => { - let cloudflare = cloudflareList.includes(x) ? ' cloudflare' : ''; - - let ms = instancesLatency[x]; - let latencyColor = (ms <= 1000 ? "green" : ms <= 2000 ? "orange" : "red"); - let latencyLimit; - if (ms == 5000) latencyLimit = '5000ms+'; - else if (ms > 5000) latencyLimit = `ERROR: ${ms - 5000}`; - else latencyLimit = ms + 'ms'; - - let latency = x in instancesLatency ? '' + latencyLimit + '' : ''; - - return `
- ${x}${cloudflare} ${latency} - -
`; - } - ), - ].join('\n
\n'); - - localise.localisePage(); - - calcNameCheckBoxes(); - nameProtocolElement.getElementsByClassName('toogle-all')[0].addEventListener("change", async event => { - if (event.target.checked) - nameDefaultRedirects = [...redirects[name][protocol]]; - else - nameDefaultRedirects = []; - - await browser.storage.local.set({ [redirectsChecks]: nameDefaultRedirects }); - calcNameCheckBoxes(); - }); - - for (let element of nameCheckListElement.getElementsByTagName('input')) { - if (element.className != 'toogle-all') - nameProtocolElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { - if (event.target.checked) - nameDefaultRedirects.push(element.className) - else { - let index = nameDefaultRedirects.indexOf(element.className); - if (index > -1) nameDefaultRedirects.splice(index, 1); - } - await browser.storage.local.set({ [redirectsChecks]: nameDefaultRedirects }); - calcNameCheckBoxes(); - }); - } - - function calcNameCustomInstances() { - nameProtocolElement.getElementsByClassName('custom-checklist')[0].innerHTML = - nameCustomInstances.map( - x => `
- ${x} - -
-
` - ).join('\n'); - - for (const item of nameCustomInstances) { - nameProtocolElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { - let index = nameCustomInstances.indexOf(item); - if (index > -1) nameCustomInstances.splice(index, 1); - await browser.storage.local.set({ [customRedirects]: nameCustomInstances }); - calcNameCustomInstances(); - }); - } - } - calcNameCustomInstances(); - nameProtocolElement.getElementsByClassName('custom-instance-form')[0].addEventListener("submit", async event => { - event.preventDefault(); - let nameCustomInstanceInput = nameProtocolElement.getElementsByClassName('custom-instance')[0]; - let url = new URL(nameCustomInstanceInput.value); - let protocolHostVar = protocolHost(url); - if (nameCustomInstanceInput.validity.valid && !redirects[name][protocol].includes(protocolHostVar)) { - if (!nameCustomInstances.includes(protocolHostVar)) { - nameCustomInstances.push(protocolHostVar) - await browser.storage.local.set({ [customRedirects]: nameCustomInstances }); - nameCustomInstanceInput.value = ''; - } - calcNameCustomInstances(); - } - }) -} - -function isRtl() { - return ["ar", "iw", "ku", "fa", "ur"].includes(browser.i18n.getUILanguage()) -} - -function getIp(href) { - return new Promise(resolve => { - let host = new URL(href).hostname; - let http = new XMLHttpRequest(); - http.open("GET", `https://dns.google/resolve?name=${host}`, /*async*/true); - http.onreadystatechange = () => { - if (http.readyState == 4 && http.status == 200) { - let r = JSON.parse(http.responseText); - resolve(r.Answer[0].data) - } - }; - http.ontimeout = () => resolve() - http.onerror = () => resolve() - try { - http.send(null) - } - catch (exception) { - resolve() - } - }) -} - -async function ping(href) { - return new Promise(async resolve => { - let http = new XMLHttpRequest(); - http.open("GET", `${href}?_=${new Date().getTime()}`, /*async*/true); - http.timeout = 5000; - let started = new Date().getTime(); - http.onreadystatechange = () => { - if (http.readyState == 2) { - if (http.status == 200) { - let ended = new Date().getTime(); - http.abort(); - resolve(ended - started); - } - else - resolve(5000 + http.status) - } - }; - http.ontimeout = () => resolve(5000) - http.onerror = () => resolve() - try { - http.send(null); - } catch (exception) { - resolve() - } - }); -} - -async function testLatency(element, instances) { - return new Promise(async resolve => { - let myList = {}; - for (const href of instances) await ping(href).then(m => { - if (m) { - myList[href] = m; - let color; - if (m <= 1000) color = "green" - else if (m <= 2000) color = "orange" - else color = "red"; - - let text; - if (m == 5000) text = '5000ms+' - else if (m > 5000) text = `ERROR: ${m - 5000}`; - else text = `${m}ms`; - element.innerHTML = `${href}: ${text}`; - } - }) - resolve(myList); - }) -} - -function copyCookie(frontend, targetUrl, url, name) { - browser.cookies.get( - { url: protocolHost(targetUrl), name: name }, - r => { - if (r) { - browser.cookies.set({ url: url, name: name, value: r.value }) - browser.storage.local.set({ [`${frontend}_${name}`]: r.value }) - } - } - ) -} - -function getCookiesFromStorage(frontend, to, name) { - let key = `${frontend}_${name}`; - browser.storage.local.get( - key, - r => { - if (r[key] !== undefined) browser.cookies.set({ url: to, name: name, value: r[key] }) - } - ) -} - -function copyRaw(test, copyRawElement) { - return new Promise(resolve => { - browser.tabs.query( - { active: true, currentWindow: true }, async tabs => { - let currTab = tabs[0]; - if (currTab) { - let url; - try { url = new URL(currTab.url); } - catch { resolve(); return; } - let newUrl = await youtubeHelper.reverse(url); - if (!newUrl) newUrl = await twitterHelper.reverse(url); - if (!newUrl) newUrl = await instagramHelper.reverse(url); - if (!newUrl) newUrl = await tiktokHelper.reverse(url); - if (!newUrl) newUrl = await imgurHelper.reverse(url); - - if (newUrl) { - resolve(true); - if (test) return; - navigator.clipboard.writeText(newUrl); - if (copyRawElement) { - const textElement = copyRawElement.getElementsByTagName('h4')[0] - const oldHtml = textElement.innerHTML; - textElement.innerHTML = 'Copied'; - setTimeout(() => textElement.innerHTML = oldHtml, 1000); - } - } else resolve() - } - } - ) - }) -} - -function unify(test) { - return new Promise(resolve => { - browser.tabs.query( - { active: true, currentWindow: true }, - async tabs => { - let currTab = tabs[0] - if (currTab) { - let url; - try { url = new URL(currTab.url); } - catch { resolve(); return; } - - let result = await youtubeHelper.initInvidiousCookies(test, url); - if (!result) result = await youtubeHelper.initPipedLocalStorage(test, url, currTab.id); - if (!result) result = await youtubeHelper.initPipedMaterialLocalStorage(test, url, currTab.id); - - if (!result) result = await twitterHelper.initNitterCookies(test, url); - - if (!result) result = await redditHelper.initLibredditCookies(test, url); - if (!result) result = await redditHelper.initTedditCookies(test, url); - - if (!result) result = await searchHelper.initSearxCookies(test, url); - if (!result) result = await searchHelper.initSearxngCookies(test, url); - - if (!result) result = await tiktokHelper.initProxiTokCookies(test, url); - - if (!result) result = await wikipediaHelper.initWikilessCookies(test, url); - - if (!result) result = await translateHelper.initSimplyTranslateCookies(test, url); - if (!result) result = await translateHelper.initLingvaLocalStorage(test, url); - - if (result) { - resolve(true); - } else resolve() - } - } - ) - }) -} - -function switchInstance(test) { - return new Promise(resolve => { - browser.tabs.query({ active: true, currentWindow: true }, async tabs => { - let currTab = tabs[0]; - if (currTab) { - let url; - try { url = new URL(currTab.url); } - catch { resolve(); return }; - let newUrl = await youtubeHelper.switchInstance(url); - if (!newUrl) newUrl = await twitterHelper.switchInstance(url); - if (!newUrl) newUrl = await instagramHelper.switchInstance(url); - if (!newUrl) newUrl = await redditHelper.switchInstance(url); - if (!newUrl) newUrl = await searchHelper.switchInstance(url); - if (!newUrl) newUrl = await translateHelper.switchInstance(url); - if (!newUrl) newUrl = await mediumHelper.switchInstance(url); - if (!newUrl) newUrl = await sendTargetsHelper.switchInstance(url); - if (!newUrl) newUrl = await peertubeHelper.switchInstance(url); - if (!newUrl) newUrl = await lbryHelper.switchInstance(url); - if (!newUrl) newUrl = await imgurHelper.switchInstance(url); - if (!newUrl) newUrl = await wikipediaHelper.switchInstance(url); - - if (newUrl) { - if (!test) - browser.tabs.update({ url: newUrl }); - resolve(true) - } else resolve() - } - }) - }) -} - -function latency(name, frontend, document, location, splitNames) { - let latencyElement; - let latencyLabel; - if (splitNames == true) { - latencyElement = document.getElementById(`latency-${frontend}`); - latencyLabel = document.getElementById(`latency-${frontend}-label`); - } else { - latencyElement = document.getElementById("latency"); - latencyLabel = document.getElementById("latency-label"); - } - latencyElement.addEventListener("click", - async () => { - let reloadWindow = () => location.reload(); - latencyElement.addEventListener("click", reloadWindow); - let key = `${name}Redirects` - browser.storage.local.get( - key, - r => { - let redirects = r[key]; - const oldHtml = latencyLabel.innerHTML; - latencyLabel.innerHTML = '...'; - testLatency(latencyLabel, redirects[frontend].normal).then(r => { - browser.storage.local.set({ [`${frontend}Latency`]: r }); - latencyLabel.innerHTML = oldHtml; - processDefaultCustomInstances(name, frontend, 'normal', document); - latencyElement.removeEventListener("click", reloadWindow) - }); - } - ) - } - ); -} - -export default { - getRandomInstance, - updateInstances, - protocolHost, - processDefaultCustomInstances, - isRtl, - latency, - copyCookie, - getCookiesFromStorage, - switchInstance, - copyRaw, - unify, -} diff --git a/src/assets/javascripts/helpers/wikipedia.js b/src/assets/javascripts/helpers/wikipedia.js deleted file mode 100644 index 868bb01c..00000000 --- a/src/assets/javascripts/helpers/wikipedia.js +++ /dev/null @@ -1,220 +0,0 @@ -window.browser = window.browser || window.chrome; - -import utils from './utils.js' - -const targets = /^https?:\/{2}(([a-z]{1,}\.){0,})wikipedia\.org/ - -let redirects = { - "wikiless": { - "normal": [], - "tor": [], - "i2p": [] - } -}; -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects.wikiless = val; - wikilessNormalRedirectsChecks = [...redirects.wikiless.normal]; - for (const instance of r.cloudflareList) { - const a = wikilessNormalRedirectsChecks.indexOf(instance); - if (a > -1) wikilessNormalRedirectsChecks.splice(a, 1); - } - browser.storage.local.set({ - wikipediaRedirects: redirects, - wikilessNormalRedirectsChecks - }) - }) -} - -let - disableWikipedia, - wikipediaRedirects, - wikipediaProtocol, - wikilessNormalRedirectsChecks, - wikilessTorRedirectsChecks, - wikilessI2pRedirectsChecks, - wikilessNormalCustomRedirects, - wikilessTorCustomRedirects, - wikilessI2pCustomRedirects; - -function init() { - return new Promise(async resolve => { - browser.storage.local.get( - [ - "disableWikipedia", - "wikipediaRedirects", - "wikipediaProtocol", - - "wikilessNormalRedirectsChecks", - "wikilessTorRedirectsChecks", - "wikilessI2pRedirectsChecks", - "wikilessNormalCustomRedirects", - "wikilessTorCustomRedirects", - "wikilessI2pCustomRedirects", - ], - r => { - disableWikipedia = r.disableWikipedia; - wikipediaRedirects = r.wikipediaRedirects; - wikipediaProtocol = r.wikipediaProtocol; - wikilessNormalRedirectsChecks = r.wikilessNormalRedirectsChecks; - wikilessTorRedirectsChecks = r.wikilessTorRedirectsChecks; - wikilessI2pRedirectsChecks = r.wikilessI2pRedirectsChecks; - wikilessNormalCustomRedirects = r.wikilessNormalCustomRedirects; - wikilessTorCustomRedirects = r.wikilessTorCustomRedirects; - wikilessI2pCustomRedirects = r.wikilessI2pCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function initWikilessCookies(test, from) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(from); - const all = [ - ...wikilessNormalRedirectsChecks, - ...wikilessNormalCustomRedirects, - ...wikilessTorRedirectsChecks, - ...wikilessTorCustomRedirects, - ...wikilessI2pRedirectsChecks, - ...wikilessI2pCustomRedirects, - ]; - if (!all.includes(protocolHost)) { resolve(); return; } - - if (!test) { - let checkedInstances; - if (wikipediaProtocol == 'normal') checkedInstances = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects] - else if (wikipediaProtocol == 'tor') checkedInstances = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects] - else if (wikipediaProtocol == 'i2p') checkedInstances = [...wikilessI2pRedirectsChecks, ...wikilessI2pCustomRedirects] - - for (const to of checkedInstances) { - utils.copyCookie('wikiless', from, to, 'theme'); - utils.copyCookie('wikiless', from, to, 'default_lang'); - } - } - resolve(true); - }) -} - -function setWikilessCookies() { - return new Promise(async resolve => { - await init(); - if (disableWikipedia || wikipediaProtocol === undefined) { resolve(); return; } - let checkedInstances; - if (wikipediaProtocol == 'normal') checkedInstances = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects] - else if (wikipediaProtocol == 'tor') checkedInstances = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects] - for (const to of checkedInstances) { - utils.getCookiesFromStorage('wikiless', to, 'theme'); - utils.getCookiesFromStorage('wikiless', to, 'default_lang'); - } - resolve(); - }) -} - -function redirect(url) { - if (disableWikipedia) return; - if (!targets.test(url.href)) return; - - let GETArguments = []; - if (url.search.length > 0) { - let search = url.search.substring(1); //get rid of '?' - let argstrings = search.split("&"); - for (let i = 0; i < argstrings.length; i++) { - let args = argstrings[i].split("="); - GETArguments.push([args[0], args[1]]); - } - } - let instancesList; - if (wikipediaProtocol == 'normal') instancesList = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects]; - else if (wikipediaProtocol == 'tor') instancesList = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects]; - else if (wikipediaProtocol == 'i2p') instancesList = [...wikilessI2pRedirectsChecks, ...wikilessI2pCustomRedirects]; - if (instancesList.length === 0) return; - const randomInstance = utils.getRandomInstance(instancesList) - - let link = `${randomInstance}${url.pathname}`; - let urlSplit = url.host.split("."); - if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") { - if (urlSplit[0] == "m") - GETArguments.push(["mobileaction", "toggle_view_mobile"]); - else - GETArguments.push(["lang", urlSplit[0]]); - if (urlSplit[1] == "m") - GETArguments.push(["mobileaction", "toggle_view_mobile"]); - // wikiless doesn't have mobile view support yet - } - for (let i = 0; i < GETArguments.length; i++) - link += (i == 0 ? "?" : "&") + GETArguments[i][0] + "=" + GETArguments[i][1]; - return link; -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - const wikipediaList = [ - ...wikipediaRedirects.wikiless.normal, - ...wikipediaRedirects.wikiless.tor, - ...wikipediaRedirects.wikiless.i2p, - - ...wikilessNormalCustomRedirects, - ...wikilessTorCustomRedirects, - ...wikilessI2pCustomRedirects - ]; - if (!wikipediaList.includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (wikipediaProtocol == 'normal') instancesList = [...wikilessNormalCustomRedirects, ...wikilessNormalRedirectsChecks]; - else if (wikipediaProtocol == 'tor') instancesList = [...wikilessTorCustomRedirects, ...wikilessTorRedirectsChecks]; - else if (wikipediaProtocol == 'i2p') instancesList = [...wikilessI2pCustomRedirects, ...wikilessI2pRedirectsChecks]; - - let index = instancesList.indexOf(protocolHost); - if (index > -1) instancesList.splice(index, 1); - if (instancesList.length === 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.wikiless = dataJson.wikiless; - browser.storage.local.get('cloudflareList', async r => { - wikilessNormalRedirectsChecks = [...redirects.wikiless.normal]; - for (const instance of r.cloudflareList) { - let i = wikilessNormalRedirectsChecks.indexOf(instance); - if (i > -1) wikilessNormalRedirectsChecks.splice(i, 1); - } - await browser.storage.local.set({ - disableWikipedia: true, - wikipediaRedirects: redirects, - wikipediaProtocol: "normal", - wikilessNormalRedirectsChecks: wikilessNormalRedirectsChecks, - wikilessTorRedirectsChecks: [...redirects.wikiless.tor], - wikilessI2pRedirectsChecks: [...redirects.wikiless.i2p], - wikilessNormalCustomRedirects: [], - wikilessTorCustomRedirects: [], - wikilessI2pCustomRedirects: [], - }) - resolve(); - }) - }) - }) -} - -export default { - setRedirects, - - initWikilessCookies, - setWikilessCookies, - - redirect, - initDefaults, - switchInstance, -}; diff --git a/src/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js b/src/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js deleted file mode 100644 index 9d052f62..00000000 --- a/src/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js +++ /dev/null @@ -1,7 +0,0 @@ -window.browser = window.browser || window.chrome; - -browser.storage.local.set( - { - 'pipedMaterial_PREFERENCES': localStorage.getItem("PREFERENCES") - } -) \ No newline at end of file diff --git a/src/assets/javascripts/helpers/youtube/get_piped_preferences.js b/src/assets/javascripts/helpers/youtube/get_piped_preferences.js deleted file mode 100644 index 417d64df..00000000 --- a/src/assets/javascripts/helpers/youtube/get_piped_preferences.js +++ /dev/null @@ -1,24 +0,0 @@ -window.browser = window.browser || window.chrome; - -browser.storage.local.set( - { - 'piped_bufferGoal': localStorage.getItem("bufferGoal"), - 'piped_comments': localStorage.getItem("comments"), - 'piped_disableLBRY': localStorage.getItem("disableLBRY"), - 'piped_enabledCodecs': localStorage.getItem("enabledCodecs"), - 'piped_hl': localStorage.getItem("hl"), - 'piped_homepage': localStorage.getItem("homepage"), - 'piped_instance': localStorage.getItem("instance"), - 'piped_listen': localStorage.getItem("listen"), - 'piped_minimizeDescription': localStorage.getItem("minimizeDescription"), - 'piped_playerAutoPlay': localStorage.getItem("playerAutoPlay"), - 'piped_proxyLBRY': localStorage.getItem("proxyLBRY"), - 'piped_quality': localStorage.getItem("quality"), - 'piped_region': localStorage.getItem("region"), - 'piped_selectedSkip': localStorage.getItem("selectedSkip"), - 'piped_sponsorblock': localStorage.getItem("sponsorblock"), - 'piped_theme': localStorage.getItem("theme"), - 'piped_volume': localStorage.getItem("volume"), - 'piped_watchHistory': localStorage.getItem("watchHistory"), - } -) diff --git a/src/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js b/src/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js deleted file mode 100644 index 7415255a..00000000 --- a/src/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js +++ /dev/null @@ -1,10 +0,0 @@ -window.browser = window.browser || window.chrome; - -browser.storage.local.get( - "pipedMaterial_PREFERENCES", - r => { - if (r.pipedMaterial_PREFERENCES !== undefined) localStorage.setItem("PREFERENCES", r.pipedMaterial_PREFERENCES) - - window.close(); - } -) \ No newline at end of file diff --git a/src/assets/javascripts/helpers/youtube/set_piped_preferences.js b/src/assets/javascripts/helpers/youtube/set_piped_preferences.js deleted file mode 100644 index d5ce49ff..00000000 --- a/src/assets/javascripts/helpers/youtube/set_piped_preferences.js +++ /dev/null @@ -1,44 +0,0 @@ -window.browser = window.browser || window.chrome; - -browser.storage.local.get( - [ - "piped_bufferGoal", - "piped_comments", - "piped_disableLBRY", - "piped_enabledCodecs", - "piped_homepage", - "piped_listen", - "piped_minimizeDescription", - "piped_playerAutoPlay", - "piped_proxyLBRY", - "piped_quality", - "piped_region", - "piped_selectedSkip", - "piped_sponsorblock", - "piped_theme", - "piped_volume", - "piped_watchHistory", - ], - r => { - if (r.piped_bufferGoal !== undefined) localStorage.setItem("bufferGoal", r.piped_bufferGoal); - if (r.piped_comments !== undefined) localStorage.setItem("comments", r.piped_comments); - if (r.piped_disableLBRY !== undefined) localStorage.setItem("disableLBRY", r.piped_disableLBRY); - if (r.piped_hl !== undefined) localStorage.setItem("hl", r.piped_hl); - if (r.piped_enabledCodecs !== undefined) localStorage.setItem("enabledCodecs", r.piped_enabledCodecs); - if (r.piped_homepage !== undefined) localStorage.setItem("homepage", r.piped_homepage); - if (r.piped_instance !== undefined) localStorage.setItem("instance", r.piped_instance); - if (r.piped_listen !== undefined) localStorage.setItem("listen", r.piped_listen); - if (r.piped_minimizeDescription !== undefined) localStorage.setItem("minimizeDescription", r.piped_minimizeDescription); - if (r.piped_playerAutoPlay !== undefined) localStorage.setItem("playerAutoPlay", r.piped_playerAutoPlay); - if (r.piped_proxyLBRY !== undefined) localStorage.setItem("proxyLBRY", r.piped_proxyLBRY); - if (r.piped_quality !== undefined) localStorage.setItem("quality", r.piped_quality); - if (r.piped_region !== undefined) localStorage.setItem("region", r.piped_region); - if (r.piped_selectedSkip !== undefined) localStorage.setItem("selectedSkip", r.piped_selectedSkip); - if (r.piped_sponsorblock !== undefined) localStorage.setItem("sponsorblock", r.piped_sponsorblock); - if (r.piped_theme !== undefined) localStorage.setItem("theme", r.piped_theme); - if (r.piped_volume !== undefined) localStorage.setItem("volume", r.piped_volume); - if (r.piped_watchHistory !== undefined) localStorage.setItem("watchHistory", r.piped_watchHistory); - - window.close(); - } -) \ No newline at end of file diff --git a/src/assets/javascripts/helpers/youtube/youtube.js b/src/assets/javascripts/helpers/youtube/youtube.js deleted file mode 100644 index 564e99c0..00000000 --- a/src/assets/javascripts/helpers/youtube/youtube.js +++ /dev/null @@ -1,453 +0,0 @@ -"use strict"; - -window.browser = window.browser || window.chrome; - -import utils from '../utils.js' - -const targets = [ - /^https?:\/{2}(www\.|music\.|m\.|)youtube\.com(\/.*|$)/, - - /^https?:\/{2}img\.youtube\.com\/vi\/.*\/..*/, // https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api - /^https?:\/{2}(i|s)\.ytimg\.com\/vi\/.*\/..*/, - - /^https?:\/{2}(www\.|music\.|)youtube\.com\/watch\?v\=..*/, - - /^https?:\/{2}youtu\.be\/..*/, - - /^https?:\/{2}(www\.|)(youtube|youtube-nocookie)\.com\/embed\/..*/, -]; -let redirects = { - "invidious": { - "normal": [], - "tor": [] - }, - "piped": { - "normal": [], - "tor": [] - }, - "pipedMaterial": { - "normal": [ - "https://piped-material.xn--17b.net", - "https://piped-material.ftp.sh", - ], - "tor": [] - } -}; -function setRedirects(val) { - browser.storage.local.get('cloudflareList', r => { - redirects.invidious = val.invidious; - redirects.piped = val.piped; - invidiousNormalRedirectsChecks = [...redirects.invidious.normal]; - pipedNormalRedirectsChecks = [...redirects.piped.normal]; - for (const instance of r.cloudflareList) { - const a = invidiousNormalRedirectsChecks.indexOf(instance); - if (a > -1) invidiousNormalRedirectsChecks.splice(a, 1); - - const b = pipedNormalRedirectsChecks.indexOf(instance); - if (b > -1) pipedNormalRedirectsChecks.splice(b, 1); - } - browser.storage.local.set({ - youtubeRedirects: redirects, - invidiousNormalRedirectsChecks, - invidiousTorRedirectsChecks: redirects.invidious.tor, - pipedNormalRedirectsChecks, - pipedTorRedirectsChecks: redirects.piped.tor, - }) - }) -} - -let - disableYoutube, - OnlyEmbeddedVideo, - youtubeFrontend, - youtubeProtocol, - youtubeEmbedFrontend, - youtubeRedirects, - invidiousNormalRedirectsChecks, - invidiousNormalCustomRedirects, - invidiousTorRedirectsChecks, - invidiousTorCustomRedirects, - pipedNormalRedirectsChecks, - pipedNormalCustomRedirects, - pipedTorRedirectsChecks, - pipedTorCustomRedirects, - pipedMaterialNormalRedirectsChecks, - pipedMaterialNormalCustomRedirects, - pipedMaterialTorRedirectsChecks, - pipedMaterialTorCustomRedirects; - -function init() { - return new Promise(resolve => { - browser.storage.local.get( - [ - "disableYoutube", - "OnlyEmbeddedVideo", - "youtubeFrontend", - "youtubeProtocol", - "youtubeEmbedFrontend", - "youtubeRedirects", - "invidiousNormalRedirectsChecks", - "invidiousNormalCustomRedirects", - "invidiousTorRedirectsChecks", - "invidiousTorCustomRedirects", - "pipedNormalRedirectsChecks", - "pipedNormalCustomRedirects", - "pipedTorRedirectsChecks", - "pipedTorCustomRedirects", - "pipedMaterialNormalRedirectsChecks", - "pipedMaterialNormalCustomRedirects", - "pipedMaterialTorRedirectsChecks", - "pipedMaterialTorCustomRedirects", - ], - r => { - disableYoutube = r.disableYoutube; - OnlyEmbeddedVideo = r.OnlyEmbeddedVideo; - youtubeFrontend = r.youtubeFrontend; - youtubeProtocol = r.youtubeProtocol; - youtubeEmbedFrontend = r.youtubeEmbedFrontend; - youtubeRedirects = r.youtubeRedirects; - invidiousNormalRedirectsChecks = r.invidiousNormalRedirectsChecks; - invidiousNormalCustomRedirects = r.invidiousNormalCustomRedirects; - invidiousTorRedirectsChecks = r.invidiousTorRedirectsChecks; - invidiousTorCustomRedirects = r.invidiousTorCustomRedirects; - pipedNormalRedirectsChecks = r.pipedNormalRedirectsChecks; - pipedNormalCustomRedirects = r.pipedNormalCustomRedirects; - pipedTorRedirectsChecks = r.pipedTorRedirectsChecks; - pipedTorCustomRedirects = r.pipedTorCustomRedirects; - pipedMaterialNormalRedirectsChecks = r.pipedMaterialNormalRedirectsChecks; - pipedMaterialNormalCustomRedirects = r.pipedMaterialNormalCustomRedirects; - pipedMaterialTorRedirectsChecks = r.pipedMaterialTorRedirectsChecks; - pipedMaterialTorCustomRedirects = r.pipedMaterialTorCustomRedirects; - resolve(); - } - ) - }) -} - -init(); -browser.storage.onChanged.addListener(init) - -function all() { - return [ - ...youtubeRedirects.invidious.normal, - ...youtubeRedirects.invidious.tor, - - ...youtubeRedirects.piped.normal, - ...youtubeRedirects.piped.tor, - - ...youtubeRedirects.pipedMaterial.normal, - ...youtubeRedirects.pipedMaterial.tor, - - ...invidiousNormalCustomRedirects, - ...invidiousTorCustomRedirects, - - ...pipedNormalCustomRedirects, - ...pipedTorCustomRedirects, - - ...pipedMaterialNormalCustomRedirects, - ...pipedMaterialTorCustomRedirects, - ]; -} - -function redirect(url, details, initiator) { - if (disableYoutube) return; - if (!targets.some(rx => rx.test(url.href))) return; - if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; - - const isInvidious = youtubeFrontend == 'invidious'; - const isPiped = youtubeFrontend == 'piped'; - const isPipedMaterial = youtubeFrontend == 'pipedMaterial' - const isFreetube = youtubeFrontend == 'freetube'; - const isYatte = youtubeFrontend == 'yatte'; - - const isFrontendYoutube = youtubeEmbedFrontend == "youtube"; - const isFrontendInvidious = youtubeEmbedFrontend == 'invidious'; - const isFrontendPiped = youtubeEmbedFrontend == 'piped'; - const isFrontendPipedMaterial = youtubeEmbedFrontend == 'pipedMaterial'; - - const isOnlyEmbeddedVideo = OnlyEmbeddedVideo == 'onlyNotEmbedded'; - const isOnlyNotEmbedded = OnlyEmbeddedVideo == 'onlyNotEmbedded' - - const is_main_frame = details.type === "main_frame"; - const is_sub_frame = details.type === "sub_frame"; - - if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return; // Don't redirect YouTube Player API. - - if (youtubeFrontend == 'yatte' && is_main_frame) - return url.href.replace(/^https?:\/{2}/, 'yattee://'); - - else if (isFreetube && is_main_frame) - return `freetube://https:${url.pathname}${url.search}`; - - else if (isFreetube && params && isFrontendYoutube) - return; - - else if (isInvidious || ((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) { - - if (isOnlyEmbeddedVideo && !is_sub_frame) return; - if (isOnlyNotEmbedded && params && !((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) return; - - let instancesList; - if (youtubeProtocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects]; - else if (youtubeProtocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects]; - if (instancesList.length === 0) return; - let randomInstance = utils.getRandomInstance(instancesList); - - return `${randomInstance}${url.pathname}${url.search}`; - } else if (isPiped || ((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)) { - - if (isOnlyEmbeddedVideo && !is_sub_frame) return; - if ( - isOnlyNotEmbedded && params && - !((isFreetube || isYatte) && isFrontendPiped && is_sub_frame) - ) return; - - let instancesList; - if (youtubeProtocol == 'normal') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects]; - else if (youtubeProtocol == 'tor') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects]; - if (instancesList.length === 0) return; - - const randomInstance = utils.getRandomInstance(instancesList); - return `${randomInstance}${url.pathname}${url.search}`; - } - else if (isPipedMaterial || ((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)) { - if (isOnlyEmbeddedVideo && details.type !== "sub_frame") return; - if ( - isOnlyNotEmbedded && params && - !((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame) - ) return; - - let instancesList; - if (youtubeProtocol == 'normal') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects]; - else if (youtubeProtocol == 'tor') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects]; - - const randomInstance = utils.getRandomInstance(instancesList); - return `${randomInstance}${url.pathname}${url.search}`; - } - else return 'CANCEL'; -} - -function reverse(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - const instances = all(); - if (!instances.includes(protocolHost)) { resolve(); return; } - - resolve(`https://youtube.com${url.pathname}${url.search}`); - }) -} - -function switchInstance(url) { - return new Promise(async resolve => { - await init(); - const protocolHost = utils.protocolHost(url); - const instances = all(); - if (!instances.includes(protocolHost)) { resolve(); return; } - - let instancesList; - if (youtubeProtocol == 'normal') { - if (youtubeFrontend == 'invidious') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects]; - else if (youtubeFrontend == 'piped') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects]; - else if (youtubeFrontend == 'pipedMaterial') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects]; - } - else if (youtubeProtocol == 'tor') { - if (youtubeFrontend == 'invidious') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects]; - else if (youtubeFrontend == 'piped') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects]; - else if (youtubeFrontend == 'pipedMaterial') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects]; - } - - const i = instancesList.indexOf(protocolHost); - if (i > -1) instancesList.splice(i, 1); - if (instancesList.length == 0) { resolve(); return; } - - const randomInstance = utils.getRandomInstance(instancesList); - resolve(`${randomInstance}${url.pathname}${url.search}`); - }) -} - -function initDefaults() { - return new Promise(async resolve => { - fetch('/instances/data.json').then(response => response.text()).then(async data => { - let dataJson = JSON.parse(data); - redirects.invidious = dataJson.invidious; - redirects.piped = dataJson.piped; - browser.storage.local.get('cloudflareList', async r => { - - invidiousNormalRedirectsChecks = [...redirects.invidious.normal]; - pipedNormalRedirectsChecks = [...redirects.piped.normal]; - pipedMaterialNormalRedirectsChecks = [...redirects.pipedMaterial.normal]; - - for (const instance of r.cloudflareList) { - let i; - - i = invidiousNormalRedirectsChecks.indexOf(instance); - if (i > -1) invidiousNormalRedirectsChecks.splice(i, 1); - - i = pipedNormalRedirectsChecks.indexOf(instance); - if (i > -1) pipedNormalRedirectsChecks.splice(i, 1); - - i = pipedMaterialNormalRedirectsChecks.indexOf(instance); - if (i > -1) pipedMaterialNormalRedirectsChecks.splice(i, 1); - } - - await browser.storage.local.set({ - disableYoutube: false, - enableYoutubeCustomSettings: false, - OnlyEmbeddedVideo: 'both', - - youtubeRedirects: redirects, - - youtubeFrontend: 'invidious', - - invidiousNormalRedirectsChecks: invidiousNormalRedirectsChecks, - invidiousNormalCustomRedirects: [], - - invidiousTorRedirectsChecks: [...redirects.invidious.tor], - invidiousTorCustomRedirects: [], - - pipedNormalRedirectsChecks: pipedNormalRedirectsChecks, - pipedNormalCustomRedirects: [], - - pipedTorRedirectsChecks: [...redirects.piped.tor], - pipedTorCustomRedirects: [], - - pipedMaterialNormalRedirectsChecks: pipedMaterialNormalRedirectsChecks, - pipedMaterialNormalCustomRedirects: [], - - pipedMaterialTorRedirectsChecks: [...redirects.pipedMaterial.tor], - pipedMaterialTorCustomRedirects: [], - - youtubeEmbedFrontend: 'invidious', - youtubeProtocol: 'normal', - }) - resolve(); - }) - }) - }) -} - -function initInvidiousCookies(test, from) { - return new Promise(async resolve => { - await init(); - if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; } - const protocolHost = utils.protocolHost(from); - if (![ - ...invidiousNormalRedirectsChecks, - ...invidiousTorRedirectsChecks, - ...invidiousNormalCustomRedirects, - ...invidiousTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - if (!test) { - let checkedInstances; - if (youtubeProtocol == 'normal') checkedInstances = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects] - else if (youtubeProtocol == 'tor') checkedInstances = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects] - const i = checkedInstances.indexOf(protocolHost); - if (i !== -1) checkedInstances.splice(i, 1); - for (const to of checkedInstances) - utils.copyCookie('invidious', from, to, 'PREFS'); - } - resolve(true); - }) -} - -function setInvidiousCookies() { - return new Promise(async resolve => { - await init(); - if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; } - let checkedInstances; - if (youtubeProtocol == 'normal') checkedInstances = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects] - else if (youtubeProtocol == 'tor') checkedInstances = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects] - for (const to of checkedInstances) - utils.getCookiesFromStorage('invidious', to, 'PREFS'); - resolve(); - }) -} - -function initPipedLocalStorage(test, url, tabId) { - return new Promise(async resolve => { - await init(); - if (disableYoutube || youtubeFrontend != 'piped') { resolve(); return; } - const protocolHost = utils.protocolHost(url); - if (![ - ...pipedNormalCustomRedirects, - ...pipedNormalRedirectsChecks, - ...pipedTorRedirectsChecks, - ...pipedTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - if (!test) { - - browser.tabs.executeScript(tabId, { file: "/assets/javascripts/helpers/youtube/get_piped_preferences.js", runAt: "document_start" }); - - let checkedInstances; - if (youtubeProtocol == 'normal') checkedInstances = [...pipedNormalCustomRedirects, ...pipedNormalRedirectsChecks] - else if (youtubeProtocol == 'tor') checkedInstances = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects] - const i = checkedInstances.indexOf(protocolHost); - if (i !== -1) checkedInstances.splice(i, 1); - for (const to of checkedInstances) { - browser.tabs.create({ url: to }, - tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/youtube/set_piped_preferences.js", runAt: "document_start" })) - } - } - resolve(true); - }) -} - -function initPipedMaterialLocalStorage(test, url, tabId,) { - return new Promise(async resolve => { - await init(); - if (disableYoutube || youtubeFrontend != 'pipedMaterial') { resolve(); return; } - const protocolHost = utils.protocolHost(url); - if (![ - ...pipedMaterialNormalRedirectsChecks, - ...pipedMaterialNormalCustomRedirects, - ...pipedMaterialTorRedirectsChecks, - ...pipedMaterialTorCustomRedirects, - ].includes(protocolHost)) { resolve(); return; } - - if (!test) { - browser.tabs.executeScript(tabId, { file: "/assets/javascripts/helpers/youtube/get_pipedMaterial_preferences.js", runAt: "document_start" }); - - let checkedInstances; - if (youtubeProtocol == 'normal') checkedInstances = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects] - else if (youtubeProtocol == 'tor') checkedInstances = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects] - const i = checkedInstances.indexOf(protocolHost); - if (i !== -1) checkedInstances.splice(i, 1); - for (const to of checkedInstances) - browser.tabs.create( - { url: to }, - tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/helpers/youtube/set_pipedMaterial_preferences.js", runAt: "document_start" }) - ); - } - resolve(true); - }) -} - -function removeXFrameOptions(e) { - const url = new URL(e.url); - let protocolHost = utils.protocolHost(url); - const instances = all(); - if (!instances.includes(protocolHost) || e.type != 'sub_frame') return; - - let isChanged = false; - for (const i in e.responseHeaders) - if (e.responseHeaders[i].name == 'x-frame-options') { - e.responseHeaders.splice(i, 1); - isChanged = true; - } - if (isChanged) return { responseHeaders: e.responseHeaders }; -} - -export default { - setRedirects, - initPipedLocalStorage, - initPipedMaterialLocalStorage, - initInvidiousCookies, - setInvidiousCookies, - redirect, - reverse, - switchInstance, - initDefaults, - removeXFrameOptions, -}; diff --git a/src/assets/javascripts/helpers/youtubeMusic.js b/src/assets/javascripts/helpers/youtubeMusic.js deleted file mode 100644 index 68fa4f24..00000000 --- a/src/assets/javascripts/helpers/youtubeMusic.js +++ /dev/null @@ -1,97 +0,0 @@ -"use strict"; - -import utils from './utils.js' - -window.browser = window.browser || window.chrome; - -const targets = [ - /^https?:\/{2}music\.youtube\.com(\/.*|$)/, -]; -let redirects = { - "beatbump": { - "normal": [ - "https://beatbump.ml" - ], - "tor": [] - }, -}; - -let - disableYoutubeMusic, - beatbumpNormalRedirectsChecks, - beatbumpNormalCustomRedirects; - -function init() { - browser.storage.local.get( - [ - "disableYoutubeMusic", - "beatbumpNormalRedirectsChecks", - "beatbumpNormalCustomRedirects", - ], - r => { - disableYoutubeMusic = r.disableYoutubeMusic; - beatbumpNormalRedirectsChecks = r.beatbumpNormalRedirectsChecks; - beatbumpNormalCustomRedirects = r.beatbumpNormalCustomRedirects; - } - ) -} - -init(); -browser.storage.onChanged.addListener(init) - -/* -Video -https://music.youtube.com/watch?v=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA -https://beatbump.ml/listen?id=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA - -Playlist -https://music.youtube.com/playlist?list=PLqxd0OMLeWy64zlwhjouj92ISc38FbOns -https://music.youtube.com/playlist?list=PLqxd0OMLeWy7lrJSzt9LnOJjbC1IaruPM -https://music.youtube.com/playlist?list=PLQod4DlD72ZMJmOrSNbmEmK_iZ1oXPzKd -https://beatbump.ml/playlist/VLPLqxd0OMLeWy64zlwhjouj92ISc38FbOns - -Channel -https://music.youtube.com/channel/UCfgmMDI7T5tOQqjnOBRe_wg -https://beatbump.ml/artist/UCfgmMDI7T5tOQqjnOBRe_wg - -Albums -https://music.youtube.com/playlist?list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU -https://music.youtube.com/playlist?list=OLAK5uy_lcr5O1zS8f6WIFI_yxqVp2RK9Dyy2bbw0 -https://beatbump.ml/release?id=MPREb_3DURc4yEUtD -https://beatbump.ml/release?id=MPREb_evaZrV1WNdS - -https://music.youtube.com/playlist?list=OLAK5uy_n6OHVllUZUCnlIY1m-gUaH8uqkN3Y-Ca8 -https://music.youtube.com/playlist?list=OLAK5uy_nBOTxAc3_RGB82-Z54jdARGxGaCYlpngY -https://beatbump.ml/release?id=MPREb_QygdC0wEoLe - -https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU -*/ -function redirect(url, type, initiator) { - if (disableYoutubeMusic) return; - if (!targets.some(rx => rx.test(url.href))) return; - - let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects]; - if (instancesList.length === 0) return; - const randomInstance = utils.getRandomInstance(instancesList); - resolve( - `${randomInstance}${url.pathname}${url.search}` - .replace("/watch?v=", "/listen?id=") - .replace("/channel/", "/artist/") - .replace("/playlist?list=", "/playlist/VL") - ); -} - -async function initDefaults() { - await browser.storage.local.set({ - disableYoutubeMusic: true, - youtubeMusicRedirects: redirects, - - beatbumpNormalRedirectsChecks: [...redirects.beatbump.normal], - beatbumpNormalCustomRedirects: [], - }) -} - -export default { - redirect, - initDefaults, -}; diff --git a/src/assets/javascripts/imgur.js b/src/assets/javascripts/imgur.js new file mode 100644 index 00000000..9f93f362 --- /dev/null +++ b/src/assets/javascripts/imgur.js @@ -0,0 +1,191 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = /^https?:\/{2}([im]\.)?imgur\.com(\/|$)/ + +let redirects = { + "rimgo": { + "normal": [], + "tor": [], + "i2p": [] + } +} +function setRedirects() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.rimgo = dataJson.rimgo; + + rimgoNormalRedirectsChecks = [...redirects.rimgo.normal]; + rimgoTorRedirectsChecks = [...redirects.rimgo.tor]; + rimgoI2pRedirectsChecks = [...redirects.rimgo.i2p]; + + for (const instance of r.cloudflareList) { + const a = rimgoNormalRedirectsChecks.indexOf(instance); + if (a > -1) rimgoNormalRedirectsChecks.splice(a, 1); + + const b = rimgoTorRedirectsChecks.indexOf(instance); + if (b > -1) rimgoTorRedirectsChecks.splice(b, 1); + + const c = rimgoI2pRedirectsChecks.indexOf(instance); + if (c > -1) rimgoI2pRedirectsChecks.splice(c, 1); + } + + await browser.storage.local.set({ + imgurRedirects: redirects, + rimgoNormalRedirectsChecks, + rimgoTorRedirectsChecks, + rimgoI2pRedirectsChecks, + }); + + resolve(); + }) + }) +} + +let + disableImgur, + imgurRedirects, + imgurProtocol, + rimgoNormalRedirectsChecks, + rimgoNormalCustomRedirects, + rimgoTorRedirectsChecks, + rimgoTorCustomRedirects, + rimgoI2pRedirectsChecks, + rimgoI2pCustomRedirects; + +function init() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + "disableImgur", + "imgurRedirects", + "imgurProtocol", + "rimgoNormalRedirectsChecks", + "rimgoNormalCustomRedirects", + "rimgoTorRedirectsChecks", + "rimgoTorCustomRedirects", + "rimgoI2pRedirectsChecks", + "rimgoI2pCustomRedirects", + ], + r => { + disableImgur = r.disableImgur; + imgurRedirects = r.imgurRedirects; + imgurProtocol = r.imgurProtocol; + rimgoNormalRedirectsChecks = r.rimgoNormalRedirectsChecks; + rimgoNormalCustomRedirects = r.rimgoNormalCustomRedirects; + rimgoTorRedirectsChecks = r.rimgoTorRedirectsChecks; + rimgoTorCustomRedirects = r.rimgoTorCustomRedirects; + rimgoI2pRedirectsChecks = r.rimgoI2pRedirectsChecks; + rimgoI2pCustomRedirects = r.rimgoI2pCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +// https://imgur.com/gallery/s4WXQmn +// https://imgur.com/a/H8M4rcp +// https://imgur.com/gallery/gYiQLWy +// https://imgur.com/gallery/cTRwaJU +// https://i.imgur.com/CFSQArP.jpeg + +function all() { + return [ + ...imgurRedirects.rimgo.normal, + ...imgurRedirects.rimgo.tor, + ...imgurRedirects.rimgo.i2p, + ...rimgoNormalCustomRedirects, + ...rimgoTorCustomRedirects, + ...rimgoI2pCustomRedirects, + ]; +} + +function redirect(url, type, initiator) { + if (disableImgur) return; + if (url.pathname == "/") return; + if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media",].includes(type)) return; + if (initiator && (all().includes(initiator.origin) || targets.test(initiator.host))) return; + if (!targets.test(url.href)) return; + if (url.pathname.includes("delete/")) return; + + let instancesList; + if (imgurProtocol == 'normal') instancesList = [...rimgoNormalRedirectsChecks, ...rimgoNormalCustomRedirects]; + if (imgurProtocol == 'tor') instancesList = [...rimgoTorRedirectsChecks, ...rimgoTorCustomRedirects]; + if (imgurProtocol == 'i2p') instancesList = [...rimgoI2pRedirectsChecks, ...rimgoI2pCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + return `${randomInstance}${url.pathname}${url.search}`; +} + +function reverse(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + resolve(`https://imgur.com${url.pathname}${url.search}`); + }) +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + let instancesList; + if (imgurProtocol == 'normal') instancesList = [...rimgoNormalCustomRedirects, ...rimgoNormalRedirectsChecks]; + else if (imgurProtocol == 'tor') instancesList = [...rimgoTorCustomRedirects, ...rimgoTorRedirectsChecks]; + else if (imgurProtocol == 'i2p') instancesList = [...rimgoI2pCustomRedirects, ...rimgoI2pRedirectsChecks]; + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.rimgo = dataJson.rimgo; + browser.storage.local.get('cloudflareList', async r => { + rimgoNormalRedirectsChecks = [...redirects.rimgo.normal]; + for (const instance of r.cloudflareList) { + const i = rimgoNormalRedirectsChecks.indexOf(instance); + if (i > -1) rimgoNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableImgur: false, + imgurProtocol: 'normal', + imgurRedirects: redirects, + + rimgoNormalRedirectsChecks: rimgoNormalRedirectsChecks, + rimgoNormalCustomRedirects: [], + + rimgoTorRedirectsChecks: [...redirects.rimgo.tor], + rimgoTorCustomRedirects: [], + + rimgoI2pRedirectsChecks: [...redirects.rimgo.i2p], + rimgoI2pCustomRedirects: [], + }); + resolve(); + }); + }); + }); +} + +export default { + setRedirects, + redirect, + reverse, + initDefaults, + switchInstance, +}; diff --git a/src/assets/javascripts/instagram.js b/src/assets/javascripts/instagram.js new file mode 100644 index 00000000..f5c54b3a --- /dev/null +++ b/src/assets/javascripts/instagram.js @@ -0,0 +1,166 @@ +window.browser = window.browser || window.chrome; +import utils from './utils.js' + +const targets = [ + "instagram.com", + "www.instagram.com", +]; +let redirects = { + "bibliogram": { + "normal": [], + "tor": [] + } +}; +function setRedirects(val) { + browser.storage.local.get('cloudflareList', async r => { + redirects.bibliogram = val; + bibliogramNormalRedirectsChecks = [...redirects.bibliogram.normal]; + for (const instance of r.cloudflareList) { + const a = bibliogramNormalRedirectsChecks.indexOf(instance); + if (a > -1) bibliogramNormalRedirectsChecks.splice(a, 1); + } + browser.storage.local.set({ + instagramRedirects: redirects, + bibliogramNormalRedirectsChecks + }) + }) +} + +let + disableInstagram, + instagramProtocol, + instagramRedirects, + bibliogramNormalRedirectsChecks, + bibliogramTorRedirectsChecks, + bibliogramNormalCustomRedirects, + bibliogramTorCustomRedirects; + +function init() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + "disableInstagram", + "instagramProtocol", + "instagramRedirects", + "bibliogramNormalRedirectsChecks", + "bibliogramTorRedirectsChecks", + "bibliogramNormalCustomRedirects", + "bibliogramTorCustomRedirects", + ], + r => { + disableInstagram = r.disableInstagram; + instagramProtocol = r.instagramProtocol; + instagramRedirects = r.instagramRedirects; + bibliogramNormalRedirectsChecks = r.bibliogramNormalRedirectsChecks; + bibliogramTorRedirectsChecks = r.bibliogramTorRedirectsChecks; + bibliogramNormalCustomRedirects = r.bibliogramNormalCustomRedirects; + bibliogramTorCustomRedirects = r.bibliogramTorCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function all() { + return [ + ...instagramRedirects.bibliogram.normal, + ...instagramRedirects.bibliogram.tor, + ...bibliogramNormalCustomRedirects, + ...bibliogramTorCustomRedirects, + ] +} + +function redirect(url, type, initiator) { + if (disableInstagram) return; + if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; + if (!targets.includes(url.host)) return; + if (!["main_frame", "sub_frame", "xmlhttprequest", "other", "image", "media"].includes(type)) return; + + const bypassPaths = [/about/, /explore/, /support/, /press/, /api/, /privacy/, /safety/, /admin/, /\/(accounts\/|embeds?.js)/]; + if (bypassPaths.some(rx => rx.test(url.pathname))) return; + + let instancesList; + if (instagramProtocol == 'normal') instancesList = [...bibliogramNormalRedirectsChecks, ...bibliogramNormalCustomRedirects]; + else if (instagramProtocol == 'tor') instancesList = [...bibliogramTorRedirectsChecks, ...bibliogramTorCustomRedirects]; + if (instancesList.length === 0) return; + let randomInstance = utils.getRandomInstance(instancesList) + + const reservedPaths = ["u", "p", "privacy",]; + if (url.pathname === "/" || reservedPaths.includes(url.pathname.split("/")[1])) + return `${randomInstance}${url.pathname}${url.search}`; + if (url.pathname.startsWith("/reel") || url.pathname.startsWith("/tv")) + return `${randomInstance}/p${url.pathname.replace(/\/reel|\/tv/i, '')}${url.search}`; + else + return `${randomInstance}/u${url.pathname}${url.search}`; // Likely a user profile, redirect to '/u/...' +} + +function reverse(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + + if (url.pathname.startsWith('/p')) resolve(`https://instagram.com${url.pathname.replace('/p', '')}${url.search}`); + if (url.pathname.startsWith('/u')) resolve(`https://instagram.com${url.pathname.replace('/u', '')}${url.search}`); + resolve(`https://instagram.com${url.pathname}${url.search}`); + }) +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (instagramProtocol == 'normal') instancesList = [...bibliogramNormalCustomRedirects, ...bibliogramNormalRedirectsChecks]; + else if (instagramProtocol == 'tor') instancesList = [...bibliogramTorCustomRedirects, ...bibliogramTorRedirectsChecks]; + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(data => { + let dataJson = JSON.parse(data); + redirects.bibliogram = dataJson.bibliogram; + browser.storage.local.get('cloudflareList', r => { + bibliogramNormalRedirectsChecks = [...redirects.bibliogram.normal]; + for (const instance of r.cloudflareList) { + const i = bibliogramNormalRedirectsChecks.indexOf(instance); + if (i > -1) bibliogramNormalRedirectsChecks.splice(i, 1); + } + browser.storage.local.set({ + disableInstagram: false, + instagramRedirects: redirects, + + bibliogramNormalRedirectsChecks: bibliogramNormalRedirectsChecks, + bibliogramTorRedirectsChecks: [], + + bibliogramNormalCustomRedirects: [...redirects.bibliogram.tor], + bibliogramTorCustomRedirects: [], + instagramProtocol: "normal", + }) + resolve(); + } + ) + }) + }) +} + +export default { + setRedirects, + reverse, + redirect, + initDefaults, + switchInstance, +}; diff --git a/src/assets/javascripts/lbry.js b/src/assets/javascripts/lbry.js new file mode 100644 index 00000000..b44cc738 --- /dev/null +++ b/src/assets/javascripts/lbry.js @@ -0,0 +1,156 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +let targets = ["odysee.com"]; + +let redirects = { + "librarian": { + "normal": [ + "https://lbry.bcow.xyz", + "https://odysee.076.ne.jp", + "https://lbry.ix.tc", + "https://librarian.pussthecat.org", + "https://lbry.mutahar.rocks", + "https://librarian.esmailelbob.xyz", + ], + "tor": [ + "http://ecc5mi5ncdw6mxhjz6re6g2uevtpbzxjvxgrxia2gyvrlnil3srbnhyd.onion", + "http://vrmbc4brkgkaysmi3fenbzkayobxjh24slmhtocambn3ewe62iuqt3yd.onion", + ] + } +} + +function setRedirects(val) { + redirects.librarian = val; + browser.storage.local.set({ lbryTargetsRedirects: redirects }) + for (const item of librarianNormalRedirectsChecks) + if (!redirects.librarian.normal.includes(item)) { + var index = librarianNormalRedirectsChecks.indexOf(item); + if (index !== -1) librarianNormalRedirectsChecks.splice(index, 1); + } + browser.storage.local.set(librarianNormalRedirectsChecks); + + for (const item of librarianTorRedirectsChecks) + if (!redirects.librarian.normal.includes(item)) { + var index = librarianTorRedirectsChecks.indexOf(item); + if (index !== -1) librarianTorRedirectsChecks.splice(index, 1); + } + browser.storage.local.set(librarianTorRedirectsChecks) +} + +let + disableLbryTargets, + lbryTargetsProtocol, + lbryTargetsRedirects, + librarianNormalRedirectsChecks, + librarianNormalCustomRedirects, + librarianTorRedirectsChecks, + librarianTorCustomRedirects; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "disableLbryTargets", + "lbryTargetsProtocol", + "lbryTargetsRedirects", + "librarianNormalRedirectsChecks", + "librarianNormalCustomRedirects", + "librarianTorRedirectsChecks", + "librarianTorCustomRedirects", + ], + r => { + disableLbryTargets = r.disableLbryTargets; + lbryTargetsProtocol = r.lbryTargetsProtocol; + lbryTargetsRedirects = r.lbryTargetsRedirects; + librarianNormalRedirectsChecks = r.librarianNormalRedirectsChecks; + librarianNormalCustomRedirects = r.librarianNormalCustomRedirects; + librarianTorRedirectsChecks = r.librarianTorRedirectsChecks; + librarianTorCustomRedirects = r.librarianTorCustomRedirects; + resolve(); + } + ) + }) +} +init(); +browser.storage.onChanged.addListener(init) + +function all() { + return [ + ...redirects.librarian.normal, + ...redirects.librarian.tor, + ...librarianNormalCustomRedirects, + ...librarianTorCustomRedirects, + ]; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (lbryTargetsProtocol == 'normal') instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]; + else if (lbryTargetsProtocol == 'tor') instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]; + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function redirect(url, type, initiator) { + if (disableLbryTargets) return; + if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return; + if (!targets.includes(url.host)) return; + if (type != "main_frame") return; + + let instancesList; + if (lbryTargetsProtocol == 'normal') instancesList = [...librarianNormalRedirectsChecks, ...librarianNormalCustomRedirects]; + if (lbryTargetsProtocol == 'tor') instancesList = [...librarianTorRedirectsChecks, ...librarianTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + return `${randomInstance}${url.pathname}${url.search}`; +} + +function initDefaults() { + return new Promise(resolve => { + browser.storage.local.get('cloudflareList', async r => { + librarianNormalRedirectsChecks = [...redirects.librarian.normal]; + for (const instance of r.cloudflareList) { + let i; + + i = librarianNormalRedirectsChecks.indexOf(instance); + if (i > -1) librarianNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableLbryTargets: true, + lbryTargetsRedirects: { + 'librarian': redirects.librarian + }, + + librarianNormalRedirectsChecks: librarianNormalRedirectsChecks, + librarianNormalCustomRedirects: [], + + librarianTorRedirectsChecks: [...redirects.librarian.tor], + librarianTorCustomRedirects: [], + + lbryTargetsProtocol: "normal", + }) + resolve(); + }) + }) +} + +export default { + setRedirects, + switchInstance, + redirect, + initDefaults, +}; diff --git a/src/assets/javascripts/localise.js b/src/assets/javascripts/localise.js index 752a6dd3..a4bbca92 100644 --- a/src/assets/javascripts/localise.js +++ b/src/assets/javascripts/localise.js @@ -1,39 +1,31 @@ window.browser = window.browser || window.chrome; -function getMessage(tag) { - return tag.replace(/__MSG_(\w+)__/g, function (_match, v1) { - return v1 ? browser.i18n.getMessage(v1) : null; - }); -} - function localisePage() { - let elements = document.querySelectorAll("[data-localise]"); + function getMessage(tag) { + return tag.replace(/__MSG_(\w+)__/g, (_match, v1) => { + return v1 ? browser.i18n.getMessage(v1) : null; + }); + } + const elements = document.querySelectorAll("[data-localise]"); for (let i in elements) if (elements.hasOwnProperty(i)) { - let obj = elements[i]; - let tag = obj.getAttribute("data-localise").toString(); - - let msg = getMessage(tag); - + const obj = elements[i]; + const tag = obj.getAttribute("data-localise").toString(); + const msg = getMessage(tag); if (msg && msg !== tag) obj.textContent = msg; } - let placeholders = document.querySelectorAll("[data-localise-placeholder]"); - + const placeholders = document.querySelectorAll("[data-localise-placeholder]"); for (let i in placeholders) if (placeholders.hasOwnProperty(i)) { - let obj = placeholders[i]; - let tag = obj.getAttribute("data-localise-placeholder").toString(); - - let msg = getMessage(tag); - + const obj = placeholders[i]; + const tag = obj.getAttribute("data-localise-placeholder").toString(); + const msg = getMessage(tag); if (msg && msg !== tag) obj.placeholder = msg; } } -localisePage(); - export default { localisePage } diff --git a/src/assets/javascripts/maps.js b/src/assets/javascripts/maps.js new file mode 100644 index 00000000..3ab5e2b6 --- /dev/null +++ b/src/assets/javascripts/maps.js @@ -0,0 +1,212 @@ +"use strict"; + +window.browser = window.browser || window.chrome; +import utils from './utils.js' + +const targets = /^https?:\/{2}(((www|maps)\.)?(google\.).*(\/maps)|maps\.(google\.).*)/; + +let redirects = { + 'osm': { + "normal": [ + "https://openstreetmap.org" + ] + }, + 'facil': { + "normal": [ + "https://facilmap.org" + ] + } +}; + + +let + disableMaps, + mapsFrontend, + facilNormalRedirectsChecks, + facilNormalCustomRedirects; + +function init() { + browser.storage.local.get( + [ + "disableMaps", + "mapsFrontend", + "facilNormalRedirectsChecks", + "facilNormalCustomRedirects", + ], + r => { + disableMaps = r.disableMaps; + mapsFrontend = r.mapsFrontend; + facilNormalRedirectsChecks = r.facilNormalRedirectsChecks; + facilNormalCustomRedirects = r.facilNormalCustomRedirects; + } + ) +} + +init(); +browser.storage.onChanged.addListener(init) + +function redirect(url, initiator) { + const mapCentreRegex = /@(-?\d[0-9.]*),(-?\d[0-9.]*),(\d{1,2})[.z]/; + const dataLatLngRegex = /!3d(-?[0-9]{1,}.[0-9]{1,})!4d(-?[0-9]{1,}.[0-9]{1,})/; + const placeRegex = /\/place\/(.*)\//; + const travelModes = { + driving: "fossgis_osrm_car", + walking: "fossgis_osrm_foot", + bicycling: "fossgis_osrm_bike", + transit: "fossgis_osrm_car", // not implemented on OSM, default to car. + }; + const travelModesFacil = { + driving: "car", + walking: "pedestrian", + bicycling: "bicycle", + transit: "car", // not implemented on Facil, default to car. + }; + const osmLayers = { + none: "S", + transit: "T", + traffic: "S", // not implemented on OSM, default to standard. + bicycling: "C", + }; + + function addressToLatLng(address) { + const xmlhttp = new XMLHttpRequest(); + xmlhttp.open("GET", `https://nominatim.openstreetmap.org/search/${address}?format=json&limit=1`, false); + xmlhttp.send(); + if (xmlhttp.status === 200) { + const json = JSON.parse(xmlhttp.responseText)[0]; + if (json) { + console.log('json', json) + return [ + `${json.lat},${json.lon}`, + `${json.boundingbox[2]},${json.boundingbox[1]},${json.boundingbox[3]},${json.boundingbox[0]}`, + ]; + } + } + console.info("Error: Status is " + xmlhttp.status); + } + + if (disableMaps) return; + if (initiator && initiator.host === "earth.google.com") return; + if (!url.href.match(targets)) return; + + let randomInstance; + if (mapsFrontend == 'osm') randomInstance = utils.getRandomInstance(redirects.osm.normal); + if (mapsFrontend == 'facil') randomInstance = utils.getRandomInstance([...facilNormalRedirectsChecks, ...facilNormalCustomRedirects]); + + let mapCentre = "#"; + let prefs = {}; + + if (url.pathname.match(mapCentreRegex)) { // Set map centre if present + var [, lat, lon, zoom] = url.pathname.match(mapCentreRegex); + } else if (url.searchParams.has("center")) { + var [lat, lon] = url.searchParams.get("center").split(","); + var zoom = url.searchParams.get("zoom") ?? "17"; + } + + if (lat && lon && zoom) { + if (mapsFrontend == 'osm') mapCentre = `#map=${zoom}/${lat}/${lon}`; + if (mapsFrontend == 'facil') mapCentre = `#${zoom}/${lat}/${lon}`; + } + + if (url.searchParams.get("layer")) prefs.layers = osmLayers[url.searchParams.get("layer")]; + + if (url.pathname.includes("/embed")) { // Handle Google Maps Embed API + // https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Eiffel+Tower,Paris+France + console.log("embed life"); + + let query = ""; + if (url.searchParams.has("q")) query = url.searchParams.get("q"); + else if (url.searchParams.has("query")) query = url.searchParams.has("query"); + + else if (url.searchParams.has("pb")) + try { query = url.searchParams.get("pb").split(/!2s(.*?)!/)[1]; } + catch (error) { console.error(error); } // Unable to find map marker in URL. + + let [coords, boundingbox] = addressToLatLng(query); + prefs.bbox = boundingbox; + prefs.marker = coords; + prefs.layer = "mapnik"; + let prefsEncoded = new URLSearchParams(prefs).toString(); + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/export/embed.html?${prefsEncoded}`); return; } + + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${query}`); return; } + + } else if (url.pathname.includes("/dir")) { // Handle Google Maps Directions + // https://www.google.com/maps/dir/?api=1&origin=Space+Needle+Seattle+WA&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling + + let travMod = url.searchParams.get("travelmode"); + if (url.searchParams.has("travelmode")) prefs.engine = travelModes[travMod]; + + let orgVal = url.searchParams.get("origin"); + let destVal = url.searchParams.get("destination"); + + let org; addressToLatLng(orgVal, a => org = a); + let dest; addressToLatLng(destVal, a => dest = a); + prefs.route = `${org};${dest}`; + + let prefsEncoded = new URLSearchParams(prefs).toString(); + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/directions?${prefsEncoded}${mapCentre}`); return; } + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${orgVal}%20to%20${destVal}%20by%20${travelModesFacil[travMod]}`); return; } + + } else if (url.pathname.includes("data=") && url.pathname.match(dataLatLngRegex)) { // Get marker from data attribute + // https://www.google.com/maps/place/41%C2%B001'58.2%22N+40%C2%B029'18.2%22E/@41.032833,40.4862063,17z/data=!3m1!4b1!4m6!3m5!1s0x0:0xf64286eaf72fc49d!7e2!8m2!3d41.0328329!4d40.4883948 + console.log("data life"); + + let [, mlat, mlon] = url.pathname.match(dataLatLngRegex); + + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; } + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; } + + } else if (url.searchParams.has("ll")) { // Get marker from ll param + // https://maps.google.com/?ll=38.882147,-76.99017 + console.log("ll life"); + + const [mlat, mlon] = url.searchParams.get("ll").split(","); + + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; } + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; } + } else if (url.searchParams.has("viewpoint")) { // Get marker from viewpoint param. + // https://www.google.com/maps/@?api=1&map_action=pano&viewpoint=48.857832,2.295226&heading=-45&pitch=38&fov=80 + console.log("viewpoint life"); + + const [mlat, mlon] = url.searchParams.get("viewpoint").split(","); + + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query=${mlat}%2C${mlon}`); return; } + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/#q=${mlat}%2C${mlon}`); return; } + } else { // Use query as search if present. + console.log("normal life"); + + let query; + if (url.searchParams.has("q")) query = url.searchParams.get("q"); + else if (url.searchParams.has("query")) query = url.searchParams.get("query"); + else if (url.pathname.match(placeRegex)) query = url.pathname.match(placeRegex)[1]; + + let prefsEncoded = new URLSearchParams(prefs).toString(); + if (query) { + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/search?query="${query}${mapCentre}&${prefsEncoded}`); return; } + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk/${query}`); return; } + } + } + + let prefsEncoded = new URLSearchParams(prefs).toString(); + console.log("mapCentre", mapCentre); + console.log("prefs", prefs); + console.log("prefsEncoded", prefsEncoded); + if (mapsFrontend == 'osm') { resolve(`${randomInstance}/${mapCentre}&${prefsEncoded}`); return; } + if (mapsFrontend == 'facil') { resolve(`${randomInstance}/${mapCentre}/Mpnk`); return; } +} + +async function initDefaults() { + await browser.storage.local.set({ + disableMaps: false, + mapsFrontend: 'osm', + mapsRedirects: redirects, + facilNormalRedirectsChecks: [...redirects.facil.normal], + facilNormalCustomRedirects: [], + }) +} + +export default { + redirect, + initDefaults, +}; diff --git a/src/assets/javascripts/medium.js b/src/assets/javascripts/medium.js new file mode 100644 index 00000000..7be6b0d1 --- /dev/null +++ b/src/assets/javascripts/medium.js @@ -0,0 +1,174 @@ +window.browser = window.browser || window.chrome; +import utils from './utils.js' + + +const targets = [ + // /(?:.*\.)*(? { + redirects.scribe = val; + scribeNormalRedirectsChecks = [...redirects.scribe.normal]; + for (const instance of r.cloudflareList) { + const a = scribeNormalRedirectsChecks.indexOf(instance); + if (a > -1) scribeNormalRedirectsChecks.splice(a, 1); + } + browser.storage.local.set({ + mediumRedirects: redirects, + scribeNormalRedirectsChecks + }) + }) +} + +let + disableMedium, + mediumRedirects, + scribeNormalRedirectsChecks, + scribeNormalCustomRedirects, + scribeTorRedirectsChecks, + scribeTorCustomRedirects, + mediumProtocol; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "disableMedium", + "mediumRedirects", + "scribeNormalRedirectsChecks", + "scribeNormalCustomRedirects", + "scribeTorRedirectsChecks", + "scribeTorCustomRedirects", + "mediumProtocol" + ], + r => { + disableMedium = r.disableMedium; + mediumRedirects = r.mediumRedirects; + scribeNormalRedirectsChecks = r.scribeNormalRedirectsChecks; + scribeNormalCustomRedirects = r.scribeNormalCustomRedirects; + scribeTorRedirectsChecks = r.scribeTorRedirectsChecks; + scribeTorCustomRedirects = r.scribeTorCustomRedirects; + mediumProtocol = r.mediumProtocol; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function redirect(url, type, initiator) { + if (disableMedium) return; + if (type != "main_frame" && "sub_frame" && "xmlhttprequest" && "other") return; + if (initiator && ( + [ + ...mediumRedirects.scribe.normal, + ...mediumRedirects.scribe.tor, + ...scribeNormalCustomRedirects, + ...scribeTorCustomRedirects, + ].includes(initiator.origin))) return; + + if (!targets.some(rx => rx.test(url.host))) return; + if (/^\/($|@[a-zA-Z.]{0,}(\/|)$)/.test(url.pathname)) return; + + let instancesList; + if (mediumProtocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects]; + else if (mediumProtocol == 'tor') instancesList = [...scribeTorRedirectsChecks, ...scribeTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList) + return `${randomInstance}${url.pathname}${url.search}`; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(url); + const all = [ + ...mediumRedirects.scribe.tor, + ...mediumRedirects.scribe.normal, + + ...scribeNormalCustomRedirects, + ...scribeTorCustomRedirects, + ]; + if (!all.includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (mediumProtocol == 'normal') instancesList = [...scribeNormalCustomRedirects, ...scribeNormalRedirectsChecks]; + else if (mediumProtocol == 'tor') instancesList = [...scribeTorCustomRedirects, ...scribeTorRedirectsChecks]; + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(data => { + let dataJson = JSON.parse(data); + redirects.scribe = dataJson.scribe; + browser.storage.local.get('cloudflareList', + async r => { + scribeNormalRedirectsChecks = [...redirects.scribe.normal]; + for (const instance of r.cloudflareList) { + let i = scribeNormalRedirectsChecks.indexOf(instance); + if (i > -1) scribeNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableMedium: false, + mediumRedirects: redirects, + + scribeNormalRedirectsChecks: scribeNormalRedirectsChecks, + scribeNormalCustomRedirects: [], + + scribeTorRedirectsChecks: [...redirects.scribe.tor], + scribeTorCustomRedirects: [], + + mediumProtocol: "normal", + }) + resolve(); + }) + }) + }) +} + +export default { + setRedirects, + redirect, + switchInstance, + initDefaults, +}; diff --git a/src/assets/javascripts/peertube.js b/src/assets/javascripts/peertube.js new file mode 100644 index 00000000..ed15bce9 --- /dev/null +++ b/src/assets/javascripts/peertube.js @@ -0,0 +1,155 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +let redirects = { + "simpleertube": { + "normal": [ + "https://tube.simple-web.org", + "https://tube.ftild3.org", + "https://stube.alefvanoon.xyz", + "https://st.phreedom.club", + "https://simpleertube.esmailelbob.xyz", + ], + "tor": [] + } +} +function setRedirects(val) { + redirects.simpleertube = val; + browser.storage.local.set({ peertubeTargetsRedirects: redirects }) + for (const item of simpleertubeNormalRedirectsChecks) + if (!redirects.simpleertube.normal.includes(item)) { + var index = simpleertubeNormalRedirectsChecks.indexOf(item); + if (index !== -1) simpleertubeNormalRedirectsChecks.splice(index, 1); + } + browser.storage.local.set({ simpleertubeNormalRedirectsChecks }) + + for (const item of simpleertubeTorRedirectsChecks) + if (!redirects.simpleertube.normal.includes(item)) { + var index = simpleertubeTorRedirectsChecks.indexOf(item); + if (index !== -1) simpleertubeTorRedirectsChecks.splice(index, 1); + } + browser.storage.local.set({ simpleertubeTorRedirectsChecks }) +} + +let + disablePeertubeTargets, + peertubeRedirects, + simpleertubeNormalRedirectsChecks, + simpleertubeNormalCustomRedirects, + simpleertubeTorRedirectsChecks, + simpleertubeTorCustomRedirects, + peerTubeTargets, + peertubeTargetsProtocol; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "disablePeertubeTargets", + "peertubeRedirects", + "simpleertubeNormalRedirectsChecks", + "simpleertubeNormalCustomRedirects", + "simpleertubeTorRedirectsChecks", + "simpleertubeTorCustomRedirects", + "peerTubeTargets", + "peertubeTargetsProtocol" + ], + r => { + disablePeertubeTargets = r.disablePeertubeTargets; + peertubeRedirects = r.peertubeRedirects; + simpleertubeNormalRedirectsChecks = r.simpleertubeNormalRedirectsChecks; + simpleertubeNormalCustomRedirects = r.simpleertubeNormalCustomRedirects; + simpleertubeTorRedirectsChecks = r.simpleertubeTorRedirectsChecks; + simpleertubeTorCustomRedirects = r.simpleertubeTorCustomRedirects; + peerTubeTargets = r.peerTubeTargets; + peertubeTargetsProtocol = r.peertubeTargetsProtocol; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function all() { + return [ + ...redirects.simpleertube.normal, + ...redirects.simpleertube.tor, + ...simpleertubeNormalCustomRedirects, + ...simpleertubeTorCustomRedirects, + ]; +} + +function redirect(url, type, initiator) { + if (disablePeertubeTargets) return; + if (initiator && (all().includes(initiator.origin) || peerTubeTargets.includes(initiator.host))) return; + let protocolHost = utils.protocolHost(url); + if (!peerTubeTargets.includes(protocolHost)) return; + if (type != "main_frame") return; + + let instancesList; + if (peertubeTargetsProtocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects]; + if (peertubeTargetsProtocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + if (url.host == 'search.joinpeertube.org' || url.host == 'sepiasearch.org') return randomInstance; + return `${randomInstance}/${url.host}${url.pathname}${url.search}`; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (peertubeTargetsProtocol == 'normal') instancesList = [...simpleertubeNormalRedirectsChecks, ...simpleertubeNormalCustomRedirects]; + else if (peertubeTargetsProtocol == 'tor') instancesList = [...simpleertubeTorRedirectsChecks, ...simpleertubeTorCustomRedirects]; + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + browser.storage.local.get('cloudflareList', async r => { + simpleertubeNormalRedirectsChecks = [...redirects.simpleertube.normal]; + for (const instance of r.cloudflareList) { + let i = simpleertubeNormalRedirectsChecks.indexOf(instance); + if (i > -1) simpleertubeNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + peerTubeTargets: ['https://search.joinpeertube.org', ...dataJson.peertube], + disablePeertubeTargets: true, + peertubeRedirects: redirects, + + simpleertubeNormalRedirectsChecks: simpleertubeNormalRedirectsChecks, + simpleertubeNormalCustomRedirects: [], + + simpleertubeTorRedirectsChecks: [...redirects.simpleertube.tor], + simpleertubeTorCustomRedirects: [], + + peertubeTargetsProtocol: "normal", + }) + resolve(); + }) + }) + }) +} + +export default { + setRedirects, + switchInstance, + redirect, + initDefaults, +}; diff --git a/src/assets/javascripts/reddit.js b/src/assets/javascripts/reddit.js new file mode 100644 index 00000000..0735ba64 --- /dev/null +++ b/src/assets/javascripts/reddit.js @@ -0,0 +1,378 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = [ + /^https?:\/{2}(www\.|old\.|np\.|new\.|amp\.|)reddit\.com/, + /^https?:\/{2}(i\.|preview\.)redd\.it/, +]; +let redirects = { + "libreddit": { + "normal": [], + "tor": [] + }, + "teddit": { + "normal": [], + "tor": [] + }, +}; +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects = val; + libredditNormalRedirectsChecks = [...redirects.libreddit.normal]; + tedditNormalRedirectsChecks = [...redirects.teddit.normal] + for (const instance of r.cloudflareList) { + const a = libredditNormalRedirectsChecks.indexOf(instance); + if (a > -1) libredditNormalRedirectsChecks.splice(a, 1); + + const b = tedditNormalRedirectsChecks.indexOf(instance); + if (b > -1) tedditNormalRedirectsChecks.splice(b, 1); + } + browser.storage.local.set({ + redditRedirects: redirects, + libredditNormalRedirectsChecks, + tedditNormalRedirectsChecks + }) + }) +} + +let + disableReddit, + redditFrontend, + redditRedirects, + redditProtocol, + libredditNormalRedirectsChecks, + libredditNormalCustomRedirects, + libredditTorRedirectsChecks, + libredditTorCustomRedirects, + tedditNormalRedirectsChecks, + tedditNormalCustomRedirects, + tedditTorRedirectsChecks, + tedditTorCustomRedirects; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "disableReddit", + "redditFrontend", + "redditRedirects", + "redditProtocol", + "libredditNormalRedirectsChecks", + "libredditNormalCustomRedirects", + "libredditTorRedirectsChecks", + "libredditTorCustomRedirects", + "tedditNormalRedirectsChecks", + "tedditNormalCustomRedirects", + "tedditTorRedirectsChecks", + "tedditTorCustomRedirects", + ], + r => { + disableReddit = r.disableReddit; + redditFrontend = r.redditFrontend; + redditRedirects = r.redditRedirects; + redditProtocol = r.redditProtocol; + libredditNormalRedirectsChecks = r.libredditNormalRedirectsChecks; + libredditNormalCustomRedirects = r.libredditNormalCustomRedirects; + libredditTorRedirectsChecks = r.libredditTorRedirectsChecks; + libredditTorCustomRedirects = r.libredditTorCustomRedirects; + tedditNormalRedirectsChecks = r.tedditNormalRedirectsChecks; + tedditNormalCustomRedirects = r.tedditNormalCustomRedirects; + tedditTorRedirectsChecks = r.tedditTorRedirectsChecks; + tedditTorCustomRedirects = r.tedditTorCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function initLibredditCookies(test, from) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(from); + if (![ + ...libredditNormalRedirectsChecks, + ...libredditTorRedirectsChecks, + ...libredditNormalCustomRedirects, + ...libredditTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + if (!test) { + let checkedInstances; + if (redditProtocol == 'normal') checkedInstances = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]; + else if (redditProtocol == 'tor') checkedInstances = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]; + for (const to of checkedInstances) { + utils.copyCookie('libreddit', from, to, "theme"); + utils.copyCookie('libreddit', from, to, "front_page"); + utils.copyCookie('libreddit', from, to, "layout"); + utils.copyCookie('libreddit', from, to, "wide"); + utils.copyCookie('libreddit', from, to, "post_sort"); + utils.copyCookie('libreddit', from, to, "comment_sort"); + utils.copyCookie('libreddit', from, to, "show_nsfw"); + utils.copyCookie('libreddit', from, to, "autoplay_videos"); + utils.copyCookie('libreddit', from, to, "use_hls"); + utils.copyCookie('libreddit', from, to, "hide_hls_notification"); + } + } + resolve(true); + }) +} + +function setLibredditCookies() { + return new Promise(async resolve => { + await init(); + if (disableReddit || redditFrontend != 'libreddit' || redditProtocol === undefined) { resolve(); return; } + let checkedInstances; + if (redditProtocol == 'normal') checkedInstances = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects] + else if (redditProtocol == 'tor') checkedInstances = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('libreddit', to, "theme"); + utils.getCookiesFromStorage('libreddit', to, "front_page"); + utils.getCookiesFromStorage('libreddit', to, "layout"); + utils.getCookiesFromStorage('libreddit', to, "wide"); + utils.getCookiesFromStorage('libreddit', to, "post_sort"); + utils.getCookiesFromStorage('libreddit', to, "comment_sort"); + utils.getCookiesFromStorage('libreddit', to, "show_nsfw"); + utils.getCookiesFromStorage('libreddit', to, "autoplay_videos"); + utils.getCookiesFromStorage('libreddit', to, "use_hls"); + utils.getCookiesFromStorage('libreddit', to, "hide_hls_notification"); + } + resolve(); + }) +} + +function initTedditCookies(test, from) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(from); + if (![ + ...tedditNormalRedirectsChecks, + ...tedditTorRedirectsChecks, + ...tedditNormalCustomRedirects, + ...tedditTorCustomRedirects, + ].includes(protocolHost)) resolve(); + + if (!test) { + let checkedInstances; + if (redditProtocol == 'normal') checkedInstances = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects] + else if (redditProtocol == 'tor') checkedInstances = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects] + for (const to of checkedInstances) { + utils.copyCookie('teddit', from, to, 'collapse_child_comments') + utils.copyCookie('teddit', from, to, 'domain_instagram') + utils.copyCookie('teddit', from, to, 'domain_twitter') + utils.copyCookie('teddit', from, to, 'domain_youtube') + utils.copyCookie('teddit', from, to, 'flairs') + utils.copyCookie('teddit', from, to, 'highlight_controversial') + utils.copyCookie('teddit', from, to, 'nsfw_enabled') + utils.copyCookie('teddit', from, to, 'post_media_max_height') + utils.copyCookie('teddit', from, to, 'show_upvoted_percentage') + utils.copyCookie('teddit', from, to, 'show_upvotes') + utils.copyCookie('teddit', from, to, 'theme') + utils.copyCookie('teddit', from, to, 'videos_muted') + } + } + resolve(true); + }) +} + +function setTedditCookies() { + return new Promise(async resolve => { + await init(); + if (disableReddit || redditFrontend != 'teddit' || redditProtocol === undefined) { resolve(); return; } + let checkedInstances; + if (redditProtocol == 'normal') checkedInstances = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects] + else if (redditProtocol == 'tor') checkedInstances = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('teddit', to, 'collapse_child_comments') + utils.getCookiesFromStorage('teddit', to, 'domain_instagram') + utils.getCookiesFromStorage('teddit', to, 'domain_twitter') + utils.getCookiesFromStorage('teddit', to, 'domain_youtube') + utils.getCookiesFromStorage('teddit', to, 'flairs') + utils.getCookiesFromStorage('teddit', to, 'highlight_controversial') + utils.getCookiesFromStorage('teddit', to, 'nsfw_enabled') + utils.getCookiesFromStorage('teddit', to, 'post_media_max_height') + utils.getCookiesFromStorage('teddit', to, 'show_upvoted_percentage') + utils.getCookiesFromStorage('teddit', to, 'show_upvotes') + utils.getCookiesFromStorage('teddit', to, 'theme') + utils.getCookiesFromStorage('teddit', to, 'videos_muted') + } + resolve(); + }) +} + +function all() { + return [ + ...redditRedirects.libreddit.normal, + ...redditRedirects.libreddit.tor, + ...redditRedirects.teddit.normal, + ...redditRedirects.teddit.tor, + ...libredditNormalCustomRedirects, + ...libredditTorCustomRedirects, + ...tedditNormalCustomRedirects, + ...tedditTorCustomRedirects, + ]; +} + +// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4 +// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png + +// https://teddit.net/vids/1mq8d0ma3yk81.mp4 +// https://teddit.net/pics/w:null_4v3t1vgvrzk81.png + + +// redd.it/t5379n +// https://v.redd.it/z08avb339n801/DASH_1_2_M +// https://i.redd.it/bfkhs659tzk81.jpg +function redirect(url, type, initiator) { + if (disableReddit) return; + if (!targets.some(rx => rx.test(url.href))) return; + if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; + const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/; + if (type !== "main_frame" || url.pathname.match(bypassPaths)) return; + + let libredditInstancesList; + let tedditInstancesList; + if (redditProtocol == 'normal') { + libredditInstancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]; + tedditInstancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects]; + } else if (redditProtocol == 'tor') { + libredditInstancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]; + tedditInstancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects]; + } + + if (url.host === "i.redd.it") { + if (redditFrontend == 'teddit') { + if (tedditInstancesList.length === 0) return; + let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList); + return `${tedditRandomInstance}/pics/w:null_${url.pathname.substring(1)}${url.reddit}`; + } + if (redditFrontend == 'libreddit') { + if (libredditInstancesList.length === 0) return; + let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList); + return `${libredditRandomInstance}/img${url.pathname}${url.reddit}` + } + } + else if (url.host === "redd.it") { + if (redditFrontend == 'libreddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) { + if (libredditInstancesList.length === 0) return; + let libredditRandomInstance = utils.getRandomInstance(libredditInstancesList); + // https://redd.it/foo => https://libredd.it/comments/foo + return `${libredditRandomInstance}/comments${url.pathname}${url.reddit}`; + } + if (redditFrontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) { + if (tedditInstancesList.length === 0) return; + let tedditRandomInstance = utils.getRandomInstance(tedditInstancesList); + // https://redd.it/foo => https://teddit.net/comments/foo + return `${tedditRandomInstance}/comments${url.pathname}${url.reddit}` + } + } + else if (url.host === 'preview.redd.it') { + if (redditFrontend == 'teddit') return; + if (redditFrontend == 'libreddit') { + if (libredditInstancesList.length === 0) return; + const libredditRandomInstance = utils.getRandomInstance(libredditInstancesList); + return `${libredditRandomInstance}/preview/pre${url.pathname}${url.reddit}`; + } + } + + let randomInstance; + if (redditFrontend == 'libreddit') { + if (libredditInstancesList.length === 0) return; + randomInstance = utils.getRandomInstance(libredditInstancesList); + } + if (redditFrontend == 'teddit') { + if (tedditInstancesList.length === 0) return; + randomInstance = utils.getRandomInstance(tedditInstancesList); + } + return `${randomInstance}${url.pathname}${url.search}`; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + let instancesList; + if (redditFrontend == 'libreddit') { + if (redditProtocol == 'normal') instancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects]; + else if (redditProtocol == 'tor') instancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects]; + if ([ + ...redditRedirects.teddit.normal, + ...redditRedirects.teddit.tor + ].includes(protocolHost)) url.pathname = url.pathname.replace("/pics/w:null_", "/img/"); + } + else if (redditFrontend == 'teddit') { + if (redditProtocol == 'normal') instancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects]; + else if (redditProtocol == 'tor') instancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects]; + if ([ + ...redditRedirects.libreddit.normal, + ...redditRedirects.libreddit.tor + ].includes(protocolHost) + ) url.pathname = url.pathname.replace("/img/", "/pics/w:null_"); + } + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.reddit}`); + }) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.teddit = dataJson.teddit; + redirects.libreddit = dataJson.libreddit; + browser.storage.local.get('cloudflareList', async r => { + libredditNormalRedirectsChecks = [...redirects.libreddit.normal]; + tedditNormalRedirectsChecks = [...redirects.teddit.normal] + for (const instance of r.cloudflareList) { + let i; + + i = libredditNormalRedirectsChecks.indexOf(instance); + if (i > -1) libredditNormalRedirectsChecks.splice(i, 1); + + i = tedditNormalRedirectsChecks.indexOf(instance); + if (i > -1) tedditNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableReddit: false, + redditProtocol: 'normal', + redditFrontend: 'libreddit', + redditRedirects: redirects, + + libredditNormalRedirectsChecks: libredditNormalRedirectsChecks, + libredditNormalCustomRedirects: [], + + libredditTorRedirectsChecks: [...redirects.libreddit.tor], + libredditTorCustomRedirects: [], + + tedditNormalRedirectsChecks: tedditNormalRedirectsChecks, + tedditNormalCustomRedirects: [], + + tedditTorRedirectsChecks: [...redirects.teddit.tor], + tedditTorCustomRedirects: [], + }); + resolve(); + }); + }); + }); +} + +export default { + setRedirects, + initLibredditCookies, + setLibredditCookies, + initTedditCookies, + setTedditCookies, + + redirect, + initDefaults, + switchInstance, +}; diff --git a/src/assets/javascripts/search.js b/src/assets/javascripts/search.js new file mode 100644 index 00000000..b32a8141 --- /dev/null +++ b/src/assets/javascripts/search.js @@ -0,0 +1,470 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = [ + /^https?:\/{2}(www\.|search\.|)google(\.[a-z]{2,3}){1,2}(\/search(\?.*|$)|\/$)/, + /^https?:\/{2}(www\.|www2\.|)bing\.com/, + /^https?:\/{2}yandex(\.[a-z]{2,3}){1,2}/, + /^https?:\/{2}search\.libredirect\.invalid/, +]; + +let redirects = { + "searx": { + "normal": [], + "tor": [], + "i2p": [] + }, + "searxng": { + "normal": [], + "tor": [], + "i2p": [] + }, + "whoogle": { + "normal": [], + "tor": [], + "i2p": [] + } +}; + +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects = val; + searxNormalRedirectsChecks = [...redirects.searx.normal]; + searxngNormalRedirectsChecks = [...redirects.searxng.normal]; + whoogleNormalRedirectsChecks = [...redirects.whoogle.normal]; + for (const instance of r.cloudflareList) { + const a = searxNormalRedirectsChecks.indexOf(instance); + if (a > -1) searxNormalRedirectsChecks.splice(a, 1); + + const b = searxngNormalRedirectsChecks.indexOf(instance); + if (b > -1) searxngNormalRedirectsChecks.splice(b, 1); + + const c = whoogleNormalRedirectsChecks.indexOf(instance); + if (c > -1) whoogleNormalRedirectsChecks.splice(c, 1); + } + browser.storage.local.set({ + searchRedirects: redirects, + searxNormalRedirectsChecks, + searxngNormalRedirectsChecks, + whoogleNormalRedirectsChecks, + }); + }) +} + +let + disableSearch, + searchFrontend, + searchRedirects, + searchProtocol, + whoogleNormalRedirectsChecks, + whoogleNormalCustomRedirects, + whoogleTorRedirectsChecks, + whoogleTorCustomRedirects, + whoogleI2pRedirectsChecks, + whoogleI2pCustomRedirects, + searxNormalRedirectsChecks, + searxNormalCustomRedirects, + searxTorRedirectsChecks, + searxTorCustomRedirects, + searxI2pRedirectsChecks, + searxI2pCustomRedirects, + searxngNormalRedirectsChecks, + searxngNormalCustomRedirects, + searxngTorRedirectsChecks, + searxngTorCustomRedirects, + searxngI2pRedirectsChecks, + searxngI2pCustomRedirects; + +function init() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + "disableSearch", + "searchFrontend", + "searchRedirects", + "searchProtocol", + "whoogleNormalRedirectsChecks", + "whoogleNormalCustomRedirects", + "whoogleTorRedirectsChecks", + "whoogleTorCustomRedirects", + "whoogleI2pRedirectsChecks", + "whoogleI2pCustomRedirects", + "searxNormalRedirectsChecks", + "searxNormalCustomRedirects", + "searxTorRedirectsChecks", + "searxTorCustomRedirects", + "searxI2pRedirectsChecks", + "searxI2pCustomRedirects", + "searxngNormalRedirectsChecks", + "searxngNormalCustomRedirects", + "searxngTorRedirectsChecks", + "searxngTorCustomRedirects", + "searxngI2pRedirectsChecks", + "searxngI2pCustomRedirects", + ], + r => { + disableSearch = r.disableSearch; + searchFrontend = r.searchFrontend; + searchRedirects = r.searchRedirects; + searchProtocol = r.searchProtocol; + whoogleNormalRedirectsChecks = r.whoogleNormalRedirectsChecks; + whoogleNormalCustomRedirects = r.whoogleNormalCustomRedirects; + whoogleTorRedirectsChecks = r.whoogleTorRedirectsChecks; + whoogleTorCustomRedirects = r.whoogleTorCustomRedirects; + whoogleI2pRedirectsChecks = r.whoogleI2pRedirectsChecks; + whoogleI2pCustomRedirects = r.whoogleI2pCustomRedirects; + searxNormalRedirectsChecks = r.searxNormalRedirectsChecks; + searxNormalCustomRedirects = r.searxNormalCustomRedirects; + searxTorRedirectsChecks = r.searxTorRedirectsChecks; + searxTorCustomRedirects = r.searxTorCustomRedirects; + searxI2pRedirectsChecks = r.searxI2pRedirectsChecks; + searxI2pCustomRedirects = r.searxI2pCustomRedirects; + searxngNormalRedirectsChecks = r.searxngNormalRedirectsChecks; + searxngNormalCustomRedirects = r.searxngNormalCustomRedirects; + searxngTorRedirectsChecks = r.searxngTorRedirectsChecks; + searxngTorCustomRedirects = r.searxngTorCustomRedirects; + searxngI2pRedirectsChecks = r.searxngI2pRedirectsChecks; + searxngI2pCustomRedirects = r.searxngI2pCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function initSearxCookies(test, from) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(from); + if (![ + ...searxNormalRedirectsChecks, + ...searxNormalCustomRedirects, + ...searxTorRedirectsChecks, + ...searxTorCustomRedirects, + ...searxI2pRedirectsChecks, + ...searxI2pCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + if (!test) { + let checkedInstances; + if (searchProtocol == 'normal') checkedInstances = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; + else if (searchProtocol == 'tor') checkedInstances = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; + else if (searchProtocol == 'i2p') checkedInstances = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; + for (const to of checkedInstances) { + utils.copyCookie('searx', from, to, 'advanced_search'); + utils.copyCookie('searx', from, to, 'autocomplete'); + utils.copyCookie('searx', from, to, 'categories'); + utils.copyCookie('searx', from, to, 'disabled_engines'); + utils.copyCookie('searx', from, to, 'disabled_plugins'); + utils.copyCookie('searx', from, to, 'doi_resolver'); + utils.copyCookie('searx', from, to, 'enabled_engines'); + utils.copyCookie('searx', from, to, 'enabled_plugins'); + utils.copyCookie('searx', from, to, 'image_proxy'); + utils.copyCookie('searx', from, to, 'language'); + utils.copyCookie('searx', from, to, 'locale'); + utils.copyCookie('searx', from, to, 'method'); + utils.copyCookie('searx', from, to, 'oscar-style'); + utils.copyCookie('searx', from, to, 'results_on_new_tab'); + utils.copyCookie('searx', from, to, 'safesearch'); + utils.copyCookie('searx', from, to, 'theme'); + utils.copyCookie('searx', from, to, 'tokens'); + } + } + resolve(true); + }) +} + +function setSearxCookies() { + return new Promise(async resolve => { + await init(); + if (disableSearch || searchFrontend != 'searx') { resolve(); return; } + let checkedInstances; + if (searchProtocol == 'normal') checkedInstances = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects] + else if (searchProtocol == 'tor') checkedInstances = [...searxTorRedirectsChecks, ...searxTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('searx', to, 'advanced_search'); + utils.getCookiesFromStorage('searx', to, 'autocomplete'); + utils.getCookiesFromStorage('searx', to, 'categories'); + utils.getCookiesFromStorage('searx', to, 'disabled_engines'); + utils.getCookiesFromStorage('searx', to, 'disabled_plugins'); + utils.getCookiesFromStorage('searx', to, 'doi_resolver'); + utils.getCookiesFromStorage('searx', to, 'enabled_engines'); + utils.getCookiesFromStorage('searx', to, 'enabled_plugins'); + utils.getCookiesFromStorage('searx', to, 'image_proxy'); + utils.getCookiesFromStorage('searx', to, 'language'); + utils.getCookiesFromStorage('searx', to, 'locale'); + utils.getCookiesFromStorage('searx', to, 'method'); + utils.getCookiesFromStorage('searx', to, 'oscar-style'); + utils.getCookiesFromStorage('searx', to, 'results_on_new_tab'); + utils.getCookiesFromStorage('searx', to, 'safesearch'); + utils.getCookiesFromStorage('searx', to, 'theme'); + utils.getCookiesFromStorage('searx', to, 'tokens'); + } + resolve(); + }) +} + +function initSearxngCookies(test, from) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(from); + if (![ + ...searxngNormalRedirectsChecks, + ...searxngNormalCustomRedirects, + ...searxngTorRedirectsChecks, + ...searxngTorCustomRedirects, + ...searxngI2pRedirectsChecks, + ...searxngI2pCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + if (!test) { + let checkedInstances; + if (searchProtocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; + else if (searchProtocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; + else if (searchProtocol == 'i2p') checkedInstances = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; + for (const to of checkedInstances) { + utils.copyCookie('searxng', from, to, 'autocomplete'); + utils.copyCookie('searxng', from, to, 'categories'); + utils.copyCookie('searxng', from, to, 'disabled_engines'); + utils.copyCookie('searxng', from, to, 'disabled_plugins'); + utils.copyCookie('searxng', from, to, 'doi_resolver'); + utils.copyCookie('searxng', from, to, 'enabled_plugins'); + utils.copyCookie('searxng', from, to, 'enabled_engines'); + utils.copyCookie('searxng', from, to, 'image_proxy'); + utils.copyCookie('searxng', from, to, 'infinite_scroll'); + utils.copyCookie('searxng', from, to, 'language'); + utils.copyCookie('searxng', from, to, 'locale'); + utils.copyCookie('searxng', from, to, 'maintab'); + utils.copyCookie('searxng', from, to, 'method'); + utils.copyCookie('searxng', from, to, 'query_in_title'); + utils.copyCookie('searxng', from, to, 'results_on_new_tab'); + utils.copyCookie('searxng', from, to, 'safesearch'); + utils.copyCookie('searxng', from, to, 'simple_style'); + utils.copyCookie('searxng', from, to, 'theme'); + utils.copyCookie('searxng', from, to, 'tokens'); + } + } + resolve(true); + }) +} + +function setSearxngCookies() { + return new Promise(async resolve => { + await init(); + if (disableSearch || searchFrontend != 'searxng', searchProtocol === undefined) { resolve(); return; } + let checkedInstances; + if (searchProtocol == 'normal') checkedInstances = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects] + else if (searchProtocol == 'tor') checkedInstances = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('searxng', to, 'autocomplete'); + utils.getCookiesFromStorage('searxng', to, 'categories'); + utils.getCookiesFromStorage('searxng', to, 'disabled_engines'); + utils.getCookiesFromStorage('searxng', to, 'disabled_plugins'); + utils.getCookiesFromStorage('searxng', to, 'doi_resolver'); + utils.getCookiesFromStorage('searxng', to, 'enabled_plugins'); + utils.getCookiesFromStorage('searxng', to, 'enabled_engines'); + utils.getCookiesFromStorage('searxng', to, 'image_proxy'); + utils.getCookiesFromStorage('searxng', to, 'infinite_scroll'); + utils.getCookiesFromStorage('searxng', to, 'language'); + utils.getCookiesFromStorage('searxng', to, 'locale'); + utils.getCookiesFromStorage('searxng', to, 'maintab'); + utils.getCookiesFromStorage('searxng', to, 'method'); + utils.getCookiesFromStorage('searxng', to, 'query_in_title'); + utils.getCookiesFromStorage('searxng', to, 'results_on_new_tab'); + utils.getCookiesFromStorage('searxng', to, 'safesearch'); + utils.getCookiesFromStorage('searxng', to, 'simple_style'); + utils.getCookiesFromStorage('searxng', to, 'theme'); + utils.getCookiesFromStorage('searxng', to, 'tokens'); + } + resolve(); + }) +} + + +function redirect(url) { + if (disableSearch) return; + if (!targets.some(rx => rx.test(url.href))) return; + if (url.searchParams.has('tbm')) return; + if (url.hostname.includes('google') && !url.searchParams.has('q') && url.pathname != '/') return; + let randomInstance; + let path; + if (searchFrontend == 'searx') { + let instancesList; + if (searchProtocol == 'normal') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; + else if (searchProtocol == 'tor') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; + else if (searchProtocol == 'i2p') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; + if (instancesList.length === 0) return; + randomInstance = utils.getRandomInstance(instancesList) + path = "/"; + } + else if (searchFrontend == 'searxng') { + let instancesList; + if (searchProtocol == 'normal') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; + else if (searchProtocol == 'tor') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; + else if (searchProtocol == 'i2p') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; + if (instancesList.length === 0) return; + randomInstance = utils.getRandomInstance(instancesList) + path = "/"; + } + else if (searchFrontend == 'whoogle') { + let instancesList; + if (searchProtocol == 'normal') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects]; + if (searchProtocol == 'tor') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]; + if (searchProtocol == 'i2p') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects]; + if (instancesList.length === 0) return; + randomInstance = utils.getRandomInstance(instancesList) + path = "/search"; + } + + if ( + ((url.hostname.includes('google') || url.hostname.includes('bing')) && !url.searchParams.has('q')) || + (url.hostname.includes('yandex') && !url.searchParams.has('text')) + ) path = '/'; + + let searchQuery = ""; + if ( + ( + url.hostname.includes('google') || + url.hostname.includes('bing') || + url.hostname.includes('search.libredirect.invalid') + ) && + url.searchParams.has('q') + ) searchQuery = `?q=${url.searchParams.get('q')}`; + if (url.hostname.includes('yandex') && url.searchParams.has('text')) searchQuery = `?q=${url.searchParams.get('text')}`; + + return `${randomInstance}${path}${searchQuery}`; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(url); + if (![ + ...searchRedirects.searx.normal, + ...searchRedirects.searx.tor, + ...searchRedirects.searx.i2p, + + ...searchRedirects.searxng.normal, + ...searchRedirects.searxng.tor, + ...searchRedirects.searxng.i2p, + + ...searchRedirects.whoogle.normal, + ...searchRedirects.whoogle.tor, + ...searchRedirects.whoogle.i2p, + + ...searxNormalCustomRedirects, + ...searxTorCustomRedirects, + ...searxI2pCustomRedirects, + + ...searxngNormalCustomRedirects, + ...searxngTorCustomRedirects, + ...searxngI2pCustomRedirects, + + ...whoogleNormalCustomRedirects, + ...whoogleTorCustomRedirects, + ...whoogleI2pCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (searchProtocol == 'normal') { + if (searchFrontend == 'searx') instancesList = [...searxNormalRedirectsChecks, ...searxNormalCustomRedirects]; + else if (searchFrontend == 'searxng') instancesList = [...searxngNormalRedirectsChecks, ...searxngNormalCustomRedirects]; + else if (searchFrontend == 'whoogle') instancesList = [...whoogleNormalRedirectsChecks, ...whoogleNormalCustomRedirects]; + } + else if (searchProtocol == 'tor') { + if (searchFrontend == 'searx') instancesList = [...searxTorRedirectsChecks, ...searxTorCustomRedirects]; + else if (searchFrontend == 'searxng') instancesList = [...searxngTorRedirectsChecks, ...searxngTorCustomRedirects]; + else if (searchFrontend == 'whoogle') instancesList = [...whoogleTorRedirectsChecks, ...whoogleTorCustomRedirects]; + } + else if (searchProtocol == 'i2p') { + if (searchFrontend == 'searx') instancesList = [...searxI2pRedirectsChecks, ...searxI2pCustomRedirects]; + else if (searchFrontend == 'searxng') instancesList = [...searxngI2pRedirectsChecks, ...searxngI2pCustomRedirects]; + else if (searchFrontend == 'whoogle') instancesList = [...whoogleI2pRedirectsChecks, ...whoogleI2pCustomRedirects]; + } + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(async resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.searx = dataJson.searx; + redirects.searxng = dataJson.searxng; + redirects.whoogle = dataJson.whoogle; + + browser.storage.local.get('cloudflareList', async r => { + whoogleNormalRedirectsChecks = [...redirects.whoogle.normal]; + searxNormalRedirectsChecks = [...redirects.searx.normal]; + searxngNormalRedirectsChecks = [...redirects.searxng.normal]; + for (const instance of r.cloudflareList) { + let i; + + i = whoogleNormalRedirectsChecks.indexOf(instance); + if (i > -1) whoogleNormalRedirectsChecks.splice(i, 1); + + i = searxNormalRedirectsChecks.indexOf(instance); + if (i > -1) searxNormalRedirectsChecks.splice(i, 1); + + i = searxngNormalRedirectsChecks.indexOf(instance); + if (i > -1) searxngNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableSearch: false, + searchFrontend: 'searxng', + searchRedirects: redirects, + searxngCustomSettings: false, + searchProtocol: 'normal', + + whoogleNormalRedirectsChecks: whoogleNormalRedirectsChecks, + whoogleNormalCustomRedirects: [], + + whoogleTorRedirectsChecks: [...redirects.whoogle.tor], + whoogleTorCustomRedirects: [], + + whoogleI2pRedirectsChecks: [...redirects.whoogle.i2p], + whoogleI2pCustomRedirects: [], + + searxNormalRedirectsChecks: searxNormalRedirectsChecks, + searxNormalCustomRedirects: [], + + searxTorRedirectsChecks: [...redirects.searx.tor], + searxTorCustomRedirects: [], + + searxI2pRedirectsChecks: [...redirects.searx.i2p], + searxI2pCustomRedirects: [], + + searxngNormalRedirectsChecks: searxngNormalRedirectsChecks, + searxngNormalCustomRedirects: [], + + searxngTorRedirectsChecks: [...redirects.searxng.tor], + searxngTorCustomRedirects: [], + + searxngI2pRedirectsChecks: [...redirects.searxng.i2p], + searxngI2pCustomRedirects: [], + }) + resolve(); + }) + }) + }) +} + +export default { + setRedirects, + initSearxCookies, + setSearxCookies, + initSearxngCookies, + setSearxngCookies, + redirect, + initDefaults, + switchInstance, +}; diff --git a/src/assets/javascripts/sendTargets.js b/src/assets/javascripts/sendTargets.js new file mode 100644 index 00000000..a3e87268 --- /dev/null +++ b/src/assets/javascripts/sendTargets.js @@ -0,0 +1,149 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = [ + /^https?:\/{2}send\.libredirect\.invalid\/$/, + /^ https ?: \/\/send\.firefox\.com\/$/, + /^https?:\/{2}sendfiles\.online\/$/ +]; + +let redirects = { + "send": { + "normal": [], + "tor": [] + } +} +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects.send = val; + sendNormalRedirectsChecks = [...redirects.send.normal]; + for (const instance of r.cloudflareList) { + const a = sendNormalRedirectsChecks.indexOf(instance); + if (a > -1) sendNormalRedirectsChecks.splice(a, 1); + } + browser.storage.local.set({ + sendTargetsRedirects: redirects, + sendNormalRedirectsChecks, + }) + }) +} + +let + disableSendTarget, + sendTargetsRedirects, + sendNormalRedirectsChecks, + sendNormalCustomRedirects, + sendTorRedirectsChecks, + sendTorCustomRedirects, + sendTargetsProtocol; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "disableSendTarget", + "sendTargetsRedirects", + "sendTargetsProtocol", + "sendNormalRedirectsChecks", + "sendNormalCustomRedirects", + "sendTorRedirectsChecks", + "sendTorCustomRedirects", + ], + r => { + disableSendTarget = r.disableSendTarget; + sendTargetsRedirects = r.sendTargetsRedirects; + sendNormalRedirectsChecks = r.sendNormalRedirectsChecks; + sendNormalCustomRedirects = r.sendNormalCustomRedirects; + sendTorRedirectsChecks = r.sendTorRedirectsChecks; + sendTorCustomRedirects = r.sendTorCustomRedirects; + sendTargetsProtocol = r.sendTargetsProtocol; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function all() { + return [ + ...sendTargetsRedirects.send.normal, + ...sendTargetsRedirects.send.tor, + ...sendNormalCustomRedirects, + ...sendTorRedirectsChecks, + ...sendTorCustomRedirects, + ]; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + if (url.pathname != '/') { resolve(); return; } + + let instancesList; + if (sendTargetsProtocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects]; + else if (sendTargetsProtocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects]; + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function redirect(url, type, initiator) { + if (disableSendTarget) return; + if (type != "main_frame") return; + if (initiator && (all().includes(initiator.origin) || targets.includes(initiator.host))) return; + if (!targets.some(rx => rx.test(url.href))) return; + + let instancesList; + if (sendTargetsProtocol == 'normal') instancesList = [...sendNormalRedirectsChecks, ...sendNormalCustomRedirects]; + if (sendTargetsProtocol == 'tor') instancesList = [...sendTorRedirectsChecks, ...sendTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + return randomInstance; +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.send = dataJson.send; + browser.storage.local.get('cloudflareList', async r => { + sendNormalRedirectsChecks = [...redirects.send.normal]; + for (const instance of r.cloudflareList) { + let i = sendNormalRedirectsChecks.indexOf(instance); + if (i > -1) sendNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableSendTarget: false, + sendTargetsRedirects: redirects, + + sendNormalRedirectsChecks: sendNormalRedirectsChecks, + sendNormalCustomRedirects: [], + + sendTorRedirectsChecks: [...redirects.send.tor], + sendTorCustomRedirects: [], + + sendTargetsProtocol: "normal", + }) + resolve(); + }) + }) + }) +} + +export default { + setRedirects, + redirect, + switchInstance, + initDefaults, +}; diff --git a/src/assets/javascripts/tiktok.js b/src/assets/javascripts/tiktok.js new file mode 100644 index 00000000..750744e6 --- /dev/null +++ b/src/assets/javascripts/tiktok.js @@ -0,0 +1,175 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = [ + /^https?:\/{2}(www\.|)tiktok\.com.*/ +]; + +let redirects = { + "proxiTok": { + "normal": [], + "tor": [] + } +} +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects.proxiTok = val; + proxiTokNormalRedirectsChecks = [...redirects.proxiTok.normal]; + for (const instance of r.cloudflareList) { + const a = proxiTokNormalRedirectsChecks.indexOf(instance); + if (a > -1) proxiTokNormalRedirectsChecks.splice(a, 1); + } + browser.storage.local.set({ + tiktokRedirects: redirects, + proxiTokNormalRedirectsChecks + }) + }) +} + +function initProxiTokCookies(test, from) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(from); + if (![ + ...proxiTokNormalRedirectsChecks, + ...proxiTokNormalCustomRedirects, + ...proxiTokTorRedirectsChecks, + ...proxiTokTorCustomRedirects, + ].includes(protocolHost)) resolve(); + + if (!test) { + let checkedInstances; + if (tiktokProtocol == 'normal') checkedInstances = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects] + else if (tiktokProtocol == 'tor') checkedInstances = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects] + for (const to of checkedInstances) { + utils.copyCookie('proxitok', from, to, 'theme'); + utils.copyCookie('proxitok', from, to, 'api-legacy'); + } + } + resolve(true); + }) +} + +function setProxiTokCookies() { + return new Promise(resolve => { + if (disableTiktok || tiktokProtocol === undefined) { resolve(); return; } + let checkedInstances; + if (tiktokProtocol == 'normal') checkedInstances = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects] + else if (tiktokProtocol == 'tor') checkedInstances = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('proxitok', to, 'theme'); + utils.getCookiesFromStorage('proxitok', to, 'api-legacy'); + } + resolve(); + }) +} + +let + disableTiktok, + tiktokProtocol, + tiktokRedirects, + proxiTokNormalRedirectsChecks, + proxiTokNormalCustomRedirects, + proxiTokTorRedirectsChecks, + proxiTokTorCustomRedirects; + +function init() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + "disableTiktok", + "tiktokProtocol", + "tiktokRedirects", + "proxiTokNormalRedirectsChecks", + "proxiTokNormalCustomRedirects", + "proxiTokTorRedirectsChecks", + "proxiTokTorCustomRedirects", + ], + r => { + disableTiktok = r.disableTiktok; + tiktokProtocol = r.tiktokProtocol; + tiktokRedirects = r.tiktokRedirects; + proxiTokNormalRedirectsChecks = r.proxiTokNormalRedirectsChecks; + proxiTokNormalCustomRedirects = r.proxiTokNormalCustomRedirects; + proxiTokTorRedirectsChecks = r.proxiTokTorRedirectsChecks; + proxiTokTorCustomRedirects = r.proxiTokTorCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +// https://www.tiktok.com/@keysikaspol/video/7061265241887345946 +// https://www.tiktok.com/@keysikaspol +function redirect(url, type, initiator) { + if (disableTiktok) return; + if (type != "main_frame") return; + const all = [ + ...tiktokRedirects.proxiTok.normal, + ...proxiTokNormalCustomRedirects + ]; + if (initiator && (all.includes(initiator.origin) || targets.includes(initiator.host))) return; + if (!targets.some(rx => rx.test(url.href))) return; + + let instancesList; + if (tiktokProtocol == 'normal') instancesList = [...proxiTokNormalRedirectsChecks, ...proxiTokNormalCustomRedirects]; + if (tiktokProtocol == 'tor') instancesList = [...proxiTokTorRedirectsChecks, ...proxiTokTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + return `${randomInstance}${url.pathname}`; +} + +function reverse(url) { + return new Promise(async resolve => { + await init(); + let protocolHost = utils.protocolHost(url); + const all = [ + ...tiktokRedirects.proxiTok.normal, + ...tiktokRedirects.proxiTok.tor, + ...proxiTokNormalCustomRedirects, + ...proxiTokTorCustomRedirects + ]; + if (!all.includes(protocolHost)) { resolve(); return; } + + resolve(`https://tiktok.com${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(async resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.proxiTok = dataJson.proxiTok; + await browser.storage.local.set({ + disableTiktok: false, + tiktokProtocol: "normal", + + tiktokRedirects: redirects, + + proxiTokNormalRedirectsChecks: [...redirects.proxiTok.normal], + proxiTokNormalCustomRedirects: [], + + proxiTokTorRedirectsChecks: [...redirects.proxiTok.tor], + proxiTokTorCustomRedirects: [], + }); + resolve(); + }); + }) +} + +export default { + setRedirects, + + redirect, + reverse, + + initProxiTokCookies, + setProxiTokCookies, + + initDefaults +}; diff --git a/src/assets/javascripts/translate/get_lingva_preferences.js b/src/assets/javascripts/translate/get_lingva_preferences.js new file mode 100644 index 00000000..f04ea3dc --- /dev/null +++ b/src/assets/javascripts/translate/get_lingva_preferences.js @@ -0,0 +1,10 @@ +window.browser = window.browser || window.chrome; + +browser.storage.local.set( + { + ['lingva_lingva_chakra-ui-color-mode']: localStorage.getItem('chakra-ui-color-mode'), + lingva_lingva_isauto: localStorage.getItem('isauto'), + lingva_lingva_source: localStorage.getItem('source'), + lingva_lingva_target: localStorage.getItem('target'), + } +) diff --git a/src/assets/javascripts/translate/set_lingva_preferences.js b/src/assets/javascripts/translate/set_lingva_preferences.js new file mode 100644 index 00000000..01a3b85e --- /dev/null +++ b/src/assets/javascripts/translate/set_lingva_preferences.js @@ -0,0 +1,19 @@ +window.browser = window.browser || window.chrome; + +browser.storage.local.get( + [ + "lingva_chakra-ui-color-mode", + "lingva_isauto", + "lingva_source", + "lingva_target", + ], + r => { + if (r['lingva_chakra-ui-color-mode'] !== undefined) localStorage.setItem('chakra-ui-color-mode', r['lingva_chakra-ui-color-mode']); + if (r.lingva_isauto !== undefined) localStorage.setItem('isauto', r.lingva_isauto); + console.log('r.lingva_isauto', r.lingva_isauto, localStorage.getItem('isauto')) + if (r.lingva_source !== undefined) localStorage.setItem('source', r.lingva_source); + if (r.lingva_target !== undefined) localStorage.setItem('target', r.lingva_target); + + window.close(); + } +) diff --git a/src/assets/javascripts/translate/translate.js b/src/assets/javascripts/translate/translate.js new file mode 100644 index 00000000..3c8f9222 --- /dev/null +++ b/src/assets/javascripts/translate/translate.js @@ -0,0 +1,295 @@ +window.browser = window.browser || window.chrome; + +import utils from '../utils.js' + +const targets = [ + /^https?:\/{2}translate\.google(\.[a-z]{2,3}){1,2}\//, +]; + +let redirects = { + "simplyTranslate": { + "normal": [], + "tor": [] + }, + "lingva": { + "normal": [], + "tor": [] + } +}; + +let + translateDisable, + translateFrontend, + translateProtocol, + translateRedirects, + simplyTranslateNormalRedirectsChecks, + simplyTranslateNormalCustomRedirects, + simplyTranslateTorRedirectsChecks, + simplyTranslateTorCustomRedirects, + lingvaNormalRedirectsChecks, + lingvaNormalCustomRedirects, + lingvaTorRedirectsChecks, + lingvaTorCustomRedirects; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "translateDisable", + "translateFrontend", + "translateProtocol", + "translateRedirects", + + "simplyTranslateNormalRedirectsChecks", + "simplyTranslateNormalCustomRedirects", + "simplyTranslateTorRedirectsChecks", + "simplyTranslateTorCustomRedirects", + + "lingvaNormalRedirectsChecks", + "lingvaNormalCustomRedirects", + "lingvaTorRedirectsChecks", + "lingvaTorCustomRedirects", + ], + r => { + translateDisable = r.translateDisable; + translateFrontend = r.translateFrontend; + translateProtocol = r.translateProtocol; + translateRedirects = r.translateRedirects; + simplyTranslateNormalRedirectsChecks = r.simplyTranslateNormalRedirectsChecks; + simplyTranslateNormalCustomRedirects = r.simplyTranslateNormalCustomRedirects; + simplyTranslateTorRedirectsChecks = r.simplyTranslateTorRedirectsChecks; + simplyTranslateTorCustomRedirects = r.simplyTranslateTorCustomRedirects; + lingvaNormalRedirectsChecks = r.lingvaNormalRedirectsChecks; + lingvaNormalCustomRedirects = r.lingvaNormalCustomRedirects; + lingvaTorRedirectsChecks = r.lingvaTorRedirectsChecks; + lingvaTorCustomRedirects = r.lingvaTorCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects = val; + simplyTranslateNormalRedirectsChecks = [...redirects.simplyTranslate.normal]; + lingvaNormalRedirectsChecks = [...redirects.lingva.normal] + for (const instance of r.cloudflareList) { + const a = simplyTranslateNormalRedirectsChecks.indexOf(instance); + if (a > -1) simplyTranslateNormalRedirectsChecks.splice(a, 1); + + const b = lingvaNormalRedirectsChecks.indexOf(instance); + if (b > -1) lingvaNormalRedirectsChecks.splice(b, 1); + } + browser.storage.local.set({ + translateRedirects: redirects, + simplyTranslateNormalRedirectsChecks, + simplyTranslateTorRedirectsChecks: redirects.simplyTranslate.tor, + lingvaNormalRedirectsChecks, + lingvaTorRedirectsChecks: redirects.lingva.tor, + }) + }) +} + +function initLingvaLocalStorage(test, url, tabId) { + return new Promise(async resolve => { + await init(); + if (translateDisable || translateFrontend != 'lingva') { resolve(); return; } + const protocolHost = utils.protocolHost(url); + if (![ + ...lingvaNormalRedirectsChecks, + ...lingvaNormalCustomRedirects, + ...lingvaTorRedirectsChecks, + ...lingvaTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + if (!test) { + browser.tabs.executeScript( + tabId, + { file: "/assets/javascripts/translate/get_lingva_preferences.js", runAt: "document_start" } + ); + + let checkedInstances; + if (translateProtocol == 'normal') checkedInstances = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]; + if (translateProtocol == 'tor') checkedInstances = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]; + const i = checkedInstances.indexOf(protocolHost); + if (i !== -1) checkedInstances.splice(i, 1); + if (checkedInstances.length === 0) { resolve(); return; } + for (const to of checkedInstances) + browser.tabs.create( + { url: to }, + tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/translate/set_lingva_preferences.js", runAt: "document_start" }) + ); + } + resolve(true); + } + ) +} + +function initSimplyTranslateCookies(test, from) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(from); + if (![ + ...simplyTranslateNormalRedirectsChecks, + ...simplyTranslateNormalCustomRedirects, + ...simplyTranslateTorRedirectsChecks, + ...simplyTranslateTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + if (!test) { + let checkedInstances; + if (translateProtocol == 'normal') checkedInstances = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects] + else if (translateProtocol == 'tor') checkedInstances = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects] + for (const to of checkedInstances) { + utils.copyCookie('simplyTranslate', from, to, 'from_lang'); + utils.copyCookie('simplyTranslate', from, to, 'to_lang'); + utils.copyCookie('simplyTranslate', from, to, 'tts_enabled'); + utils.copyCookie('simplyTranslate', from, to, 'use_text_fields'); + } + } + resolve(true); + } + ) +} + +function setSimplyTranslateCookies() { + return new Promise(async resolve => { + await init(); + if (translateDisable || translateFrontend != 'simplyTranslate') { resolve(); return; } + let checkedInstances; + if (translateProtocol == 'normal') checkedInstances = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects] + else if (translateProtocol == 'tor') checkedInstances = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('simplyTranslate', to, 'from_lang'); + utils.getCookiesFromStorage('simplyTranslate', to, 'to_lang'); + utils.getCookiesFromStorage('simplyTranslate', to, 'tts_enabled'); + utils.getCookiesFromStorage('simplyTranslate', to, 'use_text_fields'); + } + resolve(); + } + ) +} + +function redirect(url) { + if (translateDisable) return; + if (!targets.some(rx => rx.test(url.href))) return; + + if (translateFrontend == 'simplyTranslate') { + let instancesList; + if (translateProtocol == 'normal') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]; + if (translateProtocol == 'tor') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList) + return `${randomInstance}/${url.search}`; + } + else if (translateFrontend == 'lingva') { + let params_arr = url.search.split('&'); + params_arr[0] = params_arr[0].substring(1); + let params = {}; + for (let i = 0; i < params_arr.length; i++) { + let pair = params_arr[i].split('='); + params[pair[0]] = pair[1]; + } + let instancesList; + if (translateProtocol == 'normal') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]; + if (translateProtocol == 'tor') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList) + if (params.sl && params.tl && params.text) { + return `${randomInstance}/${params.sl}/${params.tl}/${params.text}` + } + return randomInstance; + } +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + if (translateDisable) { resolve(); return; } + const protocolHost = utils.protocolHost(url); + if (![ + ...translateRedirects.simplyTranslate.normal, + ...translateRedirects.simplyTranslate.tor, + + ...simplyTranslateNormalCustomRedirects, + ...simplyTranslateTorCustomRedirects, + + ...translateRedirects.lingva.normal, + ...translateRedirects.lingva.tor, + + ...lingvaNormalCustomRedirects, + ...lingvaTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (translateProtocol == 'normal') { + if (translateFrontend == 'simplyTranslate') instancesList = [...simplyTranslateNormalRedirectsChecks, ...simplyTranslateNormalCustomRedirects]; + else if (translateFrontend == 'lingva') instancesList = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects]; + } + else if (translateProtocol == 'tor') { + if (translateFrontend == 'simplyTranslate') instancesList = [...simplyTranslateTorRedirectsChecks, ...simplyTranslateTorCustomRedirects]; + else if (translateFrontend == 'lingva') instancesList = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects]; + } + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(async resolve => { + fetch('/instances/data.json').then(response => response.text()).then(data => { + let dataJson = JSON.parse(data); + redirects.simplyTranslate = dataJson.simplyTranslate; + redirects.lingva = dataJson.lingva; + browser.storage.local.get('cloudflareList', + async r => { + simplyTranslateNormalRedirectsChecks = [...redirects.simplyTranslate.normal]; + lingvaNormalRedirectsChecks = [...redirects.lingva.normal] + for (const instance of r.cloudflareList) { + const a = simplyTranslateNormalRedirectsChecks.indexOf(instance); + if (a > -1) simplyTranslateNormalRedirectsChecks.splice(a, 1); + + const b = lingvaNormalRedirectsChecks.indexOf(instance); + if (b > -1) lingvaNormalRedirectsChecks.splice(b, 1); + } + await browser.storage.local.set({ + translateDisable: false, + translateFrontend: "simplyTranslate", + translateProtocol: 'normal', + translateRedirects: redirects, + + simplyTranslateNormalRedirectsChecks: simplyTranslateNormalRedirectsChecks, + simplyTranslateNormalCustomRedirects: [], + simplyTranslateTorRedirectsChecks: [...redirects.simplyTranslate.tor], + simplyTranslateTorCustomRedirects: [], + + lingvaNormalRedirectsChecks: lingvaNormalRedirectsChecks, + lingvaNormalCustomRedirects: [], + lingvaTorRedirectsChecks: [...redirects.lingva.tor], + lingvaTorCustomRedirects: [], + }) + resolve(); + }) + }) + }) +} + +export default { + initSimplyTranslateCookies, + setSimplyTranslateCookies, + initLingvaLocalStorage, + setRedirects, + redirect, + initDefaults, + switchInstance, +}; diff --git a/src/assets/javascripts/twitter.js b/src/assets/javascripts/twitter.js new file mode 100644 index 00000000..d03c269f --- /dev/null +++ b/src/assets/javascripts/twitter.js @@ -0,0 +1,241 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = [ + /^https?:\/{2}(www\.|mobile\.|)twitter\.com/, + /^https?:\/{2}(pbs\.|video\.|)twimg\.com/, + /^https?:\/{2}platform\.twitter\.com\/embed/, + /^https?:\/{2}t\.co/ +]; + +let redirects = { + "nitter": { + "normal": [], + "tor": [] + }, +}; + +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects.nitter = val; + nitterNormalRedirectsChecks = [...redirects.nitter.normal]; + for (const instance of r.cloudflareList) { + let i = nitterNormalRedirectsChecks.indexOf(instance); + if (i > -1) nitterNormalRedirectsChecks.splice(i, 1); + } + browser.storage.local.set({ + twitterRedirects: redirects, + nitterNormalRedirectsChecks, + nitterTorRedirectsChecks: [...redirects.nitter.tor] + }) + }) +} + +let + disableTwitter, + twitterProtocol, + twitterRedirects, + nitterNormalRedirectsChecks, + nitterNormalCustomRedirects, + nitterTorRedirectsChecks, + nitterTorCustomRedirects; + +function init() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + "disableTwitter", + "twitterProtocol", + "twitterRedirects", + "nitterNormalRedirectsChecks", + "nitterNormalCustomRedirects", + "nitterTorRedirectsChecks", + "nitterTorCustomRedirects", + ], + r => { + disableTwitter = r.disableTwitter; + twitterProtocol = r.twitterProtocol; + twitterRedirects = r.twitterRedirects; + nitterNormalRedirectsChecks = r.nitterNormalRedirectsChecks; + nitterNormalCustomRedirects = r.nitterNormalCustomRedirects; + nitterTorRedirectsChecks = r.nitterTorRedirectsChecks; + nitterTorCustomRedirects = r.nitterTorCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function all() { + return [ + ...nitterNormalRedirectsChecks, + ...nitterTorRedirectsChecks, + ...nitterNormalCustomRedirects, + ...nitterTorCustomRedirects, + ]; +} + +function redirect(url, initiator) { + if (disableTwitter) return; + if (!targets.some(rx => rx.test(url.href))) return; + if (url.pathname.split("/").includes("home")) return; + if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; + + let instancesList; + if (twitterProtocol == 'normal') instancesList = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects]; + else if (twitterProtocol == 'tor') instancesList = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + // https://pbs.twimg.com/profile_images/648888480974508032/66_cUYfj_400x400.jpg + if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") + return `${randomInstance}/pic/${encodeURIComponent(`${url.host}${url.pathname}`)}`; + else if (url.pathname.split("/").includes("tweets")) + return `${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}`; + else if (url.host == 't.co') + return `${randomInstance}/t.co${url.pathname}`; + else + return `${randomInstance}${url.pathname}${url.search}`; +} + +function reverse(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + resolve(`https://twitter.com${url.pathname}${url.search}`); + }) +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + let instancesList; + if (twitterProtocol == 'normal') instancesList = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects]; + else if (twitterProtocol == 'tor') instancesList = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects]; + + let index = instancesList.indexOf(protocolHost); + if (index > -1) instancesList.splice(index, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function removeXFrameOptions(e) { + let url = new URL(e.url); + let protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost) || e.type != 'sub_frame') return; + let isChanged = false; + for (const i in e.responseHeaders) if (e.responseHeaders[i].name == 'x-frame-options') { + e.responseHeaders.splice(i, 1); + isChanged = true; + } + if (isChanged) return { responseHeaders: e.responseHeaders }; +} + +function initNitterCookies(test, from) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(from); + if (!all().includes(protocolHost) + ) { resolve(); return; } + + if (!test) { + let checkedInstances; + if (twitterProtocol == 'normal') checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects] + else if (twitterProtocol == 'tor') checkedInstances = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects] + for (const to of checkedInstances) { + utils.copyCookie('nitter', from, to, 'theme'); + utils.copyCookie('nitter', from, to, 'infiniteScroll'); + utils.copyCookie('nitter', from, to, 'stickyProfile'); + utils.copyCookie('nitter', from, to, 'bidiSupport'); + utils.copyCookie('nitter', from, to, 'hideTweetStats'); + utils.copyCookie('nitter', from, to, 'hideBanner'); + utils.copyCookie('nitter', from, to, 'hidePins'); + utils.copyCookie('nitter', from, to, 'hideReplies'); + utils.copyCookie('nitter', from, to, 'squareAvatars'); + utils.copyCookie('nitter', from, to, 'mp4Playback'); + utils.copyCookie('nitter', from, to, 'hlsPlayback'); + utils.copyCookie('nitter', from, to, 'proxyVideos'); + utils.copyCookie('nitter', from, to, 'muteVideos'); + utils.copyCookie('nitter', from, to, 'autoplayGifs'); + } + } + resolve(true); + }) +} + +function setNitterCookies() { + return new Promise(async resolve => { + await init(); + if (disableTwitter || twitterProtocol === undefined) { resolve(); return; } + let checkedInstances; + if (twitterProtocol == 'normal') checkedInstances = [...nitterNormalRedirectsChecks, ...nitterNormalCustomRedirects] + else if (twitterProtocol == 'tor') checkedInstances = [...nitterTorRedirectsChecks, ...nitterTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('nitter', to, 'theme'); + utils.getCookiesFromStorage('nitter', to, 'infiniteScroll'); + utils.getCookiesFromStorage('nitter', to, 'stickyProfile'); + utils.getCookiesFromStorage('nitter', to, 'bidiSupport'); + utils.getCookiesFromStorage('nitter', to, 'hideTweetStats'); + utils.getCookiesFromStorage('nitter', to, 'hideBanner'); + utils.getCookiesFromStorage('nitter', to, 'hidePins'); + utils.getCookiesFromStorage('nitter', to, 'hideReplies'); + utils.getCookiesFromStorage('nitter', to, 'squareAvatars'); + utils.getCookiesFromStorage('nitter', to, 'mp4Playback'); + utils.getCookiesFromStorage('nitter', to, 'hlsPlayback'); + utils.getCookiesFromStorage('nitter', to, 'proxyVideos'); + utils.getCookiesFromStorage('nitter', to, 'muteVideos'); + utils.getCookiesFromStorage('nitter', to, 'autoplayGifs'); + } + resolve(); + } + ) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(data => { + let dataJson = JSON.parse(data); + redirects.nitter = dataJson.nitter; + browser.storage.local.get('cloudflareList', async r => { + nitterNormalRedirectsChecks = [...redirects.nitter.normal]; + for (const instance of r.cloudflareList) { + let i = nitterNormalRedirectsChecks.indexOf(instance); + if (i > -1) nitterNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableTwitter: false, + twitterRedirects: redirects, + twitterProtocol: "normal", + + nitterNormalRedirectsChecks, + nitterNormalCustomRedirects: [], + + nitterTorRedirectsChecks: [...redirects.nitter.tor], + nitterTorCustomRedirects: [], + }) + resolve(); + }) + }) + }) +} + +export default { + setRedirects, + redirect, + switchInstance, + reverse, + removeXFrameOptions, + initNitterCookies, + setNitterCookies, + initDefaults, +}; diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js new file mode 100644 index 00000000..f1f18d9f --- /dev/null +++ b/src/assets/javascripts/utils.js @@ -0,0 +1,452 @@ +window.browser = window.browser || window.chrome; +import twitterHelper from "./twitter.js"; +import youtubeHelper from "./youtube/youtube.js"; +import instagramHelper from "./instagram.js"; +import mediumHelper from "./medium.js"; +import redditHelper from "./reddit.js"; +import searchHelper from "./search.js"; +import translateHelper from "./translate/translate.js"; +import wikipediaHelper from "./wikipedia.js"; +import peertubeHelper from "./peertube.js"; +import lbryHelper from "./lbry.js"; +import sendTargetsHelper from "./sendTargets.js"; +import tiktokHelper from "./tiktok.js"; +import imgurHelper from "./imgur.js"; +import localise from './localise.js' + +function getRandomInstance(instances) { + return instances[~~(instances.length * Math.random())]; +} + +let cloudflareList = []; +async function initCloudflareList() { + return new Promise(resolve => { + fetch('/instances/blocklist.json').then(response => response.text()).then(data => { + cloudflareList = JSON.parse(data); + resolve(); + }) + }); +} + +function updateInstances() { + return new Promise(async resolve => { + let http = new XMLHttpRequest(); + http.open('GET', 'https://raw.githubusercontent.com/libredirect/libredirect/master/src/instances/data.json', false); + http.send(null); + if (http.status === 200) { + await initCloudflareList(); + const instances = JSON.parse(http.responseText); + + youtubeHelper.setRedirects({ 'invidious': instances.invidious, 'piped': instances.piped, }) + twitterHelper.setRedirects(instances.nitter); + instagramHelper.setRedirects(instances.bibliogram); + redditHelper.setRedirects({ 'libreddit': instances.libreddit, 'teddit': instances.teddit }); + translateHelper.setRedirects({ "simplyTranslate": instances.simplyTranslate, "lingva": instances.lingva }); + searchHelper.setRedirects({ 'searx': instances.searx, 'searxng': instances.searxng, 'whoogle': instances.whoogle }); + wikipediaHelper.setRedirects(instances.wikiless); + mediumHelper.setRedirects(instances.scribe); + sendTargetsHelper.setRedirects(instances.send); + tiktokHelper.setRedirects(instances.proxiTok); + + console.info("Successfully updated Instances"); + resolve(true); return; + } + resolve() + }) +} + +function protocolHost(url) { + if (url.username && url.password) return `${url.protocol}//${url.username}:${url.password}@${url.host}`; + return `${url.protocol}//${url.host}`; +} + +async function processDefaultCustomInstances(target, name, protocol, document) { + + function camelCase(str) { + return str.charAt(0).toUpperCase() + str.slice(1); + } + let latencyKey = `${name}Latency`; + let instancesLatency; + await browser.storage.local.get(latencyKey, r => instancesLatency = r[latencyKey] ?? []); + let nameProtocolElement = document.getElementById(name).getElementsByClassName(protocol)[0]; + + let nameCustomInstances = []; + let nameCheckListElement = nameProtocolElement.getElementsByClassName('checklist')[0]; + + await initCloudflareList(); + + + let nameDefaultRedirects; + + let redirectsChecks = `${name}${camelCase(protocol)}RedirectsChecks`; + let customRedirects = `${name}${camelCase(protocol)}CustomRedirects`; + let redirectsKey = `${target}Redirects`; + + let redirects; + + async function getFromStorage() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + redirectsChecks, + customRedirects, + redirectsKey + ], + r => { + nameDefaultRedirects = r[redirectsChecks]; + nameCustomInstances = r[customRedirects]; + redirects = r[redirectsKey]; + resolve(); + } + ) + }) + } + await getFromStorage(); + + function calcNameCheckBoxes() { + let isTrue = true; + for (const item of redirects[name][protocol]) + if (!nameDefaultRedirects.includes(item)) { + isTrue = false; + break; + } + for (const element of nameCheckListElement.getElementsByTagName('input')) + element.checked = nameDefaultRedirects.includes(element.className) + if (nameDefaultRedirects.length == 0) isTrue = false; + nameProtocolElement.getElementsByClassName('toogle-all')[0].checked = isTrue; + } + nameCheckListElement.innerHTML = + [ + `
+ Toggle All + +
`, + ...redirects[name][protocol].map( + x => { + let cloudflare = cloudflareList.includes(x) ? ' cloudflare' : ''; + + let ms = instancesLatency[x]; + let latencyColor = (ms <= 1000 ? "green" : ms <= 2000 ? "orange" : "red"); + let latencyLimit; + if (ms == 5000) latencyLimit = '5000ms+'; + else if (ms > 5000) latencyLimit = `ERROR: ${ms - 5000}`; + else latencyLimit = ms + 'ms'; + + let latency = x in instancesLatency ? '' + latencyLimit + '' : ''; + + return `
+ ${x}${cloudflare} ${latency} + +
`; + } + ), + ].join('\n
\n'); + + localise.localisePage(); + + calcNameCheckBoxes(); + nameProtocolElement.getElementsByClassName('toogle-all')[0].addEventListener("change", async event => { + if (event.target.checked) + nameDefaultRedirects = [...redirects[name][protocol]]; + else + nameDefaultRedirects = []; + + await browser.storage.local.set({ [redirectsChecks]: nameDefaultRedirects }); + calcNameCheckBoxes(); + }); + + for (let element of nameCheckListElement.getElementsByTagName('input')) { + if (element.className != 'toogle-all') + nameProtocolElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { + if (event.target.checked) + nameDefaultRedirects.push(element.className) + else { + let index = nameDefaultRedirects.indexOf(element.className); + if (index > -1) nameDefaultRedirects.splice(index, 1); + } + await browser.storage.local.set({ [redirectsChecks]: nameDefaultRedirects }); + calcNameCheckBoxes(); + }); + } + + function calcNameCustomInstances() { + nameProtocolElement.getElementsByClassName('custom-checklist')[0].innerHTML = + nameCustomInstances.map( + x => `
+ ${x} + +
+
` + ).join('\n'); + + for (const item of nameCustomInstances) { + nameProtocolElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { + let index = nameCustomInstances.indexOf(item); + if (index > -1) nameCustomInstances.splice(index, 1); + await browser.storage.local.set({ [customRedirects]: nameCustomInstances }); + calcNameCustomInstances(); + }); + } + } + calcNameCustomInstances(); + nameProtocolElement.getElementsByClassName('custom-instance-form')[0].addEventListener("submit", async event => { + event.preventDefault(); + let nameCustomInstanceInput = nameProtocolElement.getElementsByClassName('custom-instance')[0]; + let url = new URL(nameCustomInstanceInput.value); + let protocolHostVar = protocolHost(url); + if (nameCustomInstanceInput.validity.valid && !redirects[name][protocol].includes(protocolHostVar)) { + if (!nameCustomInstances.includes(protocolHostVar)) { + nameCustomInstances.push(protocolHostVar) + await browser.storage.local.set({ [customRedirects]: nameCustomInstances }); + nameCustomInstanceInput.value = ''; + } + calcNameCustomInstances(); + } + }) +} + +function getIp(href) { + return new Promise(resolve => { + let host = new URL(href).hostname; + let http = new XMLHttpRequest(); + http.open("GET", `https://dns.google/resolve?name=${host}`, /*async*/true); + http.onreadystatechange = () => { + if (http.readyState == 4 && http.status == 200) { + let r = JSON.parse(http.responseText); + resolve(r.Answer[0].data) + } + }; + http.ontimeout = () => resolve() + http.onerror = () => resolve() + try { + http.send(null) + } + catch (exception) { + resolve() + } + }) +} + +async function ping(href) { + return new Promise(async resolve => { + let http = new XMLHttpRequest(); + http.open("GET", `${href}?_=${new Date().getTime()}`, /*async*/true); + http.timeout = 5000; + let started = new Date().getTime(); + http.onreadystatechange = () => { + if (http.readyState == 2) { + if (http.status == 200) { + let ended = new Date().getTime(); + http.abort(); + resolve(ended - started); + } + else + resolve(5000 + http.status) + } + }; + http.ontimeout = () => resolve(5000) + http.onerror = () => resolve() + try { + http.send(null); + } catch (exception) { + resolve() + } + }); +} + +async function testLatency(element, instances) { + return new Promise(async resolve => { + let myList = {}; + for (const href of instances) await ping(href).then(m => { + if (m) { + myList[href] = m; + let color; + if (m <= 1000) color = "green" + else if (m <= 2000) color = "orange" + else color = "red"; + + let text; + if (m == 5000) text = '5000ms+' + else if (m > 5000) text = `ERROR: ${m - 5000}`; + else text = `${m}ms`; + element.innerHTML = `${href}: ${text}`; + } + }) + resolve(myList); + }) +} + +function copyCookie(frontend, targetUrl, url, name) { + browser.cookies.get( + { url: protocolHost(targetUrl), name: name }, + r => { + if (r) { + browser.cookies.set({ url: url, name: name, value: r.value }) + browser.storage.local.set({ [`${frontend}_${name}`]: r.value }) + } + } + ) +} + +function getCookiesFromStorage(frontend, to, name) { + let key = `${frontend}_${name}`; + browser.storage.local.get( + key, + r => { + if (r[key] !== undefined) browser.cookies.set({ url: to, name: name, value: r[key] }) + } + ) +} + +function copyRaw(test, copyRawElement) { + return new Promise(resolve => { + browser.tabs.query( + { active: true, currentWindow: true }, async tabs => { + let currTab = tabs[0]; + if (currTab) { + let url; + try { url = new URL(currTab.url); } + catch { resolve(); return; } + + let newUrl = await youtubeHelper.reverse(url); + if (!newUrl) newUrl = await twitterHelper.reverse(url); + if (!newUrl) newUrl = await instagramHelper.reverse(url); + if (!newUrl) newUrl = await tiktokHelper.reverse(url); + if (!newUrl) newUrl = await imgurHelper.reverse(url); + + if (newUrl) { + resolve(true); + if (test) return; + navigator.clipboard.writeText(newUrl); + if (copyRawElement) { + const textElement = copyRawElement.getElementsByTagName('h4')[0] + const oldHtml = textElement.innerHTML; + textElement.innerHTML = browser.i18n.getMessage('copied'); + setTimeout(() => textElement.innerHTML = oldHtml, 1000); + } + } else resolve() + } + } + ) + }) +} + +function unify(test) { + return new Promise(resolve => { + browser.tabs.query( + { active: true, currentWindow: true }, + async tabs => { + let currTab = tabs[0] + if (currTab) { + let url; + try { url = new URL(currTab.url); } + catch { resolve(); return; } + + let result = await youtubeHelper.initInvidiousCookies(test, url); + if (!result) result = await youtubeHelper.initPipedLocalStorage(test, url, currTab.id); + if (!result) result = await youtubeHelper.initPipedMaterialLocalStorage(test, url, currTab.id); + + if (!result) result = await twitterHelper.initNitterCookies(test, url); + + if (!result) result = await redditHelper.initLibredditCookies(test, url); + if (!result) result = await redditHelper.initTedditCookies(test, url); + + if (!result) result = await searchHelper.initSearxCookies(test, url); + if (!result) result = await searchHelper.initSearxngCookies(test, url); + + if (!result) result = await tiktokHelper.initProxiTokCookies(test, url); + + if (!result) result = await wikipediaHelper.initWikilessCookies(test, url); + + if (!result) result = await translateHelper.initSimplyTranslateCookies(test, url); + if (!result) result = await translateHelper.initLingvaLocalStorage(test, url); + + if (result) { + resolve(true); + } else resolve() + } + } + ) + }) +} + +function switchInstance(test) { + return new Promise(resolve => { + browser.tabs.query({ active: true, currentWindow: true }, async tabs => { + let currTab = tabs[0]; + if (currTab) { + let url; + try { url = new URL(currTab.url); } + catch { resolve(); return }; + let newUrl = await youtubeHelper.switchInstance(url); + if (!newUrl) newUrl = await twitterHelper.switchInstance(url); + if (!newUrl) newUrl = await instagramHelper.switchInstance(url); + if (!newUrl) newUrl = await redditHelper.switchInstance(url); + if (!newUrl) newUrl = await searchHelper.switchInstance(url); + if (!newUrl) newUrl = await translateHelper.switchInstance(url); + if (!newUrl) newUrl = await mediumHelper.switchInstance(url); + if (!newUrl) newUrl = await sendTargetsHelper.switchInstance(url); + if (!newUrl) newUrl = await peertubeHelper.switchInstance(url); + if (!newUrl) newUrl = await lbryHelper.switchInstance(url); + if (!newUrl) newUrl = await imgurHelper.switchInstance(url); + if (!newUrl) newUrl = await wikipediaHelper.switchInstance(url); + + if (newUrl) { + if (!test) + browser.tabs.update({ url: newUrl }); + resolve(true) + } else resolve() + } + }) + }) +} + +function latency(name, frontend, document, location, splitNames) { + let latencyElement; + let latencyLabel; + if (splitNames == true) { + latencyElement = document.getElementById(`latency-${frontend}`); + latencyLabel = document.getElementById(`latency-${frontend}-label`); + } else { + latencyElement = document.getElementById("latency"); + latencyLabel = document.getElementById("latency-label"); + } + latencyElement.addEventListener("click", + async () => { + let reloadWindow = () => location.reload(); + latencyElement.addEventListener("click", reloadWindow); + let key = `${name}Redirects` + browser.storage.local.get( + key, + r => { + let redirects = r[key]; + const oldHtml = latencyLabel.innerHTML; + latencyLabel.innerHTML = '...'; + testLatency(latencyLabel, redirects[frontend].normal).then(r => { + browser.storage.local.set({ [`${frontend}Latency`]: r }); + latencyLabel.innerHTML = oldHtml; + processDefaultCustomInstances(name, frontend, 'normal', document); + latencyElement.removeEventListener("click", reloadWindow) + }); + } + ) + } + ); +} + +export default { + getRandomInstance, + updateInstances, + protocolHost, + processDefaultCustomInstances, + latency, + copyCookie, + getCookiesFromStorage, + switchInstance, + copyRaw, + unify, +} diff --git a/src/assets/javascripts/wikipedia.js b/src/assets/javascripts/wikipedia.js new file mode 100644 index 00000000..868bb01c --- /dev/null +++ b/src/assets/javascripts/wikipedia.js @@ -0,0 +1,220 @@ +window.browser = window.browser || window.chrome; + +import utils from './utils.js' + +const targets = /^https?:\/{2}(([a-z]{1,}\.){0,})wikipedia\.org/ + +let redirects = { + "wikiless": { + "normal": [], + "tor": [], + "i2p": [] + } +}; +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects.wikiless = val; + wikilessNormalRedirectsChecks = [...redirects.wikiless.normal]; + for (const instance of r.cloudflareList) { + const a = wikilessNormalRedirectsChecks.indexOf(instance); + if (a > -1) wikilessNormalRedirectsChecks.splice(a, 1); + } + browser.storage.local.set({ + wikipediaRedirects: redirects, + wikilessNormalRedirectsChecks + }) + }) +} + +let + disableWikipedia, + wikipediaRedirects, + wikipediaProtocol, + wikilessNormalRedirectsChecks, + wikilessTorRedirectsChecks, + wikilessI2pRedirectsChecks, + wikilessNormalCustomRedirects, + wikilessTorCustomRedirects, + wikilessI2pCustomRedirects; + +function init() { + return new Promise(async resolve => { + browser.storage.local.get( + [ + "disableWikipedia", + "wikipediaRedirects", + "wikipediaProtocol", + + "wikilessNormalRedirectsChecks", + "wikilessTorRedirectsChecks", + "wikilessI2pRedirectsChecks", + "wikilessNormalCustomRedirects", + "wikilessTorCustomRedirects", + "wikilessI2pCustomRedirects", + ], + r => { + disableWikipedia = r.disableWikipedia; + wikipediaRedirects = r.wikipediaRedirects; + wikipediaProtocol = r.wikipediaProtocol; + wikilessNormalRedirectsChecks = r.wikilessNormalRedirectsChecks; + wikilessTorRedirectsChecks = r.wikilessTorRedirectsChecks; + wikilessI2pRedirectsChecks = r.wikilessI2pRedirectsChecks; + wikilessNormalCustomRedirects = r.wikilessNormalCustomRedirects; + wikilessTorCustomRedirects = r.wikilessTorCustomRedirects; + wikilessI2pCustomRedirects = r.wikilessI2pCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function initWikilessCookies(test, from) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(from); + const all = [ + ...wikilessNormalRedirectsChecks, + ...wikilessNormalCustomRedirects, + ...wikilessTorRedirectsChecks, + ...wikilessTorCustomRedirects, + ...wikilessI2pRedirectsChecks, + ...wikilessI2pCustomRedirects, + ]; + if (!all.includes(protocolHost)) { resolve(); return; } + + if (!test) { + let checkedInstances; + if (wikipediaProtocol == 'normal') checkedInstances = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects] + else if (wikipediaProtocol == 'tor') checkedInstances = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects] + else if (wikipediaProtocol == 'i2p') checkedInstances = [...wikilessI2pRedirectsChecks, ...wikilessI2pCustomRedirects] + + for (const to of checkedInstances) { + utils.copyCookie('wikiless', from, to, 'theme'); + utils.copyCookie('wikiless', from, to, 'default_lang'); + } + } + resolve(true); + }) +} + +function setWikilessCookies() { + return new Promise(async resolve => { + await init(); + if (disableWikipedia || wikipediaProtocol === undefined) { resolve(); return; } + let checkedInstances; + if (wikipediaProtocol == 'normal') checkedInstances = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects] + else if (wikipediaProtocol == 'tor') checkedInstances = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects] + for (const to of checkedInstances) { + utils.getCookiesFromStorage('wikiless', to, 'theme'); + utils.getCookiesFromStorage('wikiless', to, 'default_lang'); + } + resolve(); + }) +} + +function redirect(url) { + if (disableWikipedia) return; + if (!targets.test(url.href)) return; + + let GETArguments = []; + if (url.search.length > 0) { + let search = url.search.substring(1); //get rid of '?' + let argstrings = search.split("&"); + for (let i = 0; i < argstrings.length; i++) { + let args = argstrings[i].split("="); + GETArguments.push([args[0], args[1]]); + } + } + let instancesList; + if (wikipediaProtocol == 'normal') instancesList = [...wikilessNormalRedirectsChecks, ...wikilessNormalCustomRedirects]; + else if (wikipediaProtocol == 'tor') instancesList = [...wikilessTorRedirectsChecks, ...wikilessTorCustomRedirects]; + else if (wikipediaProtocol == 'i2p') instancesList = [...wikilessI2pRedirectsChecks, ...wikilessI2pCustomRedirects]; + if (instancesList.length === 0) return; + const randomInstance = utils.getRandomInstance(instancesList) + + let link = `${randomInstance}${url.pathname}`; + let urlSplit = url.host.split("."); + if (urlSplit[0] != "wikipedia" && urlSplit[0] != "www") { + if (urlSplit[0] == "m") + GETArguments.push(["mobileaction", "toggle_view_mobile"]); + else + GETArguments.push(["lang", urlSplit[0]]); + if (urlSplit[1] == "m") + GETArguments.push(["mobileaction", "toggle_view_mobile"]); + // wikiless doesn't have mobile view support yet + } + for (let i = 0; i < GETArguments.length; i++) + link += (i == 0 ? "?" : "&") + GETArguments[i][0] + "=" + GETArguments[i][1]; + return link; +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + const wikipediaList = [ + ...wikipediaRedirects.wikiless.normal, + ...wikipediaRedirects.wikiless.tor, + ...wikipediaRedirects.wikiless.i2p, + + ...wikilessNormalCustomRedirects, + ...wikilessTorCustomRedirects, + ...wikilessI2pCustomRedirects + ]; + if (!wikipediaList.includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (wikipediaProtocol == 'normal') instancesList = [...wikilessNormalCustomRedirects, ...wikilessNormalRedirectsChecks]; + else if (wikipediaProtocol == 'tor') instancesList = [...wikilessTorCustomRedirects, ...wikilessTorRedirectsChecks]; + else if (wikipediaProtocol == 'i2p') instancesList = [...wikilessI2pCustomRedirects, ...wikilessI2pRedirectsChecks]; + + let index = instancesList.indexOf(protocolHost); + if (index > -1) instancesList.splice(index, 1); + if (instancesList.length === 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.wikiless = dataJson.wikiless; + browser.storage.local.get('cloudflareList', async r => { + wikilessNormalRedirectsChecks = [...redirects.wikiless.normal]; + for (const instance of r.cloudflareList) { + let i = wikilessNormalRedirectsChecks.indexOf(instance); + if (i > -1) wikilessNormalRedirectsChecks.splice(i, 1); + } + await browser.storage.local.set({ + disableWikipedia: true, + wikipediaRedirects: redirects, + wikipediaProtocol: "normal", + wikilessNormalRedirectsChecks: wikilessNormalRedirectsChecks, + wikilessTorRedirectsChecks: [...redirects.wikiless.tor], + wikilessI2pRedirectsChecks: [...redirects.wikiless.i2p], + wikilessNormalCustomRedirects: [], + wikilessTorCustomRedirects: [], + wikilessI2pCustomRedirects: [], + }) + resolve(); + }) + }) + }) +} + +export default { + setRedirects, + + initWikilessCookies, + setWikilessCookies, + + redirect, + initDefaults, + switchInstance, +}; diff --git a/src/assets/javascripts/youtube/get_pipedMaterial_preferences.js b/src/assets/javascripts/youtube/get_pipedMaterial_preferences.js new file mode 100644 index 00000000..9d052f62 --- /dev/null +++ b/src/assets/javascripts/youtube/get_pipedMaterial_preferences.js @@ -0,0 +1,7 @@ +window.browser = window.browser || window.chrome; + +browser.storage.local.set( + { + 'pipedMaterial_PREFERENCES': localStorage.getItem("PREFERENCES") + } +) \ No newline at end of file diff --git a/src/assets/javascripts/youtube/get_piped_preferences.js b/src/assets/javascripts/youtube/get_piped_preferences.js new file mode 100644 index 00000000..417d64df --- /dev/null +++ b/src/assets/javascripts/youtube/get_piped_preferences.js @@ -0,0 +1,24 @@ +window.browser = window.browser || window.chrome; + +browser.storage.local.set( + { + 'piped_bufferGoal': localStorage.getItem("bufferGoal"), + 'piped_comments': localStorage.getItem("comments"), + 'piped_disableLBRY': localStorage.getItem("disableLBRY"), + 'piped_enabledCodecs': localStorage.getItem("enabledCodecs"), + 'piped_hl': localStorage.getItem("hl"), + 'piped_homepage': localStorage.getItem("homepage"), + 'piped_instance': localStorage.getItem("instance"), + 'piped_listen': localStorage.getItem("listen"), + 'piped_minimizeDescription': localStorage.getItem("minimizeDescription"), + 'piped_playerAutoPlay': localStorage.getItem("playerAutoPlay"), + 'piped_proxyLBRY': localStorage.getItem("proxyLBRY"), + 'piped_quality': localStorage.getItem("quality"), + 'piped_region': localStorage.getItem("region"), + 'piped_selectedSkip': localStorage.getItem("selectedSkip"), + 'piped_sponsorblock': localStorage.getItem("sponsorblock"), + 'piped_theme': localStorage.getItem("theme"), + 'piped_volume': localStorage.getItem("volume"), + 'piped_watchHistory': localStorage.getItem("watchHistory"), + } +) diff --git a/src/assets/javascripts/youtube/set_pipedMaterial_preferences.js b/src/assets/javascripts/youtube/set_pipedMaterial_preferences.js new file mode 100644 index 00000000..7415255a --- /dev/null +++ b/src/assets/javascripts/youtube/set_pipedMaterial_preferences.js @@ -0,0 +1,10 @@ +window.browser = window.browser || window.chrome; + +browser.storage.local.get( + "pipedMaterial_PREFERENCES", + r => { + if (r.pipedMaterial_PREFERENCES !== undefined) localStorage.setItem("PREFERENCES", r.pipedMaterial_PREFERENCES) + + window.close(); + } +) \ No newline at end of file diff --git a/src/assets/javascripts/youtube/set_piped_preferences.js b/src/assets/javascripts/youtube/set_piped_preferences.js new file mode 100644 index 00000000..d5ce49ff --- /dev/null +++ b/src/assets/javascripts/youtube/set_piped_preferences.js @@ -0,0 +1,44 @@ +window.browser = window.browser || window.chrome; + +browser.storage.local.get( + [ + "piped_bufferGoal", + "piped_comments", + "piped_disableLBRY", + "piped_enabledCodecs", + "piped_homepage", + "piped_listen", + "piped_minimizeDescription", + "piped_playerAutoPlay", + "piped_proxyLBRY", + "piped_quality", + "piped_region", + "piped_selectedSkip", + "piped_sponsorblock", + "piped_theme", + "piped_volume", + "piped_watchHistory", + ], + r => { + if (r.piped_bufferGoal !== undefined) localStorage.setItem("bufferGoal", r.piped_bufferGoal); + if (r.piped_comments !== undefined) localStorage.setItem("comments", r.piped_comments); + if (r.piped_disableLBRY !== undefined) localStorage.setItem("disableLBRY", r.piped_disableLBRY); + if (r.piped_hl !== undefined) localStorage.setItem("hl", r.piped_hl); + if (r.piped_enabledCodecs !== undefined) localStorage.setItem("enabledCodecs", r.piped_enabledCodecs); + if (r.piped_homepage !== undefined) localStorage.setItem("homepage", r.piped_homepage); + if (r.piped_instance !== undefined) localStorage.setItem("instance", r.piped_instance); + if (r.piped_listen !== undefined) localStorage.setItem("listen", r.piped_listen); + if (r.piped_minimizeDescription !== undefined) localStorage.setItem("minimizeDescription", r.piped_minimizeDescription); + if (r.piped_playerAutoPlay !== undefined) localStorage.setItem("playerAutoPlay", r.piped_playerAutoPlay); + if (r.piped_proxyLBRY !== undefined) localStorage.setItem("proxyLBRY", r.piped_proxyLBRY); + if (r.piped_quality !== undefined) localStorage.setItem("quality", r.piped_quality); + if (r.piped_region !== undefined) localStorage.setItem("region", r.piped_region); + if (r.piped_selectedSkip !== undefined) localStorage.setItem("selectedSkip", r.piped_selectedSkip); + if (r.piped_sponsorblock !== undefined) localStorage.setItem("sponsorblock", r.piped_sponsorblock); + if (r.piped_theme !== undefined) localStorage.setItem("theme", r.piped_theme); + if (r.piped_volume !== undefined) localStorage.setItem("volume", r.piped_volume); + if (r.piped_watchHistory !== undefined) localStorage.setItem("watchHistory", r.piped_watchHistory); + + window.close(); + } +) \ No newline at end of file diff --git a/src/assets/javascripts/youtube/youtube.js b/src/assets/javascripts/youtube/youtube.js new file mode 100644 index 00000000..f8227e90 --- /dev/null +++ b/src/assets/javascripts/youtube/youtube.js @@ -0,0 +1,451 @@ +"use strict"; + +window.browser = window.browser || window.chrome; + +import utils from '../utils.js' + +const targets = [ + /^https?:\/{2}(www\.|music\.|m\.|)youtube\.com(\/.*|$)/, + + /^https?:\/{2}img\.youtube\.com\/vi\/.*\/..*/, // https://stackoverflow.com/questions/2068344/how-do-i-get-a-youtube-video-thumbnail-from-the-youtube-api + /^https?:\/{2}(i|s)\.ytimg\.com\/vi\/.*\/..*/, + + /^https?:\/{2}(www\.|music\.|)youtube\.com\/watch\?v\=..*/, + + /^https?:\/{2}youtu\.be\/..*/, + + /^https?:\/{2}(www\.|)(youtube|youtube-nocookie)\.com\/embed\/..*/, +]; +let redirects = { + "invidious": { + "normal": [], + "tor": [] + }, + "piped": { + "normal": [], + "tor": [] + }, + "pipedMaterial": { + "normal": [ + "https://piped-material.xn--17b.net", + "https://piped-material.ftp.sh", + ], + "tor": [] + } +}; +function setRedirects(val) { + browser.storage.local.get('cloudflareList', r => { + redirects.invidious = val.invidious; + redirects.piped = val.piped; + invidiousNormalRedirectsChecks = [...redirects.invidious.normal]; + pipedNormalRedirectsChecks = [...redirects.piped.normal]; + for (const instance of r.cloudflareList) { + const a = invidiousNormalRedirectsChecks.indexOf(instance); + if (a > -1) invidiousNormalRedirectsChecks.splice(a, 1); + + const b = pipedNormalRedirectsChecks.indexOf(instance); + if (b > -1) pipedNormalRedirectsChecks.splice(b, 1); + } + browser.storage.local.set({ + youtubeRedirects: redirects, + invidiousNormalRedirectsChecks, + invidiousTorRedirectsChecks: redirects.invidious.tor, + pipedNormalRedirectsChecks, + pipedTorRedirectsChecks: redirects.piped.tor, + }) + }) +} + +let + disableYoutube, + OnlyEmbeddedVideo, + youtubeFrontend, + youtubeProtocol, + youtubeEmbedFrontend, + youtubeRedirects, + invidiousNormalRedirectsChecks, + invidiousNormalCustomRedirects, + invidiousTorRedirectsChecks, + invidiousTorCustomRedirects, + pipedNormalRedirectsChecks, + pipedNormalCustomRedirects, + pipedTorRedirectsChecks, + pipedTorCustomRedirects, + pipedMaterialNormalRedirectsChecks, + pipedMaterialNormalCustomRedirects, + pipedMaterialTorRedirectsChecks, + pipedMaterialTorCustomRedirects; + +function init() { + return new Promise(resolve => { + browser.storage.local.get( + [ + "disableYoutube", + "OnlyEmbeddedVideo", + "youtubeFrontend", + "youtubeProtocol", + "youtubeEmbedFrontend", + "youtubeRedirects", + "invidiousNormalRedirectsChecks", + "invidiousNormalCustomRedirects", + "invidiousTorRedirectsChecks", + "invidiousTorCustomRedirects", + "pipedNormalRedirectsChecks", + "pipedNormalCustomRedirects", + "pipedTorRedirectsChecks", + "pipedTorCustomRedirects", + "pipedMaterialNormalRedirectsChecks", + "pipedMaterialNormalCustomRedirects", + "pipedMaterialTorRedirectsChecks", + "pipedMaterialTorCustomRedirects", + ], + r => { + disableYoutube = r.disableYoutube; + OnlyEmbeddedVideo = r.OnlyEmbeddedVideo; + youtubeFrontend = r.youtubeFrontend; + youtubeProtocol = r.youtubeProtocol; + youtubeEmbedFrontend = r.youtubeEmbedFrontend; + youtubeRedirects = r.youtubeRedirects; + invidiousNormalRedirectsChecks = r.invidiousNormalRedirectsChecks; + invidiousNormalCustomRedirects = r.invidiousNormalCustomRedirects; + invidiousTorRedirectsChecks = r.invidiousTorRedirectsChecks; + invidiousTorCustomRedirects = r.invidiousTorCustomRedirects; + pipedNormalRedirectsChecks = r.pipedNormalRedirectsChecks; + pipedNormalCustomRedirects = r.pipedNormalCustomRedirects; + pipedTorRedirectsChecks = r.pipedTorRedirectsChecks; + pipedTorCustomRedirects = r.pipedTorCustomRedirects; + pipedMaterialNormalRedirectsChecks = r.pipedMaterialNormalRedirectsChecks; + pipedMaterialNormalCustomRedirects = r.pipedMaterialNormalCustomRedirects; + pipedMaterialTorRedirectsChecks = r.pipedMaterialTorRedirectsChecks; + pipedMaterialTorCustomRedirects = r.pipedMaterialTorCustomRedirects; + resolve(); + } + ) + }) +} + +init(); +browser.storage.onChanged.addListener(init) + +function all() { + return [ + ...youtubeRedirects.invidious.normal, + ...youtubeRedirects.invidious.tor, + + ...youtubeRedirects.piped.normal, + ...youtubeRedirects.piped.tor, + + ...youtubeRedirects.pipedMaterial.normal, + ...youtubeRedirects.pipedMaterial.tor, + + ...invidiousNormalCustomRedirects, + ...invidiousTorCustomRedirects, + + ...pipedNormalCustomRedirects, + ...pipedTorCustomRedirects, + + ...pipedMaterialNormalCustomRedirects, + ...pipedMaterialTorCustomRedirects, + ]; +} + +function redirect(url, details, initiator) { + if (disableYoutube) return; + if (!targets.some(rx => rx.test(url.href))) return; + if (initiator && all().includes(initiator.origin)) return 'BYPASSTAB'; + + const isInvidious = youtubeFrontend == 'invidious'; + const isPiped = youtubeFrontend == 'piped'; + const isPipedMaterial = youtubeFrontend == 'pipedMaterial' + const isFreetube = youtubeFrontend == 'freetube'; + const isYatte = youtubeFrontend == 'yatte'; + + const isFrontendYoutube = youtubeEmbedFrontend == "youtube"; + const isFrontendInvidious = youtubeEmbedFrontend == 'invidious'; + const isFrontendPiped = youtubeEmbedFrontend == 'piped'; + const isFrontendPipedMaterial = youtubeEmbedFrontend == 'pipedMaterial'; + + const isOnlyEmbeddedVideo = OnlyEmbeddedVideo == 'onlyNotEmbedded'; + const isOnlyNotEmbedded = OnlyEmbeddedVideo == 'onlyNotEmbedded' + + const is_main_frame = details.type === "main_frame"; + const is_sub_frame = details.type === "sub_frame"; + + if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return; // Don't redirect YouTube Player API. + + if (youtubeFrontend == 'yatte' && is_main_frame) + return url.href.replace(/^https?:\/{2}/, 'yattee://'); + + else if (isFreetube && is_main_frame) + return `freetube://https:${url.pathname}${url.search}`; + + else if (isFreetube && params && isFrontendYoutube) + return; + + else if (isInvidious || ((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) { + + if (isOnlyEmbeddedVideo && !is_sub_frame) return; + if (isOnlyNotEmbedded && params && !((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) return; + + let instancesList; + if (youtubeProtocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects]; + else if (youtubeProtocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects]; + if (instancesList.length === 0) return; + let randomInstance = utils.getRandomInstance(instancesList); + + return `${randomInstance}${url.pathname}${url.search}`; + } else if (isPiped || ((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)) { + + if (isOnlyEmbeddedVideo && !is_sub_frame) return; + if ( + isOnlyNotEmbedded && params && + !((isFreetube || isYatte) && isFrontendPiped && is_sub_frame) + ) return; + + let instancesList; + if (youtubeProtocol == 'normal') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects]; + else if (youtubeProtocol == 'tor') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects]; + if (instancesList.length === 0) return; + + const randomInstance = utils.getRandomInstance(instancesList); + return `${randomInstance}${url.pathname}${url.search}`; + } + else if (isPipedMaterial || ((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)) { + if (isOnlyEmbeddedVideo && details.type !== "sub_frame") return; + if ( + isOnlyNotEmbedded && params && + !((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame) + ) return; + + let instancesList; + if (youtubeProtocol == 'normal') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects]; + else if (youtubeProtocol == 'tor') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects]; + + const randomInstance = utils.getRandomInstance(instancesList); + return `${randomInstance}${url.pathname}${url.search}`; + } + else return 'CANCEL'; +} + +function reverse(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + if (!all().includes(protocolHost)) { resolve(); return; } + resolve(`https://youtube.com${url.pathname}${url.search}`); + }) +} + +function switchInstance(url) { + return new Promise(async resolve => { + await init(); + const protocolHost = utils.protocolHost(url); + const instances = all(); + if (!instances.includes(protocolHost)) { resolve(); return; } + + let instancesList; + if (youtubeProtocol == 'normal') { + if (youtubeFrontend == 'invidious') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects]; + else if (youtubeFrontend == 'piped') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects]; + else if (youtubeFrontend == 'pipedMaterial') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects]; + } + else if (youtubeProtocol == 'tor') { + if (youtubeFrontend == 'invidious') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects]; + else if (youtubeFrontend == 'piped') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects]; + else if (youtubeFrontend == 'pipedMaterial') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects]; + } + + const i = instancesList.indexOf(protocolHost); + if (i > -1) instancesList.splice(i, 1); + if (instancesList.length == 0) { resolve(); return; } + + const randomInstance = utils.getRandomInstance(instancesList); + resolve(`${randomInstance}${url.pathname}${url.search}`); + }) +} + +function initDefaults() { + return new Promise(async resolve => { + fetch('/instances/data.json').then(response => response.text()).then(async data => { + let dataJson = JSON.parse(data); + redirects.invidious = dataJson.invidious; + redirects.piped = dataJson.piped; + browser.storage.local.get('cloudflareList', async r => { + + invidiousNormalRedirectsChecks = [...redirects.invidious.normal]; + pipedNormalRedirectsChecks = [...redirects.piped.normal]; + pipedMaterialNormalRedirectsChecks = [...redirects.pipedMaterial.normal]; + + for (const instance of r.cloudflareList) { + let i; + + i = invidiousNormalRedirectsChecks.indexOf(instance); + if (i > -1) invidiousNormalRedirectsChecks.splice(i, 1); + + i = pipedNormalRedirectsChecks.indexOf(instance); + if (i > -1) pipedNormalRedirectsChecks.splice(i, 1); + + i = pipedMaterialNormalRedirectsChecks.indexOf(instance); + if (i > -1) pipedMaterialNormalRedirectsChecks.splice(i, 1); + } + + await browser.storage.local.set({ + disableYoutube: false, + enableYoutubeCustomSettings: false, + OnlyEmbeddedVideo: 'both', + + youtubeRedirects: redirects, + + youtubeFrontend: 'invidious', + + invidiousNormalRedirectsChecks: invidiousNormalRedirectsChecks, + invidiousNormalCustomRedirects: [], + + invidiousTorRedirectsChecks: [...redirects.invidious.tor], + invidiousTorCustomRedirects: [], + + pipedNormalRedirectsChecks: pipedNormalRedirectsChecks, + pipedNormalCustomRedirects: [], + + pipedTorRedirectsChecks: [...redirects.piped.tor], + pipedTorCustomRedirects: [], + + pipedMaterialNormalRedirectsChecks: pipedMaterialNormalRedirectsChecks, + pipedMaterialNormalCustomRedirects: [], + + pipedMaterialTorRedirectsChecks: [...redirects.pipedMaterial.tor], + pipedMaterialTorCustomRedirects: [], + + youtubeEmbedFrontend: 'invidious', + youtubeProtocol: 'normal', + }) + resolve(); + }) + }) + }) +} + +function initInvidiousCookies(test, from) { + return new Promise(async resolve => { + await init(); + if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; } + const protocolHost = utils.protocolHost(from); + if (![ + ...invidiousNormalRedirectsChecks, + ...invidiousTorRedirectsChecks, + ...invidiousNormalCustomRedirects, + ...invidiousTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + if (!test) { + let checkedInstances; + if (youtubeProtocol == 'normal') checkedInstances = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects] + else if (youtubeProtocol == 'tor') checkedInstances = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects] + const i = checkedInstances.indexOf(protocolHost); + if (i !== -1) checkedInstances.splice(i, 1); + for (const to of checkedInstances) + utils.copyCookie('invidious', from, to, 'PREFS'); + } + resolve(true); + }) +} + +function setInvidiousCookies() { + return new Promise(async resolve => { + await init(); + if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; } + let checkedInstances; + if (youtubeProtocol == 'normal') checkedInstances = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects] + else if (youtubeProtocol == 'tor') checkedInstances = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects] + for (const to of checkedInstances) + utils.getCookiesFromStorage('invidious', to, 'PREFS'); + resolve(); + }) +} + +function initPipedLocalStorage(test, url, tabId) { + return new Promise(async resolve => { + await init(); + if (disableYoutube || youtubeFrontend != 'piped') { resolve(); return; } + const protocolHost = utils.protocolHost(url); + if (![ + ...pipedNormalCustomRedirects, + ...pipedNormalRedirectsChecks, + ...pipedTorRedirectsChecks, + ...pipedTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + if (!test) { + + browser.tabs.executeScript(tabId, { file: "/assets/javascripts/youtube/get_piped_preferences.js", runAt: "document_start" }); + + let checkedInstances; + if (youtubeProtocol == 'normal') checkedInstances = [...pipedNormalCustomRedirects, ...pipedNormalRedirectsChecks] + else if (youtubeProtocol == 'tor') checkedInstances = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects] + const i = checkedInstances.indexOf(protocolHost); + if (i !== -1) checkedInstances.splice(i, 1); + for (const to of checkedInstances) { + browser.tabs.create({ url: to }, + tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/youtube/set_piped_preferences.js", runAt: "document_start" })) + } + } + resolve(true); + }) +} + +function initPipedMaterialLocalStorage(test, url, tabId,) { + return new Promise(async resolve => { + await init(); + if (disableYoutube || youtubeFrontend != 'pipedMaterial') { resolve(); return; } + const protocolHost = utils.protocolHost(url); + if (![ + ...pipedMaterialNormalRedirectsChecks, + ...pipedMaterialNormalCustomRedirects, + ...pipedMaterialTorRedirectsChecks, + ...pipedMaterialTorCustomRedirects, + ].includes(protocolHost)) { resolve(); return; } + + if (!test) { + browser.tabs.executeScript(tabId, { file: "/assets/javascripts/youtube/get_pipedMaterial_preferences.js", runAt: "document_start" }); + + let checkedInstances; + if (youtubeProtocol == 'normal') checkedInstances = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects] + else if (youtubeProtocol == 'tor') checkedInstances = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects] + const i = checkedInstances.indexOf(protocolHost); + if (i !== -1) checkedInstances.splice(i, 1); + for (const to of checkedInstances) + browser.tabs.create( + { url: to }, + tab => browser.tabs.executeScript(tab.id, { file: "/assets/javascripts/youtube/set_pipedMaterial_preferences.js", runAt: "document_start" }) + ); + } + resolve(true); + }) +} + +function removeXFrameOptions(e) { + const url = new URL(e.url); + let protocolHost = utils.protocolHost(url); + const instances = all(); + if (!instances.includes(protocolHost) || e.type != 'sub_frame') return; + + let isChanged = false; + for (const i in e.responseHeaders) + if (e.responseHeaders[i].name == 'x-frame-options') { + e.responseHeaders.splice(i, 1); + isChanged = true; + } + if (isChanged) return { responseHeaders: e.responseHeaders }; +} + +export default { + setRedirects, + initPipedLocalStorage, + initPipedMaterialLocalStorage, + initInvidiousCookies, + setInvidiousCookies, + redirect, + reverse, + switchInstance, + initDefaults, + removeXFrameOptions, +}; diff --git a/src/assets/javascripts/youtubeMusic.js b/src/assets/javascripts/youtubeMusic.js new file mode 100644 index 00000000..68fa4f24 --- /dev/null +++ b/src/assets/javascripts/youtubeMusic.js @@ -0,0 +1,97 @@ +"use strict"; + +import utils from './utils.js' + +window.browser = window.browser || window.chrome; + +const targets = [ + /^https?:\/{2}music\.youtube\.com(\/.*|$)/, +]; +let redirects = { + "beatbump": { + "normal": [ + "https://beatbump.ml" + ], + "tor": [] + }, +}; + +let + disableYoutubeMusic, + beatbumpNormalRedirectsChecks, + beatbumpNormalCustomRedirects; + +function init() { + browser.storage.local.get( + [ + "disableYoutubeMusic", + "beatbumpNormalRedirectsChecks", + "beatbumpNormalCustomRedirects", + ], + r => { + disableYoutubeMusic = r.disableYoutubeMusic; + beatbumpNormalRedirectsChecks = r.beatbumpNormalRedirectsChecks; + beatbumpNormalCustomRedirects = r.beatbumpNormalCustomRedirects; + } + ) +} + +init(); +browser.storage.onChanged.addListener(init) + +/* +Video +https://music.youtube.com/watch?v=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA +https://beatbump.ml/listen?id=_PkGiKBW-DA&list=RDAMVM_PkGiKBW-DA + +Playlist +https://music.youtube.com/playlist?list=PLqxd0OMLeWy64zlwhjouj92ISc38FbOns +https://music.youtube.com/playlist?list=PLqxd0OMLeWy7lrJSzt9LnOJjbC1IaruPM +https://music.youtube.com/playlist?list=PLQod4DlD72ZMJmOrSNbmEmK_iZ1oXPzKd +https://beatbump.ml/playlist/VLPLqxd0OMLeWy64zlwhjouj92ISc38FbOns + +Channel +https://music.youtube.com/channel/UCfgmMDI7T5tOQqjnOBRe_wg +https://beatbump.ml/artist/UCfgmMDI7T5tOQqjnOBRe_wg + +Albums +https://music.youtube.com/playlist?list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU +https://music.youtube.com/playlist?list=OLAK5uy_lcr5O1zS8f6WIFI_yxqVp2RK9Dyy2bbw0 +https://beatbump.ml/release?id=MPREb_3DURc4yEUtD +https://beatbump.ml/release?id=MPREb_evaZrV1WNdS + +https://music.youtube.com/playlist?list=OLAK5uy_n6OHVllUZUCnlIY1m-gUaH8uqkN3Y-Ca8 +https://music.youtube.com/playlist?list=OLAK5uy_nBOTxAc3_RGB82-Z54jdARGxGaCYlpngY +https://beatbump.ml/release?id=MPREb_QygdC0wEoLe + +https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU +*/ +function redirect(url, type, initiator) { + if (disableYoutubeMusic) return; + if (!targets.some(rx => rx.test(url.href))) return; + + let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects]; + if (instancesList.length === 0) return; + const randomInstance = utils.getRandomInstance(instancesList); + resolve( + `${randomInstance}${url.pathname}${url.search}` + .replace("/watch?v=", "/listen?id=") + .replace("/channel/", "/artist/") + .replace("/playlist?list=", "/playlist/VL") + ); +} + +async function initDefaults() { + await browser.storage.local.set({ + disableYoutubeMusic: true, + youtubeMusicRedirects: redirects, + + beatbumpNormalRedirectsChecks: [...redirects.beatbump.normal], + beatbumpNormalCustomRedirects: [], + }) +} + +export default { + redirect, + initDefaults, +}; diff --git a/src/manifest.json b/src/manifest.json index c82d6449..fffffb38 100644 --- a/src/manifest.json +++ b/src/manifest.json @@ -40,7 +40,7 @@ } }, "options_ui": { - "page": "pages/options/general/general.html", + "page": "pages/options/index.html", "browser_style": false, "open_in_tab": true }, diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 35c975f7..0f594161 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -1,23 +1,23 @@ "use strict"; -import generalHelper from "../../assets/javascripts/helpers/general.js"; -import utils from "../../assets/javascripts/helpers/utils.js"; - -import youtubeHelper from "../../assets/javascripts/helpers/youtube/youtube.js"; -import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js"; -import twitterHelper from "../../assets/javascripts/helpers/twitter.js"; -import instagramHelper from "../../assets/javascripts/helpers/instagram.js"; -import redditHelper from "../../assets/javascripts/helpers/reddit.js"; -import searchHelper from "../../assets/javascripts/helpers/search.js"; -import translateHelper from "../../assets/javascripts/helpers/translate/translate.js"; -import mapsHelper from "../../assets/javascripts/helpers/maps.js"; -import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; -import mediumHelper from "../../assets/javascripts/helpers/medium.js"; -import imgurHelper from "../../assets/javascripts/helpers/imgur.js"; -import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js"; -import sendTargetsHelper from "../../assets/javascripts/helpers/sendTargets.js"; -import peertubeHelper from "../../assets/javascripts/helpers/peertube.js"; -import lbryHelper from "../../assets/javascripts/helpers/lbry.js"; +import generalHelper from "../../assets/javascripts/general.js"; +import utils from "../../assets/javascripts/utils.js"; + +import youtubeHelper from "../../assets/javascripts/youtube/youtube.js"; +import youtubeMusicHelper from "../../assets/javascripts/youtubeMusic.js"; +import twitterHelper from "../../assets/javascripts/twitter.js"; +import instagramHelper from "../../assets/javascripts/instagram.js"; +import redditHelper from "../../assets/javascripts/reddit.js"; +import searchHelper from "../../assets/javascripts/search.js"; +import translateHelper from "../../assets/javascripts/translate/translate.js"; +import mapsHelper from "../../assets/javascripts/maps.js"; +import wikipediaHelper from "../../assets/javascripts/wikipedia.js"; +import mediumHelper from "../../assets/javascripts/medium.js"; +import imgurHelper from "../../assets/javascripts/imgur.js"; +import tiktokHelper from "../../assets/javascripts/tiktok.js"; +import sendTargetsHelper from "../../assets/javascripts/sendTargets.js"; +import peertubeHelper from "../../assets/javascripts/peertube.js"; +import lbryHelper from "../../assets/javascripts/lbry.js"; window.browser = window.browser || window.chrome; diff --git a/src/pages/background/incognito.js b/src/pages/background/incognito.js index 2ebbe545..8152f40f 100644 --- a/src/pages/background/incognito.js +++ b/src/pages/background/incognito.js @@ -1,10 +1,10 @@ -import youtubeHelper from "../../assets/javascripts/helpers/youtube/youtube.js"; -import twitterHelper from "../../assets/javascripts/helpers/twitter.js"; -import redditHelper from "../../assets/javascripts/helpers/reddit.js"; -import searchHelper from "../../assets/javascripts/helpers/search.js"; -import translateHelper from "../../assets/javascripts/helpers/translate/translate.js"; -import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; -import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js"; +import youtubeHelper from "../../assets/javascripts/youtube/youtube.js"; +import twitterHelper from "../../assets/javascripts/twitter.js"; +import redditHelper from "../../assets/javascripts/reddit.js"; +import searchHelper from "../../assets/javascripts/search.js"; +import translateHelper from "../../assets/javascripts/translate/translate.js"; +import wikipediaHelper from "../../assets/javascripts/wikipedia.js"; +import tiktokHelper from "../../assets/javascripts/tiktok.js"; window.browser = window.browser || window.chrome; diff --git a/src/pages/options/general/general.html b/src/pages/options/general/general.html deleted file mode 100644 index 8dd60184..00000000 --- a/src/pages/options/general/general.html +++ /dev/null @@ -1,207 +0,0 @@ - - - - - - - - General - - - - -
-
-

General

-
-
-
-

Theme

- -
-
-

Auto Redirect of offline instances

- -
-
-

Exceptions

-
-
-
-
-   -   -
- -
-
-
-
- - - - Update Instances    - -     - - -   - Export Settings    - - - - - Reset Settings -
-
-
-

Customize Popup

-
- - - - -
- \ No newline at end of file diff --git a/src/pages/options/general/general.js b/src/pages/options/general/general.js deleted file mode 100644 index c943ddd8..00000000 --- a/src/pages/options/general/general.js +++ /dev/null @@ -1,224 +0,0 @@ -"use strict"; -window.browser = window.browser || window.chrome; - -import utils from "../../../assets/javascripts/helpers/utils.js"; -import generalHelper from "../../../assets/javascripts/helpers/general.js"; - -import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; -import youtubeMusicHelper from "../../../assets/javascripts/helpers/youtubeMusic.js"; -import twitterHelper from "../../../assets/javascripts/helpers/twitter.js"; -import instagramHelper from "../../../assets/javascripts/helpers/instagram.js"; -import redditHelper from "../../../assets/javascripts/helpers/reddit.js"; -import searchHelper from "../../../assets/javascripts/helpers/search.js"; -import translateHelper from "../../../assets/javascripts/helpers/translate/translate.js"; -import mapsHelper from "../../../assets/javascripts/helpers/maps.js"; -import wikipediaHelper from "../../../assets/javascripts/helpers/wikipedia.js"; -import mediumHelper from "../../../assets/javascripts/helpers/medium.js"; -import imgurHelper from "../../../assets/javascripts/helpers/imgur.js"; -import tiktokHelper from "../../../assets/javascripts/helpers/tiktok.js"; -import sendTargetsHelper from "../../../assets/javascripts/helpers/sendTargets.js"; -import peertubeHelper from "../../../assets/javascripts/helpers/peertube.js"; -import lbryHelper from "../../../assets/javascripts/helpers/lbry.js"; - -let updateInstancesElement = document.getElementById("update-instances"); -updateInstancesElement.addEventListener("click", () => { - let oldHtml = updateInstancesElement.innerHTML - updateInstancesElement.innerHTML = '...'; - if (utils.updateInstances()) { - updateInstancesElement.innerHTML = 'Done!'; - new Promise(resolve => setTimeout(resolve, 1500)).then( // sleep 1500ms - () => updateInstancesElement.innerHTML = oldHtml - ) - } - else - updateInstancesElement.innerHTML = 'Failed Miserabely'; -}); - -let exportSettingsElement = document.getElementById("export-settings"); - -function exportSettings() { - browser.storage.local.get( - null, - result => { - let resultString = JSON.stringify(result, null, ' '); - exportSettingsElement.href = 'data:application/json;base64,' + btoa(resultString); - exportSettingsElement.download = 'libredirect-settings.json'; - } - ); -} -exportSettings(); - -browser.storage.onChanged.addListener(exportSettings); - -let importSettingsElement = document.getElementById("import-settings"); -let importSettingsElementText = document.getElementById('import_settings_text'); -importSettingsElement.addEventListener("change", - () => { - let file = importSettingsElement.files[0]; - const reader = new FileReader(); - reader.readAsText(file); - reader.onload = async () => { - const data = JSON.parse(reader.result) - if ( - "theme" in data && - "disableImgur" in data && - "cloudflareList" in data && - "imgurRedirects" in data - ) { - console.log('importing a valid file...'); - await browser.storage.local.set({ ...data }) - location.reload(); - } else - importError() - } - reader.onerror = error => importError(); - } -); -function importError() { - const oldHTML = importSettingsElementText.innerHTML; - importSettingsElementText.innerHTML = 'Error!'; - setTimeout(() => importSettingsElementText.innerHTML = oldHTML, 1000); -} - -document.getElementById("reset-settings").addEventListener("click", - async () => { - await browser.storage.local.clear(); - fetch('/instances/blocklist.json').then(response => response.text()).then(async data => { - await browser.storage.local.set({ cloudflareList: JSON.parse(data) }) - await generalHelper.initDefaults(); - await youtubeHelper.initDefaults(); - await youtubeMusicHelper.initDefaults(); - await twitterHelper.initDefaults(); - await instagramHelper.initDefaults(); - await mapsHelper.initDefaults(); - await searchHelper.initDefaults(); - await translateHelper.initDefaults(); - await mediumHelper.initDefaults(); - await redditHelper.initDefaults(); - await wikipediaHelper.initDefaults(); - await imgurHelper.initDefaults(); - await tiktokHelper.initDefaults(); - await sendTargetsHelper.initDefaults(); - await peertubeHelper.initDefaults(); - await lbryHelper.initDefaults(); - location.reload(); - }) - } -); - -let autoRedirectElement = document.getElementById("auto-redirect") -autoRedirectElement.addEventListener("change", - event => browser.storage.local.set({ autoRedirect: event.target.checked }) -); - -let themeElement = document.getElementById("theme"); -themeElement.addEventListener("change", event => { - const value = event.target.options[theme.selectedIndex].value; - browser.storage.local.set({ theme: value }); -}) - -let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance"); -let instanceTypeElement = document.getElementById("exceptions-custom-instance-type"); -let instanceType = "url" - -let popupFrontends; -for (const frontend of generalHelper.allPopupFrontends) - document.getElementById(frontend).addEventListener("change", - event => { - if (event.target.checked && !popupFrontends.includes(frontend)) - popupFrontends.push(frontend) - else if (popupFrontends.includes(frontend)) { - var index = popupFrontends.indexOf(frontend); - if (index !== -1) popupFrontends.splice(index, 1); - } - browser.storage.local.set({ popupFrontends }) - } - ) - - -browser.storage.local.get( - [ - 'theme', - 'autoRedirect', - 'exceptions' - ], - r => { - autoRedirectElement.checked = r.autoRedirect; - themeElement.value = r.theme; - instanceTypeElement.addEventListener("change", - event => { - instanceType = event.target.options[instanceTypeElement.selectedIndex].value - if (instanceType == 'url') { - nameCustomInstanceInput.setAttribute("type", "url"); - nameCustomInstanceInput.setAttribute("placeholder", "https://www.google.com"); - } - else if (instanceType == 'regex') { - nameCustomInstanceInput.setAttribute("type", "text"); - nameCustomInstanceInput.setAttribute("placeholder", "https?:\/\/(www\.|)youtube\.com\/"); - } - } - ) - let exceptionsCustomInstances = r.exceptions; - function calcExceptionsCustomInstances() { - document.getElementById("exceptions-custom-checklist").innerHTML = - [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex].map( - (x) => `
- ${x} - -
-
` - ).join('\n'); - - for (const x of [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex]) { - document.getElementById(`clear-${x}`).addEventListener("click", - () => { - console.log(x); - let index; - index = exceptionsCustomInstances.url.indexOf(x); - if (index > -1) - exceptionsCustomInstances.url.splice(index, 1); - else { - index = exceptionsCustomInstances.regex.indexOf(x); - if (index > -1) - exceptionsCustomInstances.regex.splice(index, 1); - } - browser.storage.local.set({ exceptions: exceptionsCustomInstances }) - calcExceptionsCustomInstances(); - }); - } - } - calcExceptionsCustomInstances(); - document.getElementById("custom-exceptions-instance-form").addEventListener("submit", (event) => { - event.preventDefault(); - - let val - if (instanceType == 'url') { - if (nameCustomInstanceInput.validity.valid) { - let url = new URL(nameCustomInstanceInput.value); - val = `${url.protocol}//${url.host}` - if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val) - } - } else if (instanceType == 'regex') { - val = nameCustomInstanceInput.value - if (val.trim() != '' && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val) - } - if (val) { - browser.storage.local.set({ exceptions: exceptionsCustomInstances }) - nameCustomInstanceInput.value = ''; - } - calcExceptionsCustomInstances(); - }) - - browser.storage.local.get('popupFrontends', - r => { - popupFrontends = r.popupFrontends; - for (const frontend of generalHelper.allPopupFrontends) - document.getElementById(frontend).checked = popupFrontends.includes(frontend); - } - ) - }) diff --git a/src/pages/options/general/general.pug b/src/pages/options/general/general.pug deleted file mode 100644 index 3d35c311..00000000 --- a/src/pages/options/general/general.pug +++ /dev/null @@ -1,176 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title General -body.option(dir="auto") - include ../../widgets/links.pug - +links('general') - - section.option-block - .some-block.option-block - h1 General - hr - - .some-block.option-block - h4(data-localise="__MSG_theme__") Theme - select#theme - option(value="DEFAULT" data-localise="__MSG_system__") System - option(value="light" data-localise="__MSG_light__") Light - option(value="dark" data-localise="__MSG_dark__") Dark - - .some-block.option-block - h4(data-localise="__MSG_autoRedirect__") Auto Redirect of offline instances - input#auto-redirect(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_exceptions__") Exceptions - - form#custom-exceptions-instance-form - .some-block.option-block - .some-block(style="padding:0;") - input#exceptions-custom-instance(placeholder="https://www.google.com" type="url") - |  - select#exceptions-custom-instance-type - option(value="url") URL - option(value="regex") Regex - |  - button#exceptions-add-instance.add(type="submit") - svg(xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor") - path(d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z") - - #exceptions-custom-checklist.checklist - - .buttons.buttons-inline - a#update-instances.button.button-inline - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z") - x(data-localise="__MSG_updateInstances__") Update Instances - - |    - - label#import_settings_text.button.button-inline(for="import-settings") - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z") - |  - x(data-localise="__MSG_importSettings__") Import Settings - input#import-settings.button.button-inline(type="file" style="display:none;") - - |    - - a#export-settings.button.button-inline - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M10.09 15.59L11.5 17l5-5-5-5-1.41 1.41L12.67 11H3v2h9.67l-2.58 2.59zM19 3H5c-1.11 0-2 .9-2 2v4h2V5h14v14H5v-4H3v4c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z") - |  - x(data-localise="__MSG_exportSettings__") Export Settings - - |    - - a#reset-settings.button.button-inline - svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M12,5V2L8,6l4,4V7c3.31,0,6,2.69,6,6c0,2.97-2.17,5.43-5,5.91v2.02c3.95-0.49,7-3.85,7-7.93C20,8.58,16.42,5,12,5z") - path(d="M6,13c0-1.65,0.67-3.15,1.76-4.24L6.34,7.34C4.9,8.79,4,10.79,4,13c0,4.08,3.05,7.44,7,7.93v-2.02 C8.17,18.43,6,15.97,6,13z") - x(data-localise="__MSG_resetSettings__") Reset Settings - hr - - .some-block.option-block - h4(data-localise="__MSG_customPopup__") Customize Popup - - #popup-frontends-checklist.checklist-popup - div - div - img(src="../../../assets/images/youtube-icon.png") - |YouTube - input#youtube(type="checkbox") - div - div - img(src="../../../assets/images/youtube-music-icon.png") - |YoutubeMusic - input#youtubeMusic(type="checkbox") - div - div - img(src="../../../assets/images/twitter-icon.png") - |Twitter - input#twitter(type="checkbox") - - div - div - img(src="../../../assets/images/instagram-icon.png") - |Instagram - input#instagram(type="checkbox") - - div - div - img(src="../../../assets/images/tiktok-icon.png") - |TikTok - input#tikTok(type="checkbox") - - div - div - img(src="../../../assets/images/imgur-icon.png") - |Imgur - input#imgur(type="checkbox") - - div - div - img(src="../../../assets/images/reddit-icon.png") - |Reddit - input#reddit(type="checkbox") - - div - div - svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") - path(d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z") - |Search - input#search(type="checkbox") - - div - div - svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") - path(d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z") - |Translate - input#translate(type="checkbox") - - div - div - svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") - path(d="M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM10 5.47l4 1.4v11.66l-4-1.4V5.47zm-5 .99l3-1.01v11.7l-3 1.16V6.46zm14 11.08l-3 1.01V6.86l3-1.16v11.84z") - |Maps - input#maps(type="checkbox") - - div - div - img(src="../../../assets/images/wikipedia-icon.svg") - |Wikipedia - input#wikipedia(type="checkbox") - - div - div - svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1770 1000" fill="currentColor") - circle(cx="500" cy="500" r="500") - ellipse(ry="475" rx="250" cy="501" cx="1296") - ellipse(cx="1682" cy="502" rx="88" ry="424") - |Medium - input#medium(type="checkbox") - - div - div - img(src="../../../assets/images/peertube-icon.svg") - |PeerTube - input#peertube(type="checkbox") - - div - div - img(src="../../../assets/images/lbry-icon.png") - |LBRY/Odysee - input#lbry(type="checkbox") - - div - div - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z") - |Send Files - input#sendTargets(type="checkbox") - - script(type="module" src="../init.js") - script(type="module" src="./general.js") - script(type="module" src="../../../assets/javascripts/localise.js") \ No newline at end of file diff --git a/src/pages/options/imgur/imgur.html b/src/pages/options/imgur/imgur.html deleted file mode 100644 index 78730edc..00000000 --- a/src/pages/options/imgur/imgur.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - Imgur - - - - - -
-
-

Imgur

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/imgur/imgur.js b/src/pages/options/imgur/imgur.js deleted file mode 100644 index 0b1343c8..00000000 --- a/src/pages/options/imgur/imgur.js +++ /dev/null @@ -1,52 +0,0 @@ -import imgurHelper from "../../../assets/javascripts/helpers/imgur.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disableImgurElement = document.getElementById("disable-imgur"); -let protocolElement = document.getElementById("protocol") - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableImgur: !disableImgurElement.checked, - imgurProtocol: protocolElement.value, - }); - changeProtocolSettings(protocolElement.value); -}) - -function changeProtocolSettings(protocol) { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - let i2pDiv = document.getElementsByClassName("i2p")[0]; - if (protocol == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - i2pDiv.style.display = 'none'; - } - else if (protocol == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - i2pDiv.style.display = 'none'; - } - else if (protocol == 'i2p') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'none'; - i2pDiv.style.display = 'block'; - } -} - -browser.storage.local.get( - [ - "disableImgur", - "imgurProtocol", - ], - r => { - disableImgurElement.checked = !r.disableImgur; - protocolElement.value = r.imgurProtocol; - changeProtocolSettings(r.imgurProtocol); - } -); - -utils.processDefaultCustomInstances('imgur', 'rimgo', 'normal', document); -utils.processDefaultCustomInstances('imgur', 'rimgo', 'tor', document); -utils.processDefaultCustomInstances('imgur', 'rimgo', 'i2p', document); - -utils.latency('imgur', 'rimgo', document, location) \ No newline at end of file diff --git a/src/pages/options/imgur/imgur.pug b/src/pages/options/imgur/imgur.pug deleted file mode 100644 index 3dacdec8..00000000 --- a/src/pages/options/imgur/imgur.pug +++ /dev/null @@ -1,44 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Imgur -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('imgur') - - section.option-block - .some-block.option-block - h1 Imgur - hr - - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-imgur(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - option(value="i2p" data-localise="__MSG_i2p__") I2P - - #rimgo - hr - .normal - include ../../widgets/instances.pug - +instances('https://rimgo.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://rimgo.onion') - - .i2p - include ../../widgets/instances.pug - +instances('https://rimgo.onion') - - - - script(type="module" src="../init.js") - script(type="module" src="./imgur.js") \ No newline at end of file diff --git a/src/pages/options/index.html b/src/pages/options/index.html new file mode 100644 index 00000000..42553e37 --- /dev/null +++ b/src/pages/options/index.html @@ -0,0 +1,1712 @@ + + + + + + + + General + + + + +
+
+
+

General

+
+
+
+

Theme

+ +
+
+

+ +
+
+

+
+
+
+
+   +   +
+ +
+
+
+
+ + + + Update Instances    + +     + + +   + Export Settings    + + + + + Reset Settings +
+
+
+

Customize Popup

+
+ + +
+
+
+

YouTube

+
+
+
+

Enable

+ +
+
+

Frontend

+ +
+
+
+

Embedded Videos Frontend

+ +
+
+
+
+

Protocol

+ +
+
+

Redirect Type

+ +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

YouTube Music

+
+
+
+

Enable

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+ +
+
+
+

Twitter

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Instagram

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

TikTok

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Reddit

+
+
+
+

Enable

+ +
+
+

Frontend

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Imgur

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Wikipedia

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Medium

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

PeerTube

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

LBRY/Odysee

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Search

+
+
+
+

Enable

+ +
+
+

Frontend

+ +
+
+
+

Protocol

+ +
+
+
+

Note: To use Search to its full potential, make LibRedirect as the Default Search Engine

+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Translate

+
+
+
+

Enable

+ +
+
+

Frontend

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+
+

Maps

+
+
+
+

Enable

+ +
+
+

Frontend

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+ +
+
+
+

Send Files

+
+
+
+

Enable

+ +
+
+

Protocol

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+ + +
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+ +
+
+ + + \ No newline at end of file diff --git a/src/pages/options/index.js b/src/pages/options/index.js new file mode 100644 index 00000000..39f9c8f3 --- /dev/null +++ b/src/pages/options/index.js @@ -0,0 +1,24 @@ +for (const a of document.getElementById('links').getElementsByTagName('a')) { + a.addEventListener('click', e => { + const path = a.getAttribute('href').replace('#', ''); + loadPage(path); + e.preventDefault(); + }) +} + +function loadPage(path) { + for (const section of document.getElementById('pages').getElementsByTagName('section')) + section.style.display = 'none'; + document.getElementById(`${path}_page`).style.display = 'block'; + + for (const a of document.getElementById('links').getElementsByTagName('a')) + if (a.getAttribute('href') == `#${path}`) a.classList.add('selected') + else a.classList.remove('selected') + + let stateObj = { id: "100" }; + window.history.pushState(stateObj, "Page 2", `/pages/options/index.html#${path}`); +} + +const r = window.location.href.match(/#(.*)/) +if (r) loadPage(r[1]); +else loadPage('general'); \ No newline at end of file diff --git a/src/pages/options/index.pug b/src/pages/options/index.pug new file mode 100644 index 00000000..6488aced --- /dev/null +++ b/src/pages/options/index.pug @@ -0,0 +1,32 @@ +doctype html +html#elementToShowWithJavaScript(lang="en") + head + meta(charset='utf-8') + meta(name="viewport" content="width=device-width, initial-scale=1") + link(rel="icon" type="image/x-icon" href="../../../assets/images/libredirect.svg") + link(href="../stylesheets/styles.css" rel="stylesheet") + title General + + script(type="module" src="./init.js") + body.option(dir="auto") + include ../widgets/links.pug + +links('general') + div#pages + include ./widgets/general.pug + include ./widgets/youtube.pug + include ./widgets/youtubeMusic.pug + include ./widgets/twitter.pug + include ./widgets/instagram.pug + include ./widgets/tiktok.pug + include ./widgets/reddit.pug + include ./widgets/imgur.pug + include ./widgets/wikipedia.pug + include ./widgets/medium.pug + include ./widgets/peertube.pug + include ./widgets/lbry.pug + include ./widgets/search.pug + include ./widgets/translate.pug + include ./widgets/maps.pug + include ./widgets/sendTargets.pug + + script(type="module" src="./index.js") \ No newline at end of file diff --git a/src/pages/options/init.js b/src/pages/options/init.js index c9bf2f00..daea2963 100644 --- a/src/pages/options/init.js +++ b/src/pages/options/init.js @@ -1,36 +1,38 @@ window.browser = window.browser || window.chrome; -import utils from "../../assets/javascripts/helpers/utils.js"; + +import localise from "../../assets/javascripts/localise.js"; function changeTheme() { - browser.storage.local.get( - "theme", - result => { - switch (result.theme) { - case "dark": - document.body.classList.add("dark-theme"); - document.body.classList.remove("light-theme"); - break; - case "light": - document.body.classList.add("light-theme"); - document.body.classList.remove("dark-theme"); - break; - default: - if (matchMedia("(prefers-color-scheme: light)").matches) { - document.body.classList.add("light-theme"); - document.body.classList.remove("dark-theme"); - } else { + return new Promise(resolve => { + browser.storage.local.get( + "theme", + r => { + switch (r.theme) { + case "dark": document.body.classList.add("dark-theme"); document.body.classList.remove("light-theme"); - } + break; + case "light": + document.body.classList.add("light-theme"); + document.body.classList.remove("dark-theme"); + break; + default: + if (matchMedia("(prefers-color-scheme: light)").matches) { + document.body.classList.add("light-theme"); + document.body.classList.remove("dark-theme"); + } else { + document.body.classList.add("dark-theme"); + document.body.classList.remove("light-theme"); + } + } + resolve(); } - } - ) + ) + }) } -changeTheme() - -browser.storage.onChanged.addListener(changeTheme) - -window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", changeTheme) +changeTheme(); +if (["ar", "iw", "ku", "fa", "ur"].includes(browser.i18n.getUILanguage())) document.getElementsByTagName("body")[0].classList.add("rtl"); +localise.localisePage(); -if (utils.isRtl()) document.getElementsByTagName("body")[0].classList.add("rtl"); \ No newline at end of file +window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", changeTheme) \ No newline at end of file diff --git a/src/pages/options/instagram/instagram.html b/src/pages/options/instagram/instagram.html deleted file mode 100644 index 2524f909..00000000 --- a/src/pages/options/instagram/instagram.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - Instagram - - - - - -
-
-

Instagram

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/instagram/instagram.js b/src/pages/options/instagram/instagram.js deleted file mode 100644 index 955aafc3..00000000 --- a/src/pages/options/instagram/instagram.js +++ /dev/null @@ -1,42 +0,0 @@ -import instagramHelper from "../../../assets/javascripts/helpers/instagram.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -const disable = document.getElementById("disable-bibliogram"); -const protocol = document.getElementById("protocol"); - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableInstagram: disable.checked, - instagramProtocol: protocol.value, - }) - changeProtocolSettings(); -}) - -function changeProtocolSettings() { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} - -browser.storage.local.get( - [ - "disableInstagram", - "instagramProtocol" - ], - r => { - disable.checked = !r.disableInstagram; - protocol.value = r.instagramProtocol; - changeProtocolSettings(); - }) - -utils.processDefaultCustomInstances('instagram', 'bibliogram', 'normal', document); -utils.processDefaultCustomInstances('instagram', 'bibliogram', 'tor', document); - -utils.latency('instagram', 'bibliogram', document, location) \ No newline at end of file diff --git a/src/pages/options/instagram/instagram.pug b/src/pages/options/instagram/instagram.pug deleted file mode 100644 index 6acc2c6e..00000000 --- a/src/pages/options/instagram/instagram.pug +++ /dev/null @@ -1,37 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Instagram -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('instagram') - - section.option-block - .some-block.option-block - h1 Instagram - hr - - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-bibliogram(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #bibliogram - hr - .normal - include ../../widgets/instances.pug - +instances('https://bibliogram.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://bibliogram.onion') - - script(type="module" src="../init.js") - script(type="module" src="./instagram.js") \ No newline at end of file diff --git a/src/pages/options/lbry/lbry.html b/src/pages/options/lbry/lbry.html deleted file mode 100644 index 4c24239c..00000000 --- a/src/pages/options/lbry/lbry.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - LBRY/Odysee - - - - - -
-
-

LBRY/Odysee

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/lbry/lbry.js b/src/pages/options/lbry/lbry.js deleted file mode 100644 index 92cc21a5..00000000 --- a/src/pages/options/lbry/lbry.js +++ /dev/null @@ -1,43 +0,0 @@ -import lbryHelper from "../../../assets/javascripts/helpers/lbry.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-lbry"); -let protocol = document.getElementById("protocol") - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableLbryTargets: !lbryHelper.checked, - lbryTargetsProtocol: protocol.value, - }); - changeProtocolSettings() -}) - -function changeProtocolSettings() { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} - -browser.storage.local.get( - [ - "disableLbryTargets", - "lbryTargetsProtocol" - ], - r => { - disable.checked = !r.disableLbryTargets; - protocol.value = r.lbryTargetsProtocol; - changeProtocolSettings(); - } -) - -utils.processDefaultCustomInstances('lbryTargets', 'librarian', 'normal', document); -utils.processDefaultCustomInstances('lbryTargets', 'librarian', 'tor', document); - -utils.latency('lbryTargets', 'librarian', document, location) \ No newline at end of file diff --git a/src/pages/options/lbry/lbry.pug b/src/pages/options/lbry/lbry.pug deleted file mode 100644 index e579de32..00000000 --- a/src/pages/options/lbry/lbry.pug +++ /dev/null @@ -1,36 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title LBRY/Odysee -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('lbry') - - section.option-block - .some-block.option-block - h1 LBRY/Odysee - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-lbry(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #librarian - hr - .normal - include ../../widgets/instances.pug - +instances('https://librarian.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://librarian.onion') - - script(type="module" src="../init.js") - script(type="module" src="./lbry.js") \ No newline at end of file diff --git a/src/pages/options/maps/maps.html b/src/pages/options/maps/maps.html deleted file mode 100644 index 596289b8..00000000 --- a/src/pages/options/maps/maps.html +++ /dev/null @@ -1,107 +0,0 @@ - - - - - - - - Maps - - - - - -
-
-

Maps

-
-
-
-

Enable

- -
-
-

Frontend

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/maps/maps.js b/src/pages/options/maps/maps.js deleted file mode 100644 index 6db8c03e..00000000 --- a/src/pages/options/maps/maps.js +++ /dev/null @@ -1,32 +0,0 @@ -import mapsHelper from "../../../assets/javascripts/helpers/maps.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -const disable = document.getElementById("disable-osm"); -const frontend = document.getElementById("maps-frontend"); - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableMaps: !disable.checked, - mapsFrontend: frontend.value, - }) - changeFrontendsSettings(); -}) - -const facilDiv = document.getElementById("facil") -function changeFrontendsSettings() { - if (frontend.value == 'facil') facilDiv.style.display = 'block'; - else if (frontend.value == 'osm') facilDiv.style.display = 'none'; -} - -browser.storage.local.get( - [ - "disableMaps", - "mapsFrontend", - ], - r => { - disable.checked = !r.disableMaps; - frontend.value = r.mapsFrontend; - changeFrontendsSettings(); - } -) -utils.processDefaultCustomInstances('maps', 'facil', 'normal', document); \ No newline at end of file diff --git a/src/pages/options/maps/maps.pug b/src/pages/options/maps/maps.pug deleted file mode 100644 index ab51f875..00000000 --- a/src/pages/options/maps/maps.pug +++ /dev/null @@ -1,33 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Maps -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('maps') - - section.option-block - .some-block.option-block - h1 Maps - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-osm(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_frontend__") Frontend - select#maps-frontend - option(value="osm") OpenStreetMap - option(value="facil") Facil Map - - #facil - hr - .normal - include ../../widgets/instances.pug - +instances('https://facilmap.com') - include ../../widgets/latency.pug - +latency() - - script(type="module" src="../init.js") - script(type="module" src="./maps.js") \ No newline at end of file diff --git a/src/pages/options/medium/medium.html b/src/pages/options/medium/medium.html deleted file mode 100644 index cf9bab82..00000000 --- a/src/pages/options/medium/medium.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - Medium - - - - - -
-
-

Medium

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/medium/medium.js b/src/pages/options/medium/medium.js deleted file mode 100644 index 9f00878d..00000000 --- a/src/pages/options/medium/medium.js +++ /dev/null @@ -1,42 +0,0 @@ -import mediumHelper from "../../../assets/javascripts/helpers/medium.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-medium"); -let protocol = document.getElementById("protocol") - -browser.storage.local.get( - [ - "disableMedium", - "mediumProtocol" - ], - r => { - disable.checked = !r.disableMedium; - protocol.value = r.mediumProtocol; - changeProtocolSettings(); - } -) -utils.processDefaultCustomInstances('medium', 'scribe', 'normal', document); -utils.processDefaultCustomInstances('medium', 'scribe', 'tor', document); - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableMedium: !disable.checked, - mediumProtocol: protocol.value, - }) - changeProtocolSettings(); -}) - -function changeProtocolSettings() { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} - -utils.latency('medium', 'scribe', document, location) \ No newline at end of file diff --git a/src/pages/options/medium/medium.pug b/src/pages/options/medium/medium.pug deleted file mode 100644 index eb640c46..00000000 --- a/src/pages/options/medium/medium.pug +++ /dev/null @@ -1,36 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Medium -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('medium') - - section.option-block - .some-block.option-block - h1 Medium - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-medium(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #scribe - hr - .normal - include ../../widgets/instances.pug - +instances('https://scribe.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://scribe.onion') - - script(type="module" src="../init.js") - script(type="module" src="./medium.js") \ No newline at end of file diff --git a/src/pages/options/peertube/peertube.html b/src/pages/options/peertube/peertube.html deleted file mode 100644 index 384c90bf..00000000 --- a/src/pages/options/peertube/peertube.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - PeerTube - - - - - -
-
-

PeerTube

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/peertube/peertube.js b/src/pages/options/peertube/peertube.js deleted file mode 100644 index 0bf16cc7..00000000 --- a/src/pages/options/peertube/peertube.js +++ /dev/null @@ -1,40 +0,0 @@ -import peertubeHelper from "../../../assets/javascripts/helpers/peertube.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-peertube"); -let protocol = document.getElementById("protocol") -browser.storage.local.get( - [ - "disablePeertubeTargets", - "peertubeTargetsProtocol" - ], - r => { - disable.checked = !r.disablePeertubeTargets; - protocol.value = r.peertubeTargetsProtocol; - changeProtocolSettings(); - } -) -utils.processDefaultCustomInstances('peertube', 'simpleertube', 'normal', document); -utils.processDefaultCustomInstances('peertube', 'simpleertube', 'tor', document); - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disablePeertubeTargets: !disable.checked, - peertubeTargetsProtocol: protocol.value - }) - changeProtocolSettings(); -}) - -function changeProtocolSettings() { - const normalDiv = document.getElementsByClassName("normal")[0]; - const torDiv = document.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} -utils.latency('peertube', 'simpleertube', document, location) \ No newline at end of file diff --git a/src/pages/options/peertube/peertube.pug b/src/pages/options/peertube/peertube.pug deleted file mode 100644 index a30be4db..00000000 --- a/src/pages/options/peertube/peertube.pug +++ /dev/null @@ -1,36 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title PeerTube -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('peertube') - - section.option-block - .some-block.option-block - h1 PeerTube - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-peertube(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #simpleertube - hr - .normal - include ../../widgets/instances.pug - +instances('https://simpleertube.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://simpleertube.onion') - - script(type="module" src="../init.js") - script(type="module" src="./peertube.js") \ No newline at end of file diff --git a/src/pages/options/reddit/reddit.html b/src/pages/options/reddit/reddit.html deleted file mode 100644 index 20a26f6c..00000000 --- a/src/pages/options/reddit/reddit.html +++ /dev/null @@ -1,187 +0,0 @@ - - - - - - - - Reddit - - - - - -
-
-

Reddit

-
-
-
-

Enable

- -
-
-

Frontend

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/reddit/reddit.js b/src/pages/options/reddit/reddit.js deleted file mode 100644 index 3661f73f..00000000 --- a/src/pages/options/reddit/reddit.js +++ /dev/null @@ -1,90 +0,0 @@ -import redditHelper from "../../../assets/javascripts/helpers/reddit.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let libredditDivElement = document.getElementById("libreddit") -let tedditDivElement = document.getElementById("teddit") - -let disableRedditElement = document.getElementById("disable-reddit"); -let frontend = document.getElementById("reddit-frontend"); -let protocol = document.getElementById("protocol") - -document.addEventListener("change", () => { - browser.storage.local.set({ - disableReddit: !disableRedditElement.checked, - redditProtocol: protocol.value, - redditFrontend: frontend.value, - }); - changeFrontendsSettings(); - changeProtocolSettings(); -}) - -const libredditForm = libredditDivElement.getElementsByTagName('form')[0]; -const libredditCookies = libredditForm.getElementsByTagName('input')[0]; -libredditForm.addEventListener('submit', async event => { - event.preventDefault(); - const url = new URL(libredditCookies.value); - redditHelper.initLibredditCookies(url); -}); - -const tedditForm = tedditDivElement.getElementsByTagName('form')[0]; -const tedditCookies = tedditForm.getElementsByTagName('input')[0]; -tedditForm.addEventListener('submit', async event => { - event.preventDefault(); - const url = new URL(tedditCookies.value); - redditHelper.initTedditCookies(url); -}); - -function changeProtocolSettings() { - let normalLibredditDiv = libredditDivElement.getElementsByClassName("normal")[0]; - let torLibredditDiv = libredditDivElement.getElementsByClassName("tor")[0]; - - let normalTedditDiv = tedditDivElement.getElementsByClassName("normal")[0]; - let torTedditDiv = tedditDivElement.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalLibredditDiv.style.display = 'block'; - normalTedditDiv.style.display = 'block'; - torTedditDiv.style.display = 'none'; - torLibredditDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalLibredditDiv.style.display = 'none'; - normalTedditDiv.style.display = 'none'; - torTedditDiv.style.display = 'block'; - torLibredditDiv.style.display = 'block'; - } -} -function changeFrontendsSettings() { - if (frontend.value == 'libreddit') { - libredditDivElement.style.display = 'block'; - tedditDivElement.style.display = 'none'; - } - else if (frontend.value == 'teddit') { - libredditDivElement.style.display = 'none'; - tedditDivElement.style.display = 'block'; - } -} - -browser.storage.local.get( - [ - "disableReddit", - "redditProtocol", - "redditFrontend", - - "enableLibredditCustomSettings", - ], - r => { - disableRedditElement.checked = !r.disableReddit - protocol.value = r.redditProtocol - frontend.value = r.redditFrontend - changeFrontendsSettings(); - changeProtocolSettings(); - } -) - -utils.processDefaultCustomInstances('reddit', 'libreddit', 'normal', document); -utils.processDefaultCustomInstances('reddit', 'libreddit', 'tor', document); -utils.processDefaultCustomInstances('reddit', 'teddit', 'normal', document); -utils.processDefaultCustomInstances('reddit', 'teddit', 'tor', document); - -utils.latency('reddit', 'libreddit', document, location, true) -utils.latency('reddit', 'teddit', document, location, true) \ No newline at end of file diff --git a/src/pages/options/reddit/reddit.pug b/src/pages/options/reddit/reddit.pug deleted file mode 100644 index c522af29..00000000 --- a/src/pages/options/reddit/reddit.pug +++ /dev/null @@ -1,52 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Reddit -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('reddit') - - section.option-block - .some-block.option-block - h1 Reddit - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-reddit(type="checkbox") - - .some-block.option-block - h4#frontend(data-localise="__MSG_frontend__") Frontend - select#reddit-frontend - option(value="libreddit") Libreddit - option(value="teddit") Teddit - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #libreddit - hr - .normal - include ../../widgets/instances.pug - +instances('https://libreddit.com') - include ../../widgets/latency.pug - +latency('libreddit') - .tor - include ../../widgets/instances.pug - +instances('https://libreddit.onion') - - #teddit - hr - .normal - include ../../widgets/instances.pug - +instances('https://teddit.com') - +latency('teddit') - .tor - include ../../widgets/instances.pug - +instances('https://teddit.onion') - - script(type="module" src="../init.js") - script(type="module" src="./reddit.js") \ No newline at end of file diff --git a/src/pages/options/search/search.html b/src/pages/options/search/search.html deleted file mode 100644 index e7107d7b..00000000 --- a/src/pages/options/search/search.html +++ /dev/null @@ -1,309 +0,0 @@ - - - - - - - - Search - - - - - -
-
-

Search

-
-
-
-

Enable

- -
-
-

Frontend

- -
-
-
-

Protocol

- -
-
-
-

Note: To use Search to its full potential, make LibRedirect as the Default Search Engine

-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/search/search.js b/src/pages/options/search/search.js deleted file mode 100644 index fb928055..00000000 --- a/src/pages/options/search/search.js +++ /dev/null @@ -1,142 +0,0 @@ -import searchHelper from "../../../assets/javascripts/helpers/search.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let searxDiv = document.getElementById("searx"); -let searxngDiv = document.getElementById("searxng"); -let whoogleDiv = document.getElementById("whoogle"); - -let disable = document.getElementById("disable-search"); -let frontend = document.getElementById("search-frontend"); -let protocol = document.getElementById("protocol") - -const searxngForm = searxngDiv.getElementsByTagName('form')[0]; -const searxngCookies = searxngForm.getElementsByTagName('input')[0]; -searxngForm.addEventListener('submit', async event => { - event.preventDefault(); - const url = new URL(searxngCookies.value); - searchHelper.initSearxngCookies(url); -}); - -const searxForm = searxDiv.getElementsByTagName('form')[0]; -const searxCookies = searxForm.getElementsByTagName('input')[0]; -searxForm.addEventListener('submit', async event => { - event.preventDefault(); - const url = new URL(searxCookies.value); - searchHelper.initSearxCookies(url); -}); - -browser.storage.local.get( - [ - "disableSearch", - "searchFrontend", - "searchProtocol", - ], - r => { - disable.checked = !r.disableSearch; - frontend.value = r.searchFrontend; - protocol.value = r.searchProtocol; - - changeFrontendsSettings(); - changeProtocolSettings(); - } -); - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableSearch: !disable.checked, - searchFrontend: frontend.value, - searchProtocol: protocol.value, - }); - changeFrontendsSettings(frontend.value); - changeProtocolSettings(protocol.value); -}) - -function changeFrontendsSettings() { - let SearxWhoogleElement = document.getElementById("searx-whoogle"); - if (frontend.value == 'searx') { - searxDiv.style.display = 'block'; - searxngDiv.style.display = 'none'; - whoogleDiv.style.display = 'none'; - SearxWhoogleElement.style.display = 'block'; - } - else if (frontend.value == 'searxng') { - searxDiv.style.display = 'none'; - searxngDiv.style.display = 'block'; - whoogleDiv.style.display = 'none'; - SearxWhoogleElement.style.display = 'block'; - } - else if (frontend.value == 'whoogle') { - searxDiv.style.display = 'none'; - searxngDiv.style.display = 'none'; - whoogleDiv.style.display = 'block'; - SearxWhoogleElement.style.display = 'block'; - } -} - -function changeProtocolSettings() { - let normalsearxDiv = searxDiv.getElementsByClassName("normal")[0]; - let torsearxDiv = searxDiv.getElementsByClassName("tor")[0]; - let i2psearxDiv = searxDiv.getElementsByClassName("i2p")[0]; - - let normalsearxngDiv = searxngDiv.getElementsByClassName("normal")[0]; - let torsearxngDiv = searxngDiv.getElementsByClassName("tor")[0]; - let i2psearxngDiv = searxngDiv.getElementsByClassName("i2p")[0]; - - let normalwhoogleDiv = whoogleDiv.getElementsByClassName("normal")[0]; - let torwhoogleDiv = whoogleDiv.getElementsByClassName("tor")[0]; - let i2pwhoogleDiv = whoogleDiv.getElementsByClassName("i2p")[0]; - - if (protocol.value == 'normal') { - normalsearxDiv.style.display = 'block'; - normalsearxngDiv.style.display = 'block'; - normalwhoogleDiv.style.display = 'block'; - - torsearxDiv.style.display = 'none'; - torsearxngDiv.style.display = 'none'; - torwhoogleDiv.style.display = 'none'; - - i2psearxDiv.style.display = 'none'; - i2psearxngDiv.style.display = 'none'; - i2pwhoogleDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalsearxDiv.style.display = 'none'; - normalsearxngDiv.style.display = 'none'; - normalwhoogleDiv.style.display = 'none'; - - torsearxDiv.style.display = 'block'; - torsearxngDiv.style.display = 'block'; - torwhoogleDiv.style.display = 'block'; - - i2psearxDiv.style.display = 'none'; - i2psearxngDiv.style.display = 'none'; - i2pwhoogleDiv.style.display = 'none'; - } - else if (protocol.value == 'i2p') { - normalsearxDiv.style.display = 'none'; - normalsearxngDiv.style.display = 'none'; - normalwhoogleDiv.style.display = 'none'; - - torsearxDiv.style.display = 'none'; - torsearxngDiv.style.display = 'none'; - torwhoogleDiv.style.display = 'none'; - - i2psearxDiv.style.display = 'block'; - i2psearxngDiv.style.display = 'block'; - i2pwhoogleDiv.style.display = 'block'; - } -} - -utils.processDefaultCustomInstances('search', 'searx', 'normal', document); -utils.processDefaultCustomInstances('search', 'searx', 'tor', document); -utils.processDefaultCustomInstances('search', 'searx', 'i2p', document); -utils.processDefaultCustomInstances('search', 'searxng', 'normal', document); -utils.processDefaultCustomInstances('search', 'searxng', 'tor', document); -utils.processDefaultCustomInstances('search', 'searxng', 'i2p', document); -utils.processDefaultCustomInstances('search', 'whoogle', 'normal', document); -utils.processDefaultCustomInstances('search', 'whoogle', 'tor', document); -utils.processDefaultCustomInstances('search', 'whoogle', 'i2p', document); - -utils.latency('search', 'searx', document, location, true) -utils.latency('search', 'searxng', document, location, true) -utils.latency('search', 'whoogle', document, location, true) diff --git a/src/pages/options/search/search.pug b/src/pages/options/search/search.pug deleted file mode 100644 index a9001243..00000000 --- a/src/pages/options/search/search.pug +++ /dev/null @@ -1,78 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Search -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('search') - - section.option-block - .some-block.option-block - h1 Search - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-search(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_frontend__") Frontend - select#search-frontend - option(value="searxng") SearXNG - option(value="searx") SearX - option(value="whoogle") Whoogle - - - #searx-whoogle - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - option(value="i2p" data-localise="__MSG_i2p__") I2P - - .some-block - h4(data-localise="__MSG_searchNote__") Note: To use Search to its full potential, make LibRedirect as the Default Search Engine - - #searx - hr - .normal - include ../../widgets/instances.pug - +instances('https://searx.com') - include ../../widgets/latency.pug - +latency('searx') - .tor - include ../../widgets/instances.pug - +instances('https://searx.onion') - .i2p - include ../../widgets/instances.pug - +instances('https://searx.i2p') - - #searxng - hr - .normal - include ../../widgets/instances.pug - +instances('https://searxng.com') - +latency('searxng') - .tor - include ../../widgets/instances.pug - +instances('https://searxng.onion') - .i2p - include ../../widgets/instances.pug - +instances('https://searxng.i2p') - - #whoogle - hr - .normal - include ../../widgets/instances.pug - +instances('https://whoogle.com') - +latency('whoogle') - .tor - include ../../widgets/instances.pug - +instances('https://whoogle.onion') - .i2p - include ../../widgets/instances.pug - +instances('https://whoogle.i2p') - - script(type="module" src="../init.js") - script(type="module" src="./search.js") \ No newline at end of file diff --git a/src/pages/options/sendTargets/sendTargets.html b/src/pages/options/sendTargets/sendTargets.html deleted file mode 100644 index f9f72efc..00000000 --- a/src/pages/options/sendTargets/sendTargets.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - Send Files - - - - - -
-
-

Send Files

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/sendTargets/sendTargets.js b/src/pages/options/sendTargets/sendTargets.js deleted file mode 100644 index 0cb1da09..00000000 --- a/src/pages/options/sendTargets/sendTargets.js +++ /dev/null @@ -1,43 +0,0 @@ -import sendTargetsHelper from "../../../assets/javascripts/helpers/sendTargets.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-sendTargets"); -let protocol = document.getElementById("protocol") - -browser.storage.local.get( - [ - "disableSendTarget", - "sendTargetsProtocol", - ], - r => { - disable.checked = !r.disableSendTarget; - protocol.value = r.sendTargetsProtocol; - changeProtocolSettings(); - } -) - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableSendTarget: !disable.checked, - sendTargetsProtocol: protocol.value, - }) - changeProtocolSettings(); -}) - -function changeProtocolSettings() { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} - -utils.processDefaultCustomInstances('sendTargets', 'send', 'normal', document); -utils.processDefaultCustomInstances('sendTargets', 'send', 'tor', document); - -utils.latency('sendTargets', 'send', document, location) \ No newline at end of file diff --git a/src/pages/options/sendTargets/sendTargets.pug b/src/pages/options/sendTargets/sendTargets.pug deleted file mode 100644 index 027aee79..00000000 --- a/src/pages/options/sendTargets/sendTargets.pug +++ /dev/null @@ -1,36 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Send Files -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('sendTargets') - - section.option-block - .some-block.option-block - h1 Send Files - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-sendTargets(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #send - hr - .normal - include ../../widgets/instances.pug - +instances('https://send.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://send.onion') - - script(type="module" src="../init.js") - script(type="module" src="./sendTargets.js") \ No newline at end of file diff --git a/src/pages/options/tiktok/tiktok.html b/src/pages/options/tiktok/tiktok.html deleted file mode 100644 index b4fb1d2a..00000000 --- a/src/pages/options/tiktok/tiktok.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - TikTok - - - - - -
-
-

TikTok

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/tiktok/tiktok.js b/src/pages/options/tiktok/tiktok.js deleted file mode 100644 index 5a57b46c..00000000 --- a/src/pages/options/tiktok/tiktok.js +++ /dev/null @@ -1,55 +0,0 @@ -import tiktokHelper from "../../../assets/javascripts/helpers/tiktok.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-tiktok"); -let protocol = document.getElementById("protocol") - -document.addEventListener("change", () => { - browser.storage.local.set({ - disableTiktok: !disable.checked, - tiktokProtocol: protocol.value, - }); - changeProtocolSettings(); -}) - -window.onblur = tiktokHelper.initProxiTokCookies; - -browser.storage.local.get( - [ - "disableTiktok", - "tiktokProtocol", - ], - r => { - disable.checked = !r.disableTiktok; - protocol.value = r.tiktokProtocol; - changeProtocolSettings(); - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - if (r.tiktokProtocol == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (r.tiktokProtocol == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } - } -) - -function changeProtocolSettings() { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} - -utils.processDefaultCustomInstances('tiktok', 'proxiTok', 'normal', document); -utils.processDefaultCustomInstances('tiktok', 'proxiTok', 'tor', document); - -utils.latency('tiktok', 'proxiTok', document, location) \ No newline at end of file diff --git a/src/pages/options/tiktok/tiktok.pug b/src/pages/options/tiktok/tiktok.pug deleted file mode 100644 index db765c45..00000000 --- a/src/pages/options/tiktok/tiktok.pug +++ /dev/null @@ -1,36 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title TikTok -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('tiktok') - - section.option-block - .some-block.option-block - h1 TikTok - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-tiktok(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #proxiTok - hr - .normal - include ../../widgets/instances.pug - +instances('https://proxitok.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://proxitok.onion') - - script(type="module" src="../init.js") - script(type="module" src="./tiktok.js") diff --git a/src/pages/options/translate/translate.html b/src/pages/options/translate/translate.html deleted file mode 100644 index 879917bd..00000000 --- a/src/pages/options/translate/translate.html +++ /dev/null @@ -1,186 +0,0 @@ - - - - - - - - Translate - - - - - -
-
-

Translate

-
-
-
-

Enable

- -
-
-

Frontend

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/translate/translate.js b/src/pages/options/translate/translate.js deleted file mode 100644 index 998ebc32..00000000 --- a/src/pages/options/translate/translate.js +++ /dev/null @@ -1,75 +0,0 @@ -import translateHelper from "../../../assets/javascripts/helpers/translate/translate.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-simplyTranslate"); -let simplyTranslateDiv = document.getElementById("simplyTranslate"); -let lingvaDiv = document.getElementById("lingva"); -let frontend = document.getElementById("translate-frontend"); -let protocol = document.getElementById("protocol"); - - -function changeFrontendsSettings() { - if (frontend.value == 'simplyTranslate') { - simplyTranslateDiv.style.display = 'block'; - lingvaDiv.style.display = 'none'; - } - else if (frontend.value == 'lingva') { - simplyTranslateDiv.style.display = 'none'; - lingvaDiv.style.display = 'block'; - } -} - -function changeProtocolSettings() { - let normalSimplyTranslateDiv = document.getElementById("simplyTranslate").getElementsByClassName("normal")[0]; - let torSimplyTranslateDiv = document.getElementById("simplyTranslate").getElementsByClassName("tor")[0]; - - let normalLingvaDiv = document.getElementById("lingva").getElementsByClassName("normal")[0]; - let torLingvaDiv = document.getElementById("lingva").getElementsByClassName("tor")[0]; - - if (protocol.value == 'normal') { - normalSimplyTranslateDiv.style.display = 'block'; - normalLingvaDiv.style.display = 'block'; - torLingvaDiv.style.display = 'none'; - torSimplyTranslateDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalSimplyTranslateDiv.style.display = 'none'; - normalLingvaDiv.style.display = 'none'; - torLingvaDiv.style.display = 'block'; - torSimplyTranslateDiv.style.display = 'block'; - } -} - -browser.storage.local.get( - [ - "translateDisable", - "translateFrontend", - "translateProtocol", - ], - r => { - disable.checked = !r.translateDisable; - frontend.value = r.translateFrontend; - protocol.value = r.translateProtocol; - changeFrontendsSettings(); - changeProtocolSettings(); - } -); - -document.addEventListener("change", () => { - browser.storage.local.set({ - translateDisable: !disable.checked, - translateFrontend: frontend.value, - translateProtocol: protocol.value, - }) - changeProtocolSettings(); - changeFrontendsSettings(); -}) - - -utils.processDefaultCustomInstances('translate', 'simplyTranslate', 'normal', document) -utils.processDefaultCustomInstances('translate', 'simplyTranslate', 'tor', document); -utils.processDefaultCustomInstances('translate', 'lingva', 'normal', document); -utils.processDefaultCustomInstances('translate', 'lingva', 'tor', document); - -utils.latency('translate', 'simplyTranslate', document, location, true) -utils.latency('translate', 'lingva', document, location, true) \ No newline at end of file diff --git a/src/pages/options/translate/translate.pug b/src/pages/options/translate/translate.pug deleted file mode 100644 index a1689e29..00000000 --- a/src/pages/options/translate/translate.pug +++ /dev/null @@ -1,50 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Translate -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('translate') - - section.option-block - .some-block.option-block - h1 Translate - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-simplyTranslate(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_frontend__") Frontend - select#translate-frontend - option(value="simplyTranslate") SimplyTranslate - option(value="lingva") Lingva - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - hr - #simplyTranslate - .normal - include ../../widgets/instances.pug - +instances('https://simplytranslate.org') - include ../../widgets/latency.pug - +latency('simplyTranslate') - .tor - include ../../widgets/instances.pug - +instances('http://hxecvvetgrznmprg.onion') - #lingva - .normal - include ../../widgets/instances.pug - +instances('https://lingvatranslate.com') - +latency('lingva') - .tor - include ../../widgets/instances.pug - +instances('http://tyzxppdeoojdnaux.onion') - - script(type="module" src="../init.js") - script(type="module" src="./translate.js") diff --git a/src/pages/options/twitter/twitter.html b/src/pages/options/twitter/twitter.html deleted file mode 100644 index 384ba9da..00000000 --- a/src/pages/options/twitter/twitter.html +++ /dev/null @@ -1,128 +0,0 @@ - - - - - - - - Twitter - - - - - -
-
-

Twitter

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/twitter/twitter.js b/src/pages/options/twitter/twitter.js deleted file mode 100644 index 72c3d926..00000000 --- a/src/pages/options/twitter/twitter.js +++ /dev/null @@ -1,53 +0,0 @@ -import twitterHelper from "../../../assets/javascripts/helpers/twitter.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disable = document.getElementById("disable-nitter"); -let protocol = document.getElementById("protocol"); - -let nitterDiv = document.getElementById('nitter'); - -const nitterForm = nitterDiv.getElementsByTagName('form')[0]; -const nitterCookies = nitterForm.getElementsByTagName('input')[0]; -nitterForm.addEventListener('submit', event => { - event.preventDefault(); - const url = new URL(nitterCookies.value); - twitterHelper.initNitterCookies(url); -}); - -browser.storage.local.get( - [ - "disableTwitter", - "twitterProtocol", - ], - r => { - disable.checked = !r.disableTwitter; - protocol.value = r.twitterProtocol; - changeProtocolSettings(); - } -) - -document.addEventListener("change", () => { - browser.storage.local.set({ - disableTwitter: !disable.checked, - twitterProtocol: protocol.value, - }); - changeProtocolSettings(); -}) - -function changeProtocolSettings() { - let normalDiv = nitterDiv.getElementsByClassName("normal")[0]; - let torDiv = nitterDiv.getElementsByClassName("tor")[0]; - if (protocol.value == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - } - else if (protocol.value == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - } -} - -utils.processDefaultCustomInstances('twitter', 'nitter', 'normal', document); -utils.processDefaultCustomInstances('twitter', 'nitter', 'tor', document) - -utils.latency('twitter', 'nitter', document, location) \ No newline at end of file diff --git a/src/pages/options/twitter/twitter.pug b/src/pages/options/twitter/twitter.pug deleted file mode 100644 index 092c3e45..00000000 --- a/src/pages/options/twitter/twitter.pug +++ /dev/null @@ -1,37 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Twitter -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('twitter') - - section.option-block - .some-block.option-block - h1 Twitter - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-nitter(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - #nitter - hr - .normal - include ../../widgets/instances.pug - +instances('https://nitter.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://nitter.onion') - - - script(type="module" src="../init.js") - script(type="module" src="./twitter.js") diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js new file mode 100644 index 00000000..c810fb8a --- /dev/null +++ b/src/pages/options/widgets/general.js @@ -0,0 +1,225 @@ +"use strict"; +window.browser = window.browser || window.chrome; + +import utils from "../../../assets/javascripts/utils.js"; +import generalHelper from "../../../assets/javascripts/general.js"; + +import youtubeHelper from "../../../assets/javascripts/youtube/youtube.js"; +import youtubeMusicHelper from "../../../assets/javascripts/youtubeMusic.js"; +import twitterHelper from "../../../assets/javascripts/twitter.js"; +import instagramHelper from "../../../assets/javascripts/instagram.js"; +import redditHelper from "../../../assets/javascripts/reddit.js"; +import searchHelper from "../../../assets/javascripts/search.js"; +import translateHelper from "../../../assets/javascripts/translate/translate.js"; +import mapsHelper from "../../../assets/javascripts/maps.js"; +import wikipediaHelper from "../../../assets/javascripts/wikipedia.js"; +import mediumHelper from "../../../assets/javascripts/medium.js"; +import imgurHelper from "../../../assets/javascripts/imgur.js"; +import tiktokHelper from "../../../assets/javascripts/tiktok.js"; +import sendTargetsHelper from "../../../assets/javascripts/sendTargets.js"; +import peertubeHelper from "../../../assets/javascripts/peertube.js"; +import lbryHelper from "../../../assets/javascripts/lbry.js"; + +let updateInstancesElement = document.getElementById("update-instances"); +updateInstancesElement.addEventListener("click", () => { + let oldHtml = updateInstancesElement.innerHTML + updateInstancesElement.innerHTML = '...'; + if (utils.updateInstances()) { + updateInstancesElement.innerHTML = 'Done!'; + new Promise(resolve => setTimeout(resolve, 1500)).then( // sleep 1500ms + () => updateInstancesElement.innerHTML = oldHtml + ) + } + else + updateInstancesElement.innerHTML = 'Failed Miserabely'; +}); + +let exportSettingsElement = document.getElementById("export-settings"); + +function exportSettings() { + browser.storage.local.get( + null, + result => { + let resultString = JSON.stringify(result, null, ' '); + exportSettingsElement.href = 'data:application/json;base64,' + btoa(resultString); + exportSettingsElement.download = 'libredirect-settings.json'; + } + ); +} +exportSettings(); + +browser.storage.onChanged.addListener(exportSettings); + +let importSettingsElement = document.getElementById("import-settings"); +let importSettingsElementText = document.getElementById('import_settings_text'); +importSettingsElement.addEventListener("change", + () => { + let file = importSettingsElement.files[0]; + const reader = new FileReader(); + reader.readAsText(file); + reader.onload = async () => { + const data = JSON.parse(reader.result) + if ( + "theme" in data && + "disableImgur" in data && + "cloudflareList" in data && + "imgurRedirects" in data + ) { + console.log('importing a valid file...'); + await browser.storage.local.set({ ...data }) + location.reload(); + } else + importError() + } + reader.onerror = error => importError(); + } +); +function importError() { + const oldHTML = importSettingsElementText.innerHTML; + importSettingsElementText.innerHTML = 'Error!'; + setTimeout(() => importSettingsElementText.innerHTML = oldHTML, 1000); +} + +document.getElementById("reset-settings").addEventListener("click", + async () => { + await browser.storage.local.clear(); + fetch('/instances/blocklist.json').then(response => response.text()).then(async data => { + await browser.storage.local.set({ cloudflareList: JSON.parse(data) }) + await generalHelper.initDefaults(); + await youtubeHelper.initDefaults(); + await youtubeMusicHelper.initDefaults(); + await twitterHelper.initDefaults(); + await instagramHelper.initDefaults(); + await mapsHelper.initDefaults(); + await searchHelper.initDefaults(); + await translateHelper.initDefaults(); + await mediumHelper.initDefaults(); + await redditHelper.initDefaults(); + await wikipediaHelper.initDefaults(); + await imgurHelper.initDefaults(); + await tiktokHelper.initDefaults(); + await sendTargetsHelper.initDefaults(); + await peertubeHelper.initDefaults(); + await lbryHelper.initDefaults(); + location.reload(); + }) + } +); + +let autoRedirectElement = document.getElementById("auto-redirect") +autoRedirectElement.addEventListener("change", + event => browser.storage.local.set({ autoRedirect: event.target.checked }) +); + +let themeElement = document.getElementById("theme"); +themeElement.addEventListener("change", event => { + const value = event.target.options[theme.selectedIndex].value; + browser.storage.local.set({ theme: value }); + location.reload(); +}) + +let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance"); +let instanceTypeElement = document.getElementById("exceptions-custom-instance-type"); +let instanceType = "url" + +let popupFrontends; +for (const frontend of generalHelper.allPopupFrontends) + document.getElementById(frontend).addEventListener("change", + event => { + if (event.target.checked && !popupFrontends.includes(frontend)) + popupFrontends.push(frontend) + else if (popupFrontends.includes(frontend)) { + var index = popupFrontends.indexOf(frontend); + if (index !== -1) popupFrontends.splice(index, 1); + } + browser.storage.local.set({ popupFrontends }) + } + ) + + +browser.storage.local.get( + [ + 'theme', + 'autoRedirect', + 'exceptions' + ], + r => { + autoRedirectElement.checked = r.autoRedirect; + themeElement.value = r.theme; + instanceTypeElement.addEventListener("change", + event => { + instanceType = event.target.options[instanceTypeElement.selectedIndex].value + if (instanceType == 'url') { + nameCustomInstanceInput.setAttribute("type", "url"); + nameCustomInstanceInput.setAttribute("placeholder", "https://www.google.com"); + } + else if (instanceType == 'regex') { + nameCustomInstanceInput.setAttribute("type", "text"); + nameCustomInstanceInput.setAttribute("placeholder", "https?:\/\/(www\.|)youtube\.com\/"); + } + } + ) + let exceptionsCustomInstances = r.exceptions; + function calcExceptionsCustomInstances() { + document.getElementById("exceptions-custom-checklist").innerHTML = + [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex].map( + (x) => `
+ ${x} + +
+
` + ).join('\n'); + + for (const x of [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex]) { + document.getElementById(`clear-${x}`).addEventListener("click", + () => { + console.log(x); + let index; + index = exceptionsCustomInstances.url.indexOf(x); + if (index > -1) + exceptionsCustomInstances.url.splice(index, 1); + else { + index = exceptionsCustomInstances.regex.indexOf(x); + if (index > -1) + exceptionsCustomInstances.regex.splice(index, 1); + } + browser.storage.local.set({ exceptions: exceptionsCustomInstances }) + calcExceptionsCustomInstances(); + }); + } + } + calcExceptionsCustomInstances(); + document.getElementById("custom-exceptions-instance-form").addEventListener("submit", (event) => { + event.preventDefault(); + + let val + if (instanceType == 'url') { + if (nameCustomInstanceInput.validity.valid) { + let url = new URL(nameCustomInstanceInput.value); + val = `${url.protocol}//${url.host}` + if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val) + } + } else if (instanceType == 'regex') { + val = nameCustomInstanceInput.value + if (val.trim() != '' && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val) + } + if (val) { + browser.storage.local.set({ exceptions: exceptionsCustomInstances }) + nameCustomInstanceInput.value = ''; + } + calcExceptionsCustomInstances(); + }) + + browser.storage.local.get('popupFrontends', + r => { + popupFrontends = r.popupFrontends; + for (const frontend of generalHelper.allPopupFrontends) + document.getElementById(frontend).checked = popupFrontends.includes(frontend); + } + ) + }) diff --git a/src/pages/options/widgets/general.pug b/src/pages/options/widgets/general.pug new file mode 100644 index 00000000..c1fcc459 --- /dev/null +++ b/src/pages/options/widgets/general.pug @@ -0,0 +1,167 @@ +section#general_page.option-block + .some-block.option-block + h1(data-localise="__MSG_general__") General + hr + + .some-block.option-block + h4(data-localise="__MSG_theme__") Theme + select#theme + option(value="DEFAULT" data-localise="__MSG_system__") System + option(value="light" data-localise="__MSG_light__") Light + option(value="dark" data-localise="__MSG_dark__") Dark + + .some-block.option-block + h4(data-localise="__MSG_autoRedirect__") + input#auto-redirect(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_exceptions__") + + form#custom-exceptions-instance-form + .some-block.option-block + .some-block(style="padding:0;") + input#exceptions-custom-instance(placeholder="https://www.google.com" type="url") + |  + select#exceptions-custom-instance-type + option(value="url") URL + option(value="regex") Regex + |  + button#exceptions-add-instance.add(type="submit") + svg(xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor") + path(d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z") + + #exceptions-custom-checklist.checklist + + .buttons.buttons-inline + a#update-instances.button.button-inline + svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") + path(d="M19 9h-4V3H9v6H5l7 7 7-7zM5 18v2h14v-2H5z") + x(data-localise="__MSG_updateInstances__") Update Instances + + |    + + label#import_settings_text.button.button-inline(for="import-settings") + svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") + path(d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z") + |  + x(data-localise="__MSG_importSettings__") Import Settings + input#import-settings.button.button-inline(type="file" style="display:none;") + + |    + + a#export-settings.button.button-inline + svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") + path(d="M10.09 15.59L11.5 17l5-5-5-5-1.41 1.41L12.67 11H3v2h9.67l-2.58 2.59zM19 3H5c-1.11 0-2 .9-2 2v4h2V5h14v14H5v-4H3v4c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2z") + |  + x(data-localise="__MSG_exportSettings__") Export Settings + + |    + + a#reset-settings.button.button-inline + svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") + path(d="M12,5V2L8,6l4,4V7c3.31,0,6,2.69,6,6c0,2.97-2.17,5.43-5,5.91v2.02c3.95-0.49,7-3.85,7-7.93C20,8.58,16.42,5,12,5z") + path(d="M6,13c0-1.65,0.67-3.15,1.76-4.24L6.34,7.34C4.9,8.79,4,10.79,4,13c0,4.08,3.05,7.44,7,7.93v-2.02 C8.17,18.43,6,15.97,6,13z") + x(data-localise="__MSG_resetSettings__") Reset Settings + hr + + .some-block.option-block + h4(data-localise="__MSG_customPopup__") Customize Popup + + #popup-frontends-checklist.checklist-popup + div + div + img(src="../../../assets/images/youtube-icon.png") + x(data-localise="__MSG_youtube__") YouTube + input#youtube(type="checkbox") + div + div + img(src="../../../assets/images/youtube-music-icon.png") + x(data-localise="__MSG_ytmusic__") YoutubeMusic + input#youtubeMusic(type="checkbox") + div + div + img(src="../../../assets/images/twitter-icon.png") + x(data-localise="__MSG_twitter__") Twitter + input#twitter(type="checkbox") + + div + div + img(src="../../../assets/images/instagram-icon.png") + x(data-localise="__MSG_instagram__") Instagram + input#instagram(type="checkbox") + + div + div + img(src="../../../assets/images/tiktok-icon.png") + x(data-localise="__MSG_tiktok__") TikTok + input#tikTok(type="checkbox") + + div + div + img(src="../../../assets/images/imgur-icon.png") + x(data-localise="__MSG_imgur__") Imgur + input#imgur(type="checkbox") + + div + div + img(src="../../../assets/images/reddit-icon.png") + x(data-localise="__MSG_reddit__") Reddit + input#reddit(type="checkbox") + + div + div + svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") + path(d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z") + x(data-localise="__MSG_search__") Search + input#search(type="checkbox") + + div + div + svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") + path(d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z") + x(data-localise="__MSG_translate__") Translate + input#translate(type="checkbox") + + div + div + svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") + path(d="M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM10 5.47l4 1.4v11.66l-4-1.4V5.47zm-5 .99l3-1.01v11.7l-3 1.16V6.46zm14 11.08l-3 1.01V6.86l3-1.16v11.84z") + x(data-localise="__MSG_maps__") Maps + input#maps(type="checkbox") + + div + div + img(src="../../../assets/images/wikipedia-icon.svg") + x(data-localise="__MSG_wikipedia__") Wikipedia + input#wikipedia(type="checkbox") + + div + div + svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1770 1000" fill="currentColor") + circle(cx="500" cy="500" r="500") + ellipse(ry="475" rx="250" cy="501" cx="1296") + ellipse(cx="1682" cy="502" rx="88" ry="424") + x(data-localise="__MSG_medium__") Medium + input#medium(type="checkbox") + + div + div + img(src="../../../assets/images/peertube-icon.svg") + x(data-localise="__MSG_peertube__") PeerTube + input#peertube(type="checkbox") + + div + div + img(src="../../../assets/images/lbry-icon.png") + x(data-localise="__MSG_lbry__") LBRY/Odysee + input#lbry(type="checkbox") + + div + div + svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") + path(d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z") + x(data-localise="__MSG_sendFiles__") Send Files + input#sendTargets(type="checkbox") + + + script(type="module" src="./widgets/general.js") \ No newline at end of file diff --git a/src/pages/options/widgets/imgur.js b/src/pages/options/widgets/imgur.js new file mode 100644 index 00000000..036f33ed --- /dev/null +++ b/src/pages/options/widgets/imgur.js @@ -0,0 +1,52 @@ +import imgurHelper from "../../../assets/javascripts/imgur.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disableImgurElement = document.getElementById("disable-imgur"); +let protocolElement = document.getElementById("protocol") + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableImgur: !disableImgurElement.checked, + imgurProtocol: protocolElement.value, + }); + changeProtocolSettings(protocolElement.value); +}) + +function changeProtocolSettings(protocol) { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + let i2pDiv = document.getElementsByClassName("i2p")[0]; + if (protocol == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + i2pDiv.style.display = 'none'; + } + else if (protocol == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + i2pDiv.style.display = 'none'; + } + else if (protocol == 'i2p') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'none'; + i2pDiv.style.display = 'block'; + } +} + +browser.storage.local.get( + [ + "disableImgur", + "imgurProtocol", + ], + r => { + disableImgurElement.checked = !r.disableImgur; + protocolElement.value = r.imgurProtocol; + changeProtocolSettings(r.imgurProtocol); + } +); + +utils.processDefaultCustomInstances('imgur', 'rimgo', 'normal', document); +utils.processDefaultCustomInstances('imgur', 'rimgo', 'tor', document); +utils.processDefaultCustomInstances('imgur', 'rimgo', 'i2p', document); + +utils.latency('imgur', 'rimgo', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/imgur.pug b/src/pages/options/widgets/imgur.pug new file mode 100644 index 00000000..45104cd3 --- /dev/null +++ b/src/pages/options/widgets/imgur.pug @@ -0,0 +1,32 @@ +section#imgur_page.option-block + .some-block.option-block + h1(data-localise="__MSG_imgur__") Imgur + hr + + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-imgur(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + option(value="i2p" data-localise="__MSG_i2p__") I2P + + #rimgo + hr + .normal + include ../../widgets/instances.pug + +instances('https://rimgo.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://rimgo.onion') + + .i2p + include ../../widgets/instances.pug + +instances('https://rimgo.onion') + + script(type="module" src="./widgets/imgur.js") \ No newline at end of file diff --git a/src/pages/options/widgets/instagram.js b/src/pages/options/widgets/instagram.js new file mode 100644 index 00000000..f04fc8c5 --- /dev/null +++ b/src/pages/options/widgets/instagram.js @@ -0,0 +1,42 @@ +import instagramHelper from "../../../assets/javascripts/instagram.js"; +import utils from "../../../assets/javascripts/utils.js"; + +const disable = document.getElementById("disable-bibliogram"); +const protocol = document.getElementById("protocol"); + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableInstagram: disable.checked, + instagramProtocol: protocol.value, + }) + changeProtocolSettings(); +}) + +function changeProtocolSettings() { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +browser.storage.local.get( + [ + "disableInstagram", + "instagramProtocol" + ], + r => { + disable.checked = !r.disableInstagram; + protocol.value = r.instagramProtocol; + changeProtocolSettings(); + }) + +utils.processDefaultCustomInstances('instagram', 'bibliogram', 'normal', document); +utils.processDefaultCustomInstances('instagram', 'bibliogram', 'tor', document); + +utils.latency('instagram', 'bibliogram', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/instagram.pug b/src/pages/options/widgets/instagram.pug new file mode 100644 index 00000000..e5698b41 --- /dev/null +++ b/src/pages/options/widgets/instagram.pug @@ -0,0 +1,27 @@ +section#instagram_page.option-block + .some-block.option-block + h1(data-localise="__MSG_instagram__") Instagram + hr + + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-bibliogram(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #bibliogram + hr + .normal + include ../../widgets/instances.pug + +instances('https://bibliogram.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://bibliogram.onion') + + script(type="module" src="./widgets/instagram.js") \ No newline at end of file diff --git a/src/pages/options/widgets/lbry.js b/src/pages/options/widgets/lbry.js new file mode 100644 index 00000000..2aac362f --- /dev/null +++ b/src/pages/options/widgets/lbry.js @@ -0,0 +1,43 @@ +import lbryHelper from "../../../assets/javascripts/lbry.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-lbry"); +let protocol = document.getElementById("protocol") + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableLbryTargets: !lbryHelper.checked, + lbryTargetsProtocol: protocol.value, + }); + changeProtocolSettings() +}) + +function changeProtocolSettings() { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +browser.storage.local.get( + [ + "disableLbryTargets", + "lbryTargetsProtocol" + ], + r => { + disable.checked = !r.disableLbryTargets; + protocol.value = r.lbryTargetsProtocol; + changeProtocolSettings(); + } +) + +utils.processDefaultCustomInstances('lbryTargets', 'librarian', 'normal', document); +utils.processDefaultCustomInstances('lbryTargets', 'librarian', 'tor', document); + +utils.latency('lbryTargets', 'librarian', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/lbry.pug b/src/pages/options/widgets/lbry.pug new file mode 100644 index 00000000..21c4f497 --- /dev/null +++ b/src/pages/options/widgets/lbry.pug @@ -0,0 +1,26 @@ +section#lbry_page.option-block + .some-block.option-block + h1(data-localise="__MSG_lbry__") LBRY/Odysee + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-lbry(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #librarian + hr + .normal + include ../../widgets/instances.pug + +instances('https://librarian.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://librarian.onion') + + script(type="module" src="./widgets/lbry.js") \ No newline at end of file diff --git a/src/pages/options/widgets/maps.js b/src/pages/options/widgets/maps.js new file mode 100644 index 00000000..ddfa8345 --- /dev/null +++ b/src/pages/options/widgets/maps.js @@ -0,0 +1,32 @@ +import mapsHelper from "../../../assets/javascripts/maps.js"; +import utils from "../../../assets/javascripts/utils.js"; + +const disable = document.getElementById("disable-osm"); +const frontend = document.getElementById("maps-frontend"); + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableMaps: !disable.checked, + mapsFrontend: frontend.value, + }) + changeFrontendsSettings(); +}) + +const facilDiv = document.getElementById("facil") +function changeFrontendsSettings() { + if (frontend.value == 'facil') facilDiv.style.display = 'block'; + else if (frontend.value == 'osm') facilDiv.style.display = 'none'; +} + +browser.storage.local.get( + [ + "disableMaps", + "mapsFrontend", + ], + r => { + disable.checked = !r.disableMaps; + frontend.value = r.mapsFrontend; + changeFrontendsSettings(); + } +) +utils.processDefaultCustomInstances('maps', 'facil', 'normal', document); \ No newline at end of file diff --git a/src/pages/options/widgets/maps.pug b/src/pages/options/widgets/maps.pug new file mode 100644 index 00000000..b36c3521 --- /dev/null +++ b/src/pages/options/widgets/maps.pug @@ -0,0 +1,23 @@ +section#maps_page.option-block + .some-block.option-block + h1(data-localise="__MSG_maps__") Maps + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-osm(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_frontend__") Frontend + select#maps-frontend + option(value="osm") OpenStreetMap + option(value="facil") Facil Map + + #facil + hr + .normal + include ../../widgets/instances.pug + +instances('https://facilmap.com') + include ../../widgets/latency.pug + +latency() + + script(type="module" src="./widgets/maps.js") \ No newline at end of file diff --git a/src/pages/options/widgets/medium.js b/src/pages/options/widgets/medium.js new file mode 100644 index 00000000..085d6804 --- /dev/null +++ b/src/pages/options/widgets/medium.js @@ -0,0 +1,42 @@ +import mediumHelper from "../../../assets/javascripts/medium.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-medium"); +let protocol = document.getElementById("protocol") + +browser.storage.local.get( + [ + "disableMedium", + "mediumProtocol" + ], + r => { + disable.checked = !r.disableMedium; + protocol.value = r.mediumProtocol; + changeProtocolSettings(); + } +) +utils.processDefaultCustomInstances('medium', 'scribe', 'normal', document); +utils.processDefaultCustomInstances('medium', 'scribe', 'tor', document); + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableMedium: !disable.checked, + mediumProtocol: protocol.value, + }) + changeProtocolSettings(); +}) + +function changeProtocolSettings() { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +utils.latency('medium', 'scribe', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/medium.pug b/src/pages/options/widgets/medium.pug new file mode 100644 index 00000000..10c18f6d --- /dev/null +++ b/src/pages/options/widgets/medium.pug @@ -0,0 +1,26 @@ +section#medium_page.option-block + .some-block.option-block + h1(data-localise="__MSG_medium__") Medium + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-medium(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #scribe + hr + .normal + include ../../widgets/instances.pug + +instances('https://scribe.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://scribe.onion') + + script(type="module" src="./widgets/medium.js") \ No newline at end of file diff --git a/src/pages/options/widgets/peertube.js b/src/pages/options/widgets/peertube.js new file mode 100644 index 00000000..f2cede89 --- /dev/null +++ b/src/pages/options/widgets/peertube.js @@ -0,0 +1,40 @@ +import peertubeHelper from "../../../assets/javascripts/peertube.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-peertube"); +let protocol = document.getElementById("protocol") +browser.storage.local.get( + [ + "disablePeertubeTargets", + "peertubeTargetsProtocol" + ], + r => { + disable.checked = !r.disablePeertubeTargets; + protocol.value = r.peertubeTargetsProtocol; + changeProtocolSettings(); + } +) +utils.processDefaultCustomInstances('peertube', 'simpleertube', 'normal', document); +utils.processDefaultCustomInstances('peertube', 'simpleertube', 'tor', document); + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disablePeertubeTargets: !disable.checked, + peertubeTargetsProtocol: protocol.value + }) + changeProtocolSettings(); +}) + +function changeProtocolSettings() { + const normalDiv = document.getElementsByClassName("normal")[0]; + const torDiv = document.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} +utils.latency('peertube', 'simpleertube', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/peertube.pug b/src/pages/options/widgets/peertube.pug new file mode 100644 index 00000000..496fb2df --- /dev/null +++ b/src/pages/options/widgets/peertube.pug @@ -0,0 +1,26 @@ +section#peertube_page.option-block + .some-block.option-block + h1(data-localise="__MSG_peertube__") PeerTube + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-peertube(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #simpleertube + hr + .normal + include ../../widgets/instances.pug + +instances('https://simpleertube.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://simpleertube.onion') + + script(type="module" src="./widgets/peertube.js") \ No newline at end of file diff --git a/src/pages/options/widgets/reddit.js b/src/pages/options/widgets/reddit.js new file mode 100644 index 00000000..da4221aa --- /dev/null +++ b/src/pages/options/widgets/reddit.js @@ -0,0 +1,90 @@ +import redditHelper from "../../../assets/javascripts/reddit.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let libredditDivElement = document.getElementById("libreddit") +let tedditDivElement = document.getElementById("teddit") + +let disableRedditElement = document.getElementById("disable-reddit"); +let frontend = document.getElementById("reddit-frontend"); +let protocol = document.getElementById("protocol") + +document.addEventListener("change", () => { + browser.storage.local.set({ + disableReddit: !disableRedditElement.checked, + redditProtocol: protocol.value, + redditFrontend: frontend.value, + }); + changeFrontendsSettings(); + changeProtocolSettings(); +}) + +const libredditForm = libredditDivElement.getElementsByTagName('form')[0]; +const libredditCookies = libredditForm.getElementsByTagName('input')[0]; +libredditForm.addEventListener('submit', async event => { + event.preventDefault(); + const url = new URL(libredditCookies.value); + redditHelper.initLibredditCookies(url); +}); + +const tedditForm = tedditDivElement.getElementsByTagName('form')[0]; +const tedditCookies = tedditForm.getElementsByTagName('input')[0]; +tedditForm.addEventListener('submit', async event => { + event.preventDefault(); + const url = new URL(tedditCookies.value); + redditHelper.initTedditCookies(url); +}); + +function changeProtocolSettings() { + let normalLibredditDiv = libredditDivElement.getElementsByClassName("normal")[0]; + let torLibredditDiv = libredditDivElement.getElementsByClassName("tor")[0]; + + let normalTedditDiv = tedditDivElement.getElementsByClassName("normal")[0]; + let torTedditDiv = tedditDivElement.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalLibredditDiv.style.display = 'block'; + normalTedditDiv.style.display = 'block'; + torTedditDiv.style.display = 'none'; + torLibredditDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalLibredditDiv.style.display = 'none'; + normalTedditDiv.style.display = 'none'; + torTedditDiv.style.display = 'block'; + torLibredditDiv.style.display = 'block'; + } +} +function changeFrontendsSettings() { + if (frontend.value == 'libreddit') { + libredditDivElement.style.display = 'block'; + tedditDivElement.style.display = 'none'; + } + else if (frontend.value == 'teddit') { + libredditDivElement.style.display = 'none'; + tedditDivElement.style.display = 'block'; + } +} + +browser.storage.local.get( + [ + "disableReddit", + "redditProtocol", + "redditFrontend", + + "enableLibredditCustomSettings", + ], + r => { + disableRedditElement.checked = !r.disableReddit + protocol.value = r.redditProtocol + frontend.value = r.redditFrontend + changeFrontendsSettings(); + changeProtocolSettings(); + } +) + +utils.processDefaultCustomInstances('reddit', 'libreddit', 'normal', document); +utils.processDefaultCustomInstances('reddit', 'libreddit', 'tor', document); +utils.processDefaultCustomInstances('reddit', 'teddit', 'normal', document); +utils.processDefaultCustomInstances('reddit', 'teddit', 'tor', document); + +utils.latency('reddit', 'libreddit', document, location, true) +utils.latency('reddit', 'teddit', document, location, true) \ No newline at end of file diff --git a/src/pages/options/widgets/reddit.pug b/src/pages/options/widgets/reddit.pug new file mode 100644 index 00000000..ae72b31f --- /dev/null +++ b/src/pages/options/widgets/reddit.pug @@ -0,0 +1,42 @@ +section#reddit_page.option-block + .some-block.option-block + h1(data-localise="__MSG_reddit__") Reddit + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-reddit(type="checkbox") + + .some-block.option-block + h4#frontend(data-localise="__MSG_frontend__") Frontend + select#reddit-frontend + option(value="libreddit") Libreddit + option(value="teddit") Teddit + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #libreddit + hr + .normal + include ../../widgets/instances.pug + +instances('https://libreddit.com') + include ../../widgets/latency.pug + +latency('libreddit') + .tor + include ../../widgets/instances.pug + +instances('https://libreddit.onion') + + #teddit + hr + .normal + include ../../widgets/instances.pug + +instances('https://teddit.com') + +latency('teddit') + .tor + include ../../widgets/instances.pug + +instances('https://teddit.onion') + + script(type="module" src="./widgets/reddit.js") \ No newline at end of file diff --git a/src/pages/options/widgets/search.js b/src/pages/options/widgets/search.js new file mode 100644 index 00000000..2506279a --- /dev/null +++ b/src/pages/options/widgets/search.js @@ -0,0 +1,142 @@ +import searchHelper from "../../../assets/javascripts/search.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let searxDiv = document.getElementById("searx"); +let searxngDiv = document.getElementById("searxng"); +let whoogleDiv = document.getElementById("whoogle"); + +let disable = document.getElementById("disable-search"); +let frontend = document.getElementById("search-frontend"); +let protocol = document.getElementById("protocol") + +const searxngForm = searxngDiv.getElementsByTagName('form')[0]; +const searxngCookies = searxngForm.getElementsByTagName('input')[0]; +searxngForm.addEventListener('submit', async event => { + event.preventDefault(); + const url = new URL(searxngCookies.value); + searchHelper.initSearxngCookies(url); +}); + +const searxForm = searxDiv.getElementsByTagName('form')[0]; +const searxCookies = searxForm.getElementsByTagName('input')[0]; +searxForm.addEventListener('submit', async event => { + event.preventDefault(); + const url = new URL(searxCookies.value); + searchHelper.initSearxCookies(url); +}); + +browser.storage.local.get( + [ + "disableSearch", + "searchFrontend", + "searchProtocol", + ], + r => { + disable.checked = !r.disableSearch; + frontend.value = r.searchFrontend; + protocol.value = r.searchProtocol; + + changeFrontendsSettings(); + changeProtocolSettings(); + } +); + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableSearch: !disable.checked, + searchFrontend: frontend.value, + searchProtocol: protocol.value, + }); + changeFrontendsSettings(frontend.value); + changeProtocolSettings(protocol.value); +}) + +function changeFrontendsSettings() { + let SearxWhoogleElement = document.getElementById("searx-whoogle"); + if (frontend.value == 'searx') { + searxDiv.style.display = 'block'; + searxngDiv.style.display = 'none'; + whoogleDiv.style.display = 'none'; + SearxWhoogleElement.style.display = 'block'; + } + else if (frontend.value == 'searxng') { + searxDiv.style.display = 'none'; + searxngDiv.style.display = 'block'; + whoogleDiv.style.display = 'none'; + SearxWhoogleElement.style.display = 'block'; + } + else if (frontend.value == 'whoogle') { + searxDiv.style.display = 'none'; + searxngDiv.style.display = 'none'; + whoogleDiv.style.display = 'block'; + SearxWhoogleElement.style.display = 'block'; + } +} + +function changeProtocolSettings() { + let normalsearxDiv = searxDiv.getElementsByClassName("normal")[0]; + let torsearxDiv = searxDiv.getElementsByClassName("tor")[0]; + let i2psearxDiv = searxDiv.getElementsByClassName("i2p")[0]; + + let normalsearxngDiv = searxngDiv.getElementsByClassName("normal")[0]; + let torsearxngDiv = searxngDiv.getElementsByClassName("tor")[0]; + let i2psearxngDiv = searxngDiv.getElementsByClassName("i2p")[0]; + + let normalwhoogleDiv = whoogleDiv.getElementsByClassName("normal")[0]; + let torwhoogleDiv = whoogleDiv.getElementsByClassName("tor")[0]; + let i2pwhoogleDiv = whoogleDiv.getElementsByClassName("i2p")[0]; + + if (protocol.value == 'normal') { + normalsearxDiv.style.display = 'block'; + normalsearxngDiv.style.display = 'block'; + normalwhoogleDiv.style.display = 'block'; + + torsearxDiv.style.display = 'none'; + torsearxngDiv.style.display = 'none'; + torwhoogleDiv.style.display = 'none'; + + i2psearxDiv.style.display = 'none'; + i2psearxngDiv.style.display = 'none'; + i2pwhoogleDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalsearxDiv.style.display = 'none'; + normalsearxngDiv.style.display = 'none'; + normalwhoogleDiv.style.display = 'none'; + + torsearxDiv.style.display = 'block'; + torsearxngDiv.style.display = 'block'; + torwhoogleDiv.style.display = 'block'; + + i2psearxDiv.style.display = 'none'; + i2psearxngDiv.style.display = 'none'; + i2pwhoogleDiv.style.display = 'none'; + } + else if (protocol.value == 'i2p') { + normalsearxDiv.style.display = 'none'; + normalsearxngDiv.style.display = 'none'; + normalwhoogleDiv.style.display = 'none'; + + torsearxDiv.style.display = 'none'; + torsearxngDiv.style.display = 'none'; + torwhoogleDiv.style.display = 'none'; + + i2psearxDiv.style.display = 'block'; + i2psearxngDiv.style.display = 'block'; + i2pwhoogleDiv.style.display = 'block'; + } +} + +utils.processDefaultCustomInstances('search', 'searx', 'normal', document); +utils.processDefaultCustomInstances('search', 'searx', 'tor', document); +utils.processDefaultCustomInstances('search', 'searx', 'i2p', document); +utils.processDefaultCustomInstances('search', 'searxng', 'normal', document); +utils.processDefaultCustomInstances('search', 'searxng', 'tor', document); +utils.processDefaultCustomInstances('search', 'searxng', 'i2p', document); +utils.processDefaultCustomInstances('search', 'whoogle', 'normal', document); +utils.processDefaultCustomInstances('search', 'whoogle', 'tor', document); +utils.processDefaultCustomInstances('search', 'whoogle', 'i2p', document); + +utils.latency('search', 'searx', document, location, true) +utils.latency('search', 'searxng', document, location, true) +utils.latency('search', 'whoogle', document, location, true) diff --git a/src/pages/options/widgets/search.pug b/src/pages/options/widgets/search.pug new file mode 100644 index 00000000..feea4b0d --- /dev/null +++ b/src/pages/options/widgets/search.pug @@ -0,0 +1,69 @@ + +section#search_page.option-block + .some-block.option-block + h1(data-localise="__MSG_search__") Search + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-search(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_frontend__") Frontend + select#search-frontend + option(value="searxng") SearXNG + option(value="searx") SearX + option(value="whoogle") Whoogle + + + #searx-whoogle + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + option(value="i2p" data-localise="__MSG_i2p__") I2P + + .some-block + h4(data-localise="__MSG_searchNote__") Note: To use Search to its full potential, make LibRedirect as the Default Search Engine + + #searx + hr + .normal + include ../../widgets/instances.pug + +instances('https://searx.com') + include ../../widgets/latency.pug + +latency('searx') + .tor + include ../../widgets/instances.pug + +instances('https://searx.onion') + .i2p + include ../../widgets/instances.pug + +instances('https://searx.i2p') + + #searxng + hr + .normal + include ../../widgets/instances.pug + +instances('https://searxng.com') + +latency('searxng') + .tor + include ../../widgets/instances.pug + +instances('https://searxng.onion') + .i2p + include ../../widgets/instances.pug + +instances('https://searxng.i2p') + + #whoogle + hr + .normal + include ../../widgets/instances.pug + +instances('https://whoogle.com') + +latency('whoogle') + .tor + include ../../widgets/instances.pug + +instances('https://whoogle.onion') + .i2p + include ../../widgets/instances.pug + +instances('https://whoogle.i2p') + + script(type="module" src="./widgets/search.js") \ No newline at end of file diff --git a/src/pages/options/widgets/sendTargets.js b/src/pages/options/widgets/sendTargets.js new file mode 100644 index 00000000..37e2588e --- /dev/null +++ b/src/pages/options/widgets/sendTargets.js @@ -0,0 +1,43 @@ +import sendTargetsHelper from "../../../assets/javascripts/sendTargets.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-sendTargets"); +let protocol = document.getElementById("protocol") + +browser.storage.local.get( + [ + "disableSendTarget", + "sendTargetsProtocol", + ], + r => { + disable.checked = !r.disableSendTarget; + protocol.value = r.sendTargetsProtocol; + changeProtocolSettings(); + } +) + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableSendTarget: !disable.checked, + sendTargetsProtocol: protocol.value, + }) + changeProtocolSettings(); +}) + +function changeProtocolSettings() { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +utils.processDefaultCustomInstances('sendTargets', 'send', 'normal', document); +utils.processDefaultCustomInstances('sendTargets', 'send', 'tor', document); + +utils.latency('sendTargets', 'send', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/sendTargets.pug b/src/pages/options/widgets/sendTargets.pug new file mode 100644 index 00000000..c4a933d1 --- /dev/null +++ b/src/pages/options/widgets/sendTargets.pug @@ -0,0 +1,26 @@ +section#sendTargets_page.option-block + .some-block.option-block + h1(data-localise="__MSG_sendFiles__") Send Files + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-sendTargets(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #send + hr + .normal + include ../../widgets/instances.pug + +instances('https://send.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://send.onion') + + script(type="module" src="./widgets/sendTargets.js") \ No newline at end of file diff --git a/src/pages/options/widgets/tiktok.js b/src/pages/options/widgets/tiktok.js new file mode 100644 index 00000000..6b5702e1 --- /dev/null +++ b/src/pages/options/widgets/tiktok.js @@ -0,0 +1,53 @@ +import tiktokHelper from "../../../assets/javascripts/tiktok.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-tiktok"); +let protocol = document.getElementById("protocol") + +document.addEventListener("change", () => { + browser.storage.local.set({ + disableTiktok: !disable.checked, + tiktokProtocol: protocol.value, + }); + changeProtocolSettings(); +}) + +browser.storage.local.get( + [ + "disableTiktok", + "tiktokProtocol", + ], + r => { + disable.checked = !r.disableTiktok; + protocol.value = r.tiktokProtocol; + changeProtocolSettings(); + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + if (r.tiktokProtocol == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (r.tiktokProtocol == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } + } +) + +function changeProtocolSettings() { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +utils.processDefaultCustomInstances('tiktok', 'proxiTok', 'normal', document); +utils.processDefaultCustomInstances('tiktok', 'proxiTok', 'tor', document); + +utils.latency('tiktok', 'proxiTok', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/tiktok.pug b/src/pages/options/widgets/tiktok.pug new file mode 100644 index 00000000..ec55671c --- /dev/null +++ b/src/pages/options/widgets/tiktok.pug @@ -0,0 +1,26 @@ +section#tiktok_page.option-block + .some-block.option-block + h1(data-localise="__MSG_tiktok__") TikTok + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-tiktok(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #proxiTok + hr + .normal + include ../../widgets/instances.pug + +instances('https://proxitok.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://proxitok.onion') + + script(type="module" src="./widgets/tiktok.js") diff --git a/src/pages/options/widgets/translate.js b/src/pages/options/widgets/translate.js new file mode 100644 index 00000000..3e1990f4 --- /dev/null +++ b/src/pages/options/widgets/translate.js @@ -0,0 +1,75 @@ +import translateHelper from "../../../assets/javascripts/translate/translate.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-simplyTranslate"); +let simplyTranslateDiv = document.getElementById("simplyTranslate"); +let lingvaDiv = document.getElementById("lingva"); +let frontend = document.getElementById("translate-frontend"); +let protocol = document.getElementById("protocol"); + + +function changeFrontendsSettings() { + if (frontend.value == 'simplyTranslate') { + simplyTranslateDiv.style.display = 'block'; + lingvaDiv.style.display = 'none'; + } + else if (frontend.value == 'lingva') { + simplyTranslateDiv.style.display = 'none'; + lingvaDiv.style.display = 'block'; + } +} + +function changeProtocolSettings() { + let normalSimplyTranslateDiv = document.getElementById("simplyTranslate").getElementsByClassName("normal")[0]; + let torSimplyTranslateDiv = document.getElementById("simplyTranslate").getElementsByClassName("tor")[0]; + + let normalLingvaDiv = document.getElementById("lingva").getElementsByClassName("normal")[0]; + let torLingvaDiv = document.getElementById("lingva").getElementsByClassName("tor")[0]; + + if (protocol.value == 'normal') { + normalSimplyTranslateDiv.style.display = 'block'; + normalLingvaDiv.style.display = 'block'; + torLingvaDiv.style.display = 'none'; + torSimplyTranslateDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalSimplyTranslateDiv.style.display = 'none'; + normalLingvaDiv.style.display = 'none'; + torLingvaDiv.style.display = 'block'; + torSimplyTranslateDiv.style.display = 'block'; + } +} + +browser.storage.local.get( + [ + "translateDisable", + "translateFrontend", + "translateProtocol", + ], + r => { + disable.checked = !r.translateDisable; + frontend.value = r.translateFrontend; + protocol.value = r.translateProtocol; + changeFrontendsSettings(); + changeProtocolSettings(); + } +); + +document.addEventListener("change", () => { + browser.storage.local.set({ + translateDisable: !disable.checked, + translateFrontend: frontend.value, + translateProtocol: protocol.value, + }) + changeProtocolSettings(); + changeFrontendsSettings(); +}) + + +utils.processDefaultCustomInstances('translate', 'simplyTranslate', 'normal', document) +utils.processDefaultCustomInstances('translate', 'simplyTranslate', 'tor', document); +utils.processDefaultCustomInstances('translate', 'lingva', 'normal', document); +utils.processDefaultCustomInstances('translate', 'lingva', 'tor', document); + +utils.latency('translate', 'simplyTranslate', document, location, true) +utils.latency('translate', 'lingva', document, location, true) \ No newline at end of file diff --git a/src/pages/options/widgets/translate.pug b/src/pages/options/widgets/translate.pug new file mode 100644 index 00000000..a97a4245 --- /dev/null +++ b/src/pages/options/widgets/translate.pug @@ -0,0 +1,40 @@ +section#translate_page.option-block + .some-block.option-block + h1(data-localise="__MSG_translate__") Translate + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-simplyTranslate(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_frontend__") Frontend + select#translate-frontend + option(value="simplyTranslate") SimplyTranslate + option(value="lingva") Lingva + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + hr + #simplyTranslate + .normal + include ../../widgets/instances.pug + +instances('https://simplytranslate.org') + include ../../widgets/latency.pug + +latency('simplyTranslate') + .tor + include ../../widgets/instances.pug + +instances('http://hxecvvetgrznmprg.onion') + #lingva + .normal + include ../../widgets/instances.pug + +instances('https://lingvatranslate.com') + +latency('lingva') + .tor + include ../../widgets/instances.pug + +instances('http://tyzxppdeoojdnaux.onion') + + script(type="module" src="./widgets/translate.js") diff --git a/src/pages/options/widgets/twitter.js b/src/pages/options/widgets/twitter.js new file mode 100644 index 00000000..266fd027 --- /dev/null +++ b/src/pages/options/widgets/twitter.js @@ -0,0 +1,53 @@ +import twitterHelper from "../../../assets/javascripts/twitter.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disable = document.getElementById("disable-nitter"); +let protocol = document.getElementById("protocol"); + +let nitterDiv = document.getElementById('nitter'); + +const nitterForm = nitterDiv.getElementsByTagName('form')[0]; +const nitterCookies = nitterForm.getElementsByTagName('input')[0]; +nitterForm.addEventListener('submit', event => { + event.preventDefault(); + const url = new URL(nitterCookies.value); + twitterHelper.initNitterCookies(url); +}); + +browser.storage.local.get( + [ + "disableTwitter", + "twitterProtocol", + ], + r => { + disable.checked = !r.disableTwitter; + protocol.value = r.twitterProtocol; + changeProtocolSettings(); + } +) + +document.addEventListener("change", () => { + browser.storage.local.set({ + disableTwitter: !disable.checked, + twitterProtocol: protocol.value, + }); + changeProtocolSettings(); +}) + +function changeProtocolSettings() { + let normalDiv = nitterDiv.getElementsByClassName("normal")[0]; + let torDiv = nitterDiv.getElementsByClassName("tor")[0]; + if (protocol.value == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol.value == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + +utils.processDefaultCustomInstances('twitter', 'nitter', 'normal', document); +utils.processDefaultCustomInstances('twitter', 'nitter', 'tor', document) + +utils.latency('twitter', 'nitter', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/twitter.pug b/src/pages/options/widgets/twitter.pug new file mode 100644 index 00000000..af743dcd --- /dev/null +++ b/src/pages/options/widgets/twitter.pug @@ -0,0 +1,26 @@ +section#twitter_page.option-block + .some-block.option-block + h1(data-localise="__MSG_twitter__") Twitter + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-nitter(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + #nitter + hr + .normal + include ../../widgets/instances.pug + +instances('https://nitter.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://nitter.onion') + + script(type="module" src="./widgets/twitter.js") diff --git a/src/pages/options/widgets/wikipedia.js b/src/pages/options/widgets/wikipedia.js new file mode 100644 index 00000000..6e847c8d --- /dev/null +++ b/src/pages/options/widgets/wikipedia.js @@ -0,0 +1,51 @@ +import wikipediaHelper from "../../../assets/javascripts/wikipedia.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disableWikipediaElement = document.getElementById("disable-wikipedia"); +let protocolElement = document.getElementById("protocol"); + +browser.storage.local.get( + [ + "disableWikipedia", + "wikipediaProtocol", + ], + r => { + disableWikipediaElement.checked = !r.disableWikipedia; + protocolElement.value = r.wikipediaProtocol; + changeProtocolSettings(r.wikipediaProtocol); + } +) + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableWikipedia: !disableWikipediaElement.checked, + wikipediaProtocol: protocolElement.value, + }) + changeProtocolSettings(protocolElement.value) +}) + +function changeProtocolSettings(protocol) { + let normalDiv = document.getElementsByClassName("normal")[0]; + let torDiv = document.getElementsByClassName("tor")[0]; + let i2pDiv = document.getElementsByClassName("i2p")[0]; + if (protocol == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + i2pDiv.style.display = 'none'; + } + else if (protocol == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + i2pDiv.style.display = 'none'; + } + else if (protocol == 'i2p') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'none'; + i2pDiv.style.display = 'block'; + } +} +utils.processDefaultCustomInstances('wikipedia', 'wikiless', 'normal', document); +utils.processDefaultCustomInstances('wikipedia', 'wikiless', 'tor', document); +utils.processDefaultCustomInstances('wikipedia', 'wikiless', 'i2p', document); + +utils.latency('wikipedia', 'wikiless', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/wikipedia.pug b/src/pages/options/widgets/wikipedia.pug new file mode 100644 index 00000000..79d1e323 --- /dev/null +++ b/src/pages/options/widgets/wikipedia.pug @@ -0,0 +1,32 @@ +section#wikipedia_page.option-block + .some-block.option-block + h1(data-localise="__MSG_wikipedia__") Wikipedia + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-wikipedia(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + option(value="i2p" data-localise="__MSG_i2p__") I2P + + #wikiless + hr + .normal + include ../../widgets/instances.pug + +instances('https://wikiless.com') + include ../../widgets/latency.pug + +latency() + .tor + include ../../widgets/instances.pug + +instances('https://wikiless.onion') + + .i2p + include ../../widgets/instances.pug + +instances('https://wikiless.i2p') + + script(type="module" src="./widgets/wikipedia.js") + \ No newline at end of file diff --git a/src/pages/options/widgets/youtube.js b/src/pages/options/widgets/youtube.js new file mode 100644 index 00000000..7826541b --- /dev/null +++ b/src/pages/options/widgets/youtube.js @@ -0,0 +1,161 @@ +import youtubeHelper from "../../../assets/javascripts/youtube/youtube.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disableYoutube = document.getElementById("disable-invidious"); +let youtubeFrontend = document.getElementById("youtube-frontend"); +let invidiousDiv = document.getElementById("invidious"); +let pipedDiv = document.getElementById("piped"); +let pipedMaterialDiv = document.getElementById("pipedMaterial"); +let freetubeYatteeDiv = document.getElementById("freetube-yatte"); +let youtubeEmbedFrontend = document.getElementById("youtube-embed-frontend"); +let OnlyEmbeddedVideo = document.getElementById("only-embed"); +let protoco = document.getElementById("protocol"); + +function changeFrontendsSettings() { + let frontend = youtubeFrontend.value; + + if (frontend == 'invidious') { + invidiousDiv.style.display = 'block'; + pipedDiv.style.display = 'none'; + pipedMaterialDiv.style.display = 'none'; + freetubeYatteeDiv.style.display = 'none'; + } + else if (frontend == 'piped') { + invidiousDiv.style.display = 'none'; + pipedDiv.style.display = 'block'; + pipedMaterialDiv.style.display = 'none'; + freetubeYatteeDiv.style.display = 'none'; + } + else if (frontend == 'pipedMaterial') { + invidiousDiv.style.display = 'none'; + pipedDiv.style.display = 'none'; + pipedMaterialDiv.style.display = 'block'; + freetubeYatteeDiv.style.display = 'none'; + } + else if (frontend == 'freetube' || frontend == 'yatte') { + invidiousDiv.style.display = 'none'; + pipedDiv.style.display = 'none'; + pipedMaterialDiv.style.display = 'none'; + freetubeYatteeDiv.style.display = 'block'; + changeYoutubeEmbedFrontendsSettings(); + } +} + +function changeYoutubeEmbedFrontendsSettings() { + if (youtubeEmbedFrontend.value == 'invidious') { + pipedDiv.style.display = 'none'; + pipedMaterialDiv.style.display = 'none'; + invidiousDiv.style.display = 'block'; + } + if (youtubeEmbedFrontend.value == 'piped') { + pipedDiv.style.display = 'block'; + pipedMaterialDiv.style.display = 'none'; + invidiousDiv.style.display = 'none'; + } + if (youtubeEmbedFrontend.value == 'pipedMaterial') { + pipedDiv.style.display = 'none'; + pipedMaterialDiv.style.display = 'block'; + invidiousDiv.style.display = 'none'; + } + else if (youtubeEmbedFrontend.value == 'youtube') { + pipedDiv.style.display = 'none'; + pipedMaterialDiv.style.display = 'none'; + invidiousDiv.style.display = 'none'; + } +} + +function changeProtocolSettings() { + const normalPipedDiv = document.getElementById('piped').getElementsByClassName("normal")[0]; + const torPipedDiv = document.getElementById('piped').getElementsByClassName("tor")[0]; + + const normalPipedMaterialDiv = document.getElementById('pipedMaterial').getElementsByClassName("normal")[0]; + const torPipedMaterialDiv = document.getElementById('pipedMaterial').getElementsByClassName("tor")[0]; + + const normalInvidiousDiv = document.getElementById('invidious').getElementsByClassName("normal")[0]; + const torInvidiousDiv = document.getElementById('invidious').getElementsByClassName("tor")[0]; + + if (protoco.value == 'normal') { + normalInvidiousDiv.style.display = 'block'; + torInvidiousDiv.style.display = 'none'; + + normalPipedDiv.style.display = 'block'; + torPipedDiv.style.display = 'none'; + + normalPipedMaterialDiv.style.display = 'block'; + torPipedMaterialDiv.style.display = 'none'; + } + else if (protoco.value == 'tor') { + normalInvidiousDiv.style.display = 'none'; + torInvidiousDiv.style.display = 'block'; + + normalPipedDiv.style.display = 'none'; + torPipedDiv.style.display = 'block'; + + normalPipedMaterialDiv.style.display = 'none'; + torPipedMaterialDiv.style.display = 'block'; + } +} + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableYoutube: !disableYoutube.checked, + youtubeFrontend: youtubeFrontend.value, + youtubeEmbedFrontend: youtubeEmbedFrontend.value, + OnlyEmbeddedVideo: OnlyEmbeddedVideo.value, + youtubeProtocol: protoco.value, + }) + changeProtocolSettings(); + changeYoutubeEmbedFrontendsSettings(); + changeFrontendsSettings(); +}) + +browser.storage.local.get( + [ + "disableYoutube", + "OnlyEmbeddedVideo", + "youtubeRedirects", + "youtubeFrontend", + + "youtubeEmbedFrontend", + "youtubeProtocol", + ], + r => { + disableYoutube.checked = !r.disableYoutube; + OnlyEmbeddedVideo.value = r.OnlyEmbeddedVideo; + youtubeFrontend.value = r.youtubeFrontend; + protoco.value = r.youtubeProtocol; + + changeFrontendsSettings(); + changeProtocolSettings(); + + youtubeEmbedFrontend.value = youtubeEmbedFrontend.value + if (r.youtubeFrontend == "freetube" || r.youtubeFrontend == "yatte") changeYoutubeEmbedFrontendsSettings() + } +); + +const invidiousForm = invidiousDiv.getElementsByTagName('form')[0]; +const invidiousCookies = invidiousForm.getElementsByTagName('input')[0]; +invidiousForm.addEventListener('submit', async event => { + event.preventDefault(); + const url = new URL(invidiousCookies.value); + youtubeHelper.initInvidiousCookies(url); +}); + +// const pipedForm = pipedDiv.getElementsByTagName('form')[0]; +// const pipedCookies = pipedForm.getElementsByTagName('input')[0]; +// pipedForm.addEventListener('submit', async event => { +// event.preventDefault(); +// const url = new URL(pipedCookies.value); +// youtubeHelper.applyPipedLocalStorage(url); +// }); + +utils.processDefaultCustomInstances('youtube', 'invidious', 'normal', document); +utils.processDefaultCustomInstances('youtube', 'invidious', 'tor', document); +utils.processDefaultCustomInstances('youtube', 'pipedMaterial', 'normal', document); +utils.processDefaultCustomInstances('youtube', 'pipedMaterial', 'tor', document); +utils.processDefaultCustomInstances('youtube', 'piped', 'normal', document); +utils.processDefaultCustomInstances('youtube', 'piped', 'tor', document); + +utils.latency('youtube', 'invidious', document, location, true) +utils.latency('youtube', 'piped', document, location, true) +utils.latency('youtube', 'pipedMaterial', document, location, true) diff --git a/src/pages/options/widgets/youtube.pug b/src/pages/options/widgets/youtube.pug new file mode 100644 index 00000000..71bf104b --- /dev/null +++ b/src/pages/options/widgets/youtube.pug @@ -0,0 +1,73 @@ +section#youtube_page.option-block + .some-block.option-block + h1(data-localise="__MSG_youtube__") YouTube + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-invidious(type="checkbox") + + .some-block.option-block + h4(data-localise="__MSG_frontend__") Frontend + select#youtube-frontend + option(value="invidious") Invidious + option(value="piped") Piped + option(value="pipedMaterial") Piped-Material + option(value="freetube") FreeTube + option(value="yatte") Yattee + + #freetube-yatte + .some-block.option-block + h4(data-localise="__MSG_embeddedVids__") Embedded Videos Frontend + select#youtube-embed-frontend + option(value="invidious") Invidious + option(value="piped") Piped + option(value="pipedMaterial") Piped-Material + option(value="youtube") Youtube + + #invidious-piped-pipedMaterial + .some-block.option-block + h4(data-localise="__MSG_protocol__") Protocol + select#protocol + option(value="normal" data-localise="__MSG_normal__") Normal + option(value="tor" data-localise="__MSG_tor__") Tor + + .some-block.option-block + h4(data-localise="__MSG_redirectType__") Redirect Type + select#only-embed + option(value="both" data-localise="__MSG_both__") both + option(value="onlyEmbedded" data-localise="__MSG_onlyEmbedded__") Only Embedded + option(value="onlyNotEmbedded" data-localise="__MSG_onlyNotEmbedded__") Only Not Embedded + + #invidious + hr + .normal + include ../../widgets/instances.pug + +instances('https://invidious.com') + include ../../widgets/latency.pug + +latency('invidious') + .tor + include ../../widgets/instances.pug + +instances('https://invidious.onion') + + #piped + hr + .normal + include ../../widgets/instances.pug + +instances('https://piped.com') + +latency('piped') + .tor + include ../../widgets/instances.pug + +instances('https://piped.onion') + + #pipedMaterial + hr + .normal + include ../../widgets/instances.pug + +instances('https://piped-material.com') + +latency('pipedMaterial') + .tor + include ../../widgets/instances.pug + +instances('https://piped-material.onion') + + + script(type="module" src="./widgets/youtube.js") diff --git a/src/pages/options/widgets/youtubeMusic.js b/src/pages/options/widgets/youtubeMusic.js new file mode 100644 index 00000000..9a9bf8fb --- /dev/null +++ b/src/pages/options/widgets/youtubeMusic.js @@ -0,0 +1,23 @@ +import youtubeMusicHelper from "../../../assets/javascripts/youtubeMusic.js"; +import utils from "../../../assets/javascripts/utils.js"; + +let disableYoutubeMusicElement = document.getElementById("disable-beatbump"); + +browser.storage.local.get( + [ + "disableYoutubeMusic", + ], + r => { + disableYoutubeMusicElement.checked = !r.disableYoutubeMusic; + } +); + +document.addEventListener("change", async () => { + await browser.storage.local.set({ + disableYoutubeMusic: !disableYoutubeMusicElement.checked, + }) +}) + +utils.processDefaultCustomInstances('youtubeMusic', 'beatbump', 'normal', document); + +utils.latency('youtubeMusic', 'beatbump', document, location) \ No newline at end of file diff --git a/src/pages/options/widgets/youtubeMusic.pug b/src/pages/options/widgets/youtubeMusic.pug new file mode 100644 index 00000000..231b6caf --- /dev/null +++ b/src/pages/options/widgets/youtubeMusic.pug @@ -0,0 +1,17 @@ +section#youtubeMusic_page.option-block + .some-block.option-block + h1(data-localise="__MSG_ytmusic__") YouTube Music + hr + .some-block.option-block + h4(data-localise="__MSG_enable__") Enable + input#disable-beatbump(type="checkbox") + + #beatbump + hr + .normal + include ../../widgets/instances.pug + +instances('https://beatbump.wewe') + include ../../widgets/latency.pug + +latency() + + script(type="module" src="./widgets/youtubeMusic.js") diff --git a/src/pages/options/wikipedia/wikipedia.html b/src/pages/options/wikipedia/wikipedia.html deleted file mode 100644 index fe735ac5..00000000 --- a/src/pages/options/wikipedia/wikipedia.html +++ /dev/null @@ -1,150 +0,0 @@ - - - - - - - - Wikipedia - - - - - -
-
-

Wikipedia

-
-
-
-

Enable

- -
-
-

Protocol

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/wikipedia/wikipedia.js b/src/pages/options/wikipedia/wikipedia.js deleted file mode 100644 index c421c18a..00000000 --- a/src/pages/options/wikipedia/wikipedia.js +++ /dev/null @@ -1,53 +0,0 @@ -import wikipediaHelper from "../../../assets/javascripts/helpers/wikipedia.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disableWikipediaElement = document.getElementById("disable-wikipedia"); -let protocolElement = document.getElementById("protocol"); - -browser.storage.local.get( - [ - "disableWikipedia", - "wikipediaProtocol", - ], - r => { - disableWikipediaElement.checked = !r.disableWikipedia; - protocolElement.value = r.wikipediaProtocol; - changeProtocolSettings(r.wikipediaProtocol); - } -) - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableWikipedia: !disableWikipediaElement.checked, - wikipediaProtocol: protocolElement.value, - }) - changeProtocolSettings(protocolElement.value) -}) - -function changeProtocolSettings(protocol) { - let normalDiv = document.getElementsByClassName("normal")[0]; - let torDiv = document.getElementsByClassName("tor")[0]; - let i2pDiv = document.getElementsByClassName("i2p")[0]; - if (protocol == 'normal') { - normalDiv.style.display = 'block'; - torDiv.style.display = 'none'; - i2pDiv.style.display = 'none'; - } - else if (protocol == 'tor') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'block'; - i2pDiv.style.display = 'none'; - } - else if (protocol == 'i2p') { - normalDiv.style.display = 'none'; - torDiv.style.display = 'none'; - i2pDiv.style.display = 'block'; - } -} -utils.processDefaultCustomInstances('wikipedia', 'wikiless', 'normal', document); -utils.processDefaultCustomInstances('wikipedia', 'wikiless', 'tor', document); -utils.processDefaultCustomInstances('wikipedia', 'wikiless', 'i2p', document); - -window.onblur = wikipediaHelper.initWikilessCookies; - -utils.latency('wikipedia', 'wikiless', document, location) \ No newline at end of file diff --git a/src/pages/options/wikipedia/wikipedia.pug b/src/pages/options/wikipedia/wikipedia.pug deleted file mode 100644 index d08431db..00000000 --- a/src/pages/options/wikipedia/wikipedia.pug +++ /dev/null @@ -1,41 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title Wikipedia -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('wikipedia') - - section.option-block - .some-block.option-block - h1 Wikipedia - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-wikipedia(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - option(value="i2p" data-localise="__MSG_i2p__") I2P - - #wikiless - hr - .normal - include ../../widgets/instances.pug - +instances('https://wikiless.com') - include ../../widgets/latency.pug - +latency() - .tor - include ../../widgets/instances.pug - +instances('https://wikiless.onion') - - .i2p - include ../../widgets/instances.pug - +instances('https://wikiless.i2p') - - script(type="module" src="../init.js") - script(type="module" src="./wikipedia.js") diff --git a/src/pages/options/youtube/youtube.html b/src/pages/options/youtube/youtube.html deleted file mode 100644 index 2938ccd1..00000000 --- a/src/pages/options/youtube/youtube.html +++ /dev/null @@ -1,263 +0,0 @@ - - - - - - - - YouTube - - - - - -
-
-

YouTube

-
-
-
-

Enable

- -
-
-

Frontend

- -
-
-
-

Embedded Videos Frontend

- -
-
-
-
-

Protocol

- -
-
-

Redirect Type

- -
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
-
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/youtube/youtube.js b/src/pages/options/youtube/youtube.js deleted file mode 100644 index 4f987849..00000000 --- a/src/pages/options/youtube/youtube.js +++ /dev/null @@ -1,161 +0,0 @@ -import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disableYoutube = document.getElementById("disable-invidious"); -let youtubeFrontend = document.getElementById("youtube-frontend"); -let invidiousDiv = document.getElementById("invidious"); -let pipedDiv = document.getElementById("piped"); -let pipedMaterialDiv = document.getElementById("pipedMaterial"); -let freetubeYatteeDiv = document.getElementById("freetube-yatte"); -let youtubeEmbedFrontend = document.getElementById("youtube-embed-frontend"); -let OnlyEmbeddedVideo = document.getElementById("only-embed"); -let protoco = document.getElementById("protocol"); - -function changeFrontendsSettings() { - let frontend = youtubeFrontend.value; - - if (frontend == 'invidious') { - invidiousDiv.style.display = 'block'; - pipedDiv.style.display = 'none'; - pipedMaterialDiv.style.display = 'none'; - freetubeYatteeDiv.style.display = 'none'; - } - else if (frontend == 'piped') { - invidiousDiv.style.display = 'none'; - pipedDiv.style.display = 'block'; - pipedMaterialDiv.style.display = 'none'; - freetubeYatteeDiv.style.display = 'none'; - } - else if (frontend == 'pipedMaterial') { - invidiousDiv.style.display = 'none'; - pipedDiv.style.display = 'none'; - pipedMaterialDiv.style.display = 'block'; - freetubeYatteeDiv.style.display = 'none'; - } - else if (frontend == 'freetube' || frontend == 'yatte') { - invidiousDiv.style.display = 'none'; - pipedDiv.style.display = 'none'; - pipedMaterialDiv.style.display = 'none'; - freetubeYatteeDiv.style.display = 'block'; - changeYoutubeEmbedFrontendsSettings(); - } -} - -function changeYoutubeEmbedFrontendsSettings() { - if (youtubeEmbedFrontend.value == 'invidious') { - pipedDiv.style.display = 'none'; - pipedMaterialDiv.style.display = 'none'; - invidiousDiv.style.display = 'block'; - } - if (youtubeEmbedFrontend.value == 'piped') { - pipedDiv.style.display = 'block'; - pipedMaterialDiv.style.display = 'none'; - invidiousDiv.style.display = 'none'; - } - if (youtubeEmbedFrontend.value == 'pipedMaterial') { - pipedDiv.style.display = 'none'; - pipedMaterialDiv.style.display = 'block'; - invidiousDiv.style.display = 'none'; - } - else if (youtubeEmbedFrontend.value == 'youtube') { - pipedDiv.style.display = 'none'; - pipedMaterialDiv.style.display = 'none'; - invidiousDiv.style.display = 'none'; - } -} - -function changeProtocolSettings() { - const normalPipedDiv = document.getElementById('piped').getElementsByClassName("normal")[0]; - const torPipedDiv = document.getElementById('piped').getElementsByClassName("tor")[0]; - - const normalPipedMaterialDiv = document.getElementById('pipedMaterial').getElementsByClassName("normal")[0]; - const torPipedMaterialDiv = document.getElementById('pipedMaterial').getElementsByClassName("tor")[0]; - - const normalInvidiousDiv = document.getElementById('invidious').getElementsByClassName("normal")[0]; - const torInvidiousDiv = document.getElementById('invidious').getElementsByClassName("tor")[0]; - - if (protoco.value == 'normal') { - normalInvidiousDiv.style.display = 'block'; - torInvidiousDiv.style.display = 'none'; - - normalPipedDiv.style.display = 'block'; - torPipedDiv.style.display = 'none'; - - normalPipedMaterialDiv.style.display = 'block'; - torPipedMaterialDiv.style.display = 'none'; - } - else if (protoco.value == 'tor') { - normalInvidiousDiv.style.display = 'none'; - torInvidiousDiv.style.display = 'block'; - - normalPipedDiv.style.display = 'none'; - torPipedDiv.style.display = 'block'; - - normalPipedMaterialDiv.style.display = 'none'; - torPipedMaterialDiv.style.display = 'block'; - } -} - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableYoutube: !disableYoutube.checked, - youtubeFrontend: youtubeFrontend.value, - youtubeEmbedFrontend: youtubeEmbedFrontend.value, - OnlyEmbeddedVideo: OnlyEmbeddedVideo.value, - youtubeProtocol: protoco.value, - }) - changeProtocolSettings(); - changeYoutubeEmbedFrontendsSettings(); - changeFrontendsSettings(); -}) - -browser.storage.local.get( - [ - "disableYoutube", - "OnlyEmbeddedVideo", - "youtubeRedirects", - "youtubeFrontend", - - "youtubeEmbedFrontend", - "youtubeProtocol", - ], - r => { - disableYoutube.checked = !r.disableYoutube; - OnlyEmbeddedVideo.value = r.OnlyEmbeddedVideo; - youtubeFrontend.value = r.youtubeFrontend; - protoco.value = r.youtubeProtocol; - - changeFrontendsSettings(); - changeProtocolSettings(); - - youtubeEmbedFrontend.value = youtubeEmbedFrontend.value - if (r.youtubeFrontend == "freetube" || r.youtubeFrontend == "yatte") changeYoutubeEmbedFrontendsSettings() - } -); - -const invidiousForm = invidiousDiv.getElementsByTagName('form')[0]; -const invidiousCookies = invidiousForm.getElementsByTagName('input')[0]; -invidiousForm.addEventListener('submit', async event => { - event.preventDefault(); - const url = new URL(invidiousCookies.value); - youtubeHelper.initInvidiousCookies(url); -}); - -// const pipedForm = pipedDiv.getElementsByTagName('form')[0]; -// const pipedCookies = pipedForm.getElementsByTagName('input')[0]; -// pipedForm.addEventListener('submit', async event => { -// event.preventDefault(); -// const url = new URL(pipedCookies.value); -// youtubeHelper.applyPipedLocalStorage(url); -// }); - -utils.processDefaultCustomInstances('youtube', 'invidious', 'normal', document); -utils.processDefaultCustomInstances('youtube', 'invidious', 'tor', document); -utils.processDefaultCustomInstances('youtube', 'pipedMaterial', 'normal', document); -utils.processDefaultCustomInstances('youtube', 'pipedMaterial', 'tor', document); -utils.processDefaultCustomInstances('youtube', 'piped', 'normal', document); -utils.processDefaultCustomInstances('youtube', 'piped', 'tor', document); - -utils.latency('youtube', 'invidious', document, location, true) -utils.latency('youtube', 'piped', document, location, true) -utils.latency('youtube', 'pipedMaterial', document, location, true) diff --git a/src/pages/options/youtube/youtube.pug b/src/pages/options/youtube/youtube.pug deleted file mode 100644 index 6d5d2469..00000000 --- a/src/pages/options/youtube/youtube.pug +++ /dev/null @@ -1,83 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title YouTube -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('youtube') - - section.option-block - .some-block.option-block - h1 YouTube - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-invidious(type="checkbox") - - .some-block.option-block - h4(data-localise="__MSG_frontend__") Frontend - select#youtube-frontend - option(value="invidious") Invidious - option(value="piped") Piped - option(value="pipedMaterial") Piped-Material - option(value="freetube") FreeTube - option(value="yatte") Yattee - - #freetube-yatte - .some-block.option-block - h4(data-localise="__MSG_embeddedVids__") Embedded Videos Frontend - select#youtube-embed-frontend - option(value="invidious") Invidious - option(value="piped") Piped - option(value="pipedMaterial") Piped-Material - option(value="youtube") Youtube - - #invidious-piped-pipedMaterial - .some-block.option-block - h4(data-localise="__MSG_protocol__") Protocol - select#protocol - option(value="normal" data-localise="__MSG_normal__") Normal - option(value="tor" data-localise="__MSG_tor__") Tor - - .some-block.option-block - h4(data-localise="__MSG_redirectType") Redirect Type - select#only-embed - option(value="both" data-localise="__MSG_both__") both - option(value="onlyEmbedded" data-localise="__MSG_onlyEmbedded__") Only Embedded - option(value="onlyNotEmbedded" data-localise="__MSG_onlyNotEmbedded__") Only Not Embedded - - #invidious - hr - .normal - include ../../widgets/instances.pug - +instances('https://invidious.com') - include ../../widgets/latency.pug - +latency('invidious') - .tor - include ../../widgets/instances.pug - +instances('https://invidious.onion') - - #piped - hr - .normal - include ../../widgets/instances.pug - +instances('https://piped.com') - +latency('piped') - .tor - include ../../widgets/instances.pug - +instances('https://piped.onion') - - #pipedMaterial - hr - .normal - include ../../widgets/instances.pug - +instances('https://piped-material.com') - +latency('pipedMaterial') - .tor - include ../../widgets/instances.pug - +instances('https://piped-material.onion') - - - script(type="module" src="../init.js") - script(type="module" src="./youtube.js") diff --git a/src/pages/options/youtubeMusic/youtubeMusic.html b/src/pages/options/youtubeMusic/youtubeMusic.html deleted file mode 100644 index b77a2a88..00000000 --- a/src/pages/options/youtubeMusic/youtubeMusic.html +++ /dev/null @@ -1,100 +0,0 @@ - - - - - - - - YouTube Music - - - - - -
-
-

YouTube Music

-
-
-
-

Enable

- -
-
-
-
-
-

Default Instances

-
-
-
-
-

Custom Instances

-
-
-
- - -
-
-
- - -
-
-
- - - \ No newline at end of file diff --git a/src/pages/options/youtubeMusic/youtubeMusic.js b/src/pages/options/youtubeMusic/youtubeMusic.js deleted file mode 100644 index 167630eb..00000000 --- a/src/pages/options/youtubeMusic/youtubeMusic.js +++ /dev/null @@ -1,23 +0,0 @@ -import youtubeMusicHelper from "../../../assets/javascripts/helpers/youtubeMusic.js"; -import utils from "../../../assets/javascripts/helpers/utils.js"; - -let disableYoutubeMusicElement = document.getElementById("disable-beatbump"); - -browser.storage.local.get( - [ - "disableYoutubeMusic", - ], - r => { - disableYoutubeMusicElement.checked = !r.disableYoutubeMusic; - } -); - -document.addEventListener("change", async () => { - await browser.storage.local.set({ - disableYoutubeMusic: !disableYoutubeMusicElement.checked, - }) -}) - -utils.processDefaultCustomInstances('youtubeMusic', 'beatbump', 'normal', document); - -utils.latency('youtubeMusic', 'beatbump', document, location) \ No newline at end of file diff --git a/src/pages/options/youtubeMusic/youtubeMusic.pug b/src/pages/options/youtubeMusic/youtubeMusic.pug deleted file mode 100644 index ad3271d4..00000000 --- a/src/pages/options/youtubeMusic/youtubeMusic.pug +++ /dev/null @@ -1,27 +0,0 @@ -doctype html -html(lang="en") - include ../../widgets/head.pug - title YouTube Music -script(type="module" src="../../../assets/javascripts/localise.js") -body.option(dir="auto") - include ../../widgets/links.pug - +links('youtubeMusic') - - section.option-block - .some-block.option-block - h1 YouTube Music - hr - .some-block.option-block - h4(data-localise="__MSG_enable__") Enable - input#disable-beatbump(type="checkbox") - - #beatbump - hr - .normal - include ../../widgets/instances.pug - +instances('https://beatbump.wewe') - include ../../widgets/latency.pug - +latency() - - script(type="module" src="../init.js") - script(type="module" src="./youtubeMusic.js") diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 3eb6ba19..5b00b084 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -8,35 +8,35 @@
-

YouTube

+

YouTube

-

YT Music

+

YT Music

-

Twitter

+

Twitter

-

Instagram

+

Instagram

-

TikTok

+

TikTok

-

Imgur

+

Imgur

-

Reddit

+

Reddit

-

Wikipedia

+

Wikipedia

@@ -45,63 +45,63 @@ -

Medium

+

Medium

-

PeerTube

+

PeerTube

-

LBRY

+

LBRY

-

Translate

+

Translate

-

Maps

+

Maps

-

Send Files

+

Send Files


-

Change Instance

+

Change Instance

-

Copy Raw

+

Copy Raw

-

Unify Settings

+

Unify Settings

-

Settings

+

Settings

diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 73890b07..5d309f63 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -1,8 +1,42 @@ "use strict"; window.browser = window.browser || window.chrome; -import utils from "../../assets/javascripts/helpers/utils.js"; -import generalHelper from "../../assets/javascripts/helpers/general.js"; +import utils from "../../assets/javascripts/utils.js"; +import generalHelper from "../../assets/javascripts/general.js"; + +utils.unify(true).then(r => { + if (!r) document.getElementById('unify_div').style.display = 'none'; + else { + const unify = document.getElementById('unify'); + unify.addEventListener("click", () => + browser.runtime.sendMessage({ function: 'unify' }, + response => { + if (response && response.response) { + const textElement = document.getElementById('unify').getElementsByTagName('h4')[0] + const oldHtml = textElement.innerHTML; + textElement.innerHTML = browser.i18n.getMessage('unified'); + setTimeout(() => textElement.innerHTML = oldHtml, 1000); + } + }) + ); + } +}) + +utils.switchInstance(true).then(r => { + if (!r) document.getElementById("change_instance_div").style.display = 'none'; + else document.getElementById("change_instance").addEventListener("click", () => utils.switchInstance(false)); +}); + +utils.copyRaw(true).then(r => { + if (!r) document.getElementById('copy_raw_div').style.display = 'none'; + else { + const copy_raw = document.getElementById('copy_raw'); + copy_raw.addEventListener("click", () => utils.copyRaw(false, copy_raw)); + } +}) + +document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage()); + let disableTwitterElement = document.getElementById("disable-nitter"); let disableYoutubeElement = document.getElementById("disable-youtube"); @@ -37,6 +71,8 @@ browser.storage.local.get( "disablePeertubeTargets", "disableLbryTargets", "disableSendTarget", + + 'popupFrontends', ], r => { disableTwitterElement.checked = !r.disableTwitter; @@ -53,7 +89,13 @@ browser.storage.local.get( disableMediumElement.checked = !r.disableMedium; disablePeertubeElement.checked = !r.disablePeertubeTargets; disableLbryElement.checked = !r.disableLbryTargets; - disableSendTargetsElement.checked = r.disableSendTarget; + disableSendTargetsElement.checked = !r.disableSendTarget; + + for (const frontend of generalHelper.allPopupFrontends) + if (!r.popupFrontends.includes(frontend)) + document.getElementById(frontend).classList.add("hide") + else + document.getElementById(frontend).classList.remove("hide") } ) @@ -77,51 +119,6 @@ document.addEventListener("change", () => { }); }) -utils.switchInstance(true).then(r => { - if (!r) document.getElementById("change_instance_div").style.display = 'none'; - else document.getElementById("change_instance").addEventListener("click", () => utils.switchInstance(false)); -}); - -utils.copyRaw(true).then(r => { - if (!r) document.getElementById('copy_raw_div').style.display = 'none'; - else { - const copy_raw = document.getElementById('copy_raw'); - copy_raw.addEventListener("click", () => utils.copyRaw(false, copy_raw)); - } -}) - - -utils.unify(true).then(r => { - if (!r) document.getElementById('unify_div').style.display = 'none'; - else { - const unify = document.getElementById('unify'); - unify.addEventListener("click", () => - browser.runtime.sendMessage({ function: 'unify' }, - response => { - if (response && response.response) { - const textElement = document.getElementById('unify').getElementsByTagName('h4')[0] - const oldHtml = textElement.innerHTML; - textElement.innerHTML = 'Unified'; - setTimeout(() => textElement.innerHTML = oldHtml, 1000); - } - }) - ); - } -}) - -document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage()); - -browser.storage.local.get( - 'popupFrontends', - r => { - for (const frontend of generalHelper.allPopupFrontends) - if (!r.popupFrontends.includes(frontend)) - document.getElementById(frontend).classList.add("hide") - else - document.getElementById(frontend).classList.remove("hide") - } -); - for (const a of document.getElementsByTagName('a')) { a.addEventListener('click', e => { if (!a.classList.contains('button')) { diff --git a/src/pages/popup/popup.pug b/src/pages/popup/popup.pug index 94f65eae..a2c8de93 100644 --- a/src/pages/popup/popup.pug +++ b/src/pages/popup/popup.pug @@ -11,117 +11,116 @@ html(lang="en") #youtube.some-block a.title(href="https://youtube.com") img(src="../../assets/images/youtube-icon.png") - h4 YouTube + h4(data-localise="__MSG_youtube__") YouTube input#disable-youtube(type="checkbox") #youtubeMusic.some-block a.title(href="https://music.youtube.com") img(src="../../assets/images/youtube-music-icon.png") - h4 YT Music + h4(data-localise="__MSG_ytmusic__") YT Music input#disable-youtubeMusic(type="checkbox") #twitter.some-block a.title(href="https://twitter.com") img(src="../../assets/images/twitter-icon.png") - h4 Twitter + h4(data-localise="__MSG_twitter__") Twitter input#disable-nitter(type="checkbox") #instagram.some-block a.title(href="https://instagram.com") img(src="../../assets/images/instagram-icon.png") - h4 Instagram + h4(data-localise="__MSG_instagram__") Instagram input#disable-bibliogram(type="checkbox") #tikTok.some-block a.title(href="https://tiktok.com") img(src="../../assets/images/tiktok-icon.png") - h4 TikTok + h4(data-localise="__MSG_tiktok__") TikTok input#disable-tiktok(type="checkbox") #imgur.some-block a.title(href="https://imgur.com") img(src="../../assets/images/imgur-icon.png") - h4 Imgur + h4(data-localise="__MSG_imgur__") Imgur input#disable-imgur(type="checkbox") #reddit.some-block a.title(href="https://reddit.com") img(src="../../assets/images/reddit-icon.png") - h4 Reddit + h4(data-localise="__MSG_reddit__") Reddit input#disable-reddit(type="checkbox") #wikipedia.some-block a.title(href="https://wikipedia.com") img(src="../../assets/images/wikipedia-icon.svg") - h4 Wikipedia + h4(data-localise="__MSG_wikipedia__") Wikipedia input#disable-wikipedia(type="checkbox") #medium.some-block a.title(href="https://medium.com") +medium - h4 Medium + h4(data-localise="__MSG_medium__") Medium input#disable-medium(type="checkbox") #peertube.some-block a.title(href="https://search.joinpeertube.org") img(src="../../assets/images/peertube-icon.svg") - h4 PeerTube + h4(data-localise="__MSG_peertube__") PeerTube input#disable-peertube(type="checkbox") #lbry.some-block a.title(href="https://odysee.com/") img(src="../../assets/images/lbry-icon.png") - h4 LBRY + h4(data-localise="__MSG_lbry__") LBRY input#disable-lbry(type="checkbox") #search.some-block a.title(href="https://search.libredirect.invalid") +search - h4 Search + h4(data-localise="__MSG_search__") Search input#disable-search(type="checkbox") #translate.some-block a.title(href="https://translate.google.com") +translate - h4 Translate + h4(data-localise="__MSG_translate__") Translate input#disable-simplyTranslate(type="checkbox") #maps.some-block a.title(href="https://www.openstreetmap.org") +maps - h4 Maps + h4(data-localise="__MSG_maps__") Maps input#disable-osm(type="checkbox") #sendTargets.some-block a.title(href="https://send.libredirect.invalid") +send - h4 Send Files + h4(data-localise="__MSG_sendFiles__") Send Files input#disable-sendTargets(type="checkbox") hr #change_instance_div.some-block a#change_instance.title.button - h4 Change Instance + h4(data-localise="__MSG_switchInstance__") Change Instance +change_instance #copy_raw_div.some-block(title="Copy the original redirected link") a#copy_raw.title.button - h4 Copy Raw + h4(data-localise="__MSG_copyRaw__") Copy Raw +copy_raw #unify_div.some-block(title="Unify cookies across all selected instances") a#unify.title.button - h4 Unify Settings + h4(data-localise="__MSG_unifySettings__") Unify Settings +unify .some-block a#more-options.title.button - h4 Settings + h4(data-localise="__MSG_settings__") Settings +settings .space script(type="module" src="../options/init.js") - script(type="module" src="./popup.js") - //- script(src="../../assets/javascripts/localise.js") \ No newline at end of file + script(type="module" src="./popup.js") \ No newline at end of file diff --git a/src/pages/stylesheets/styles.css b/src/pages/stylesheets/styles.css index f4027c28..e04f638f 100644 --- a/src/pages/stylesheets/styles.css +++ b/src/pages/stylesheets/styles.css @@ -112,6 +112,7 @@ body.option { section.links div { margin: 20px 0; + width: max-content; } a { @@ -297,11 +298,6 @@ div.buttons-popup { margin-right: 5px; } -body.rtl { - margin-right: 0; - margin-left: 5px; -} - .button:hover svg { color: var(--active); } @@ -449,4 +445,8 @@ button { display: inline-block; cursor: pointer; border-radius: 5px; +} + +body div section { + display: none; } \ No newline at end of file diff --git a/src/pages/widgets/icons.pug b/src/pages/widgets/icons.pug index 60186693..89e207a0 100644 --- a/src/pages/widgets/icons.pug +++ b/src/pages/widgets/icons.pug @@ -37,7 +37,6 @@ mixin general svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="26px" viewBox="0 0 24 24" width="26px" fill="currentColor") path(d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z") - mixin unify svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") path(d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z") \ No newline at end of file diff --git a/src/pages/widgets/links.pug b/src/pages/widgets/links.pug index 97601966..7a04a991 100644 --- a/src/pages/widgets/links.pug +++ b/src/pages/widgets/links.pug @@ -1,67 +1,67 @@ include ../widgets/icons.pug mixin links(service) - section.links + section#links.links .title +general - a(href="../general/general.html" data-localise="__MSG_general__" class=service == "general" ? "selected" : "") General + a(href="#general" data-localise="__MSG_general__") General .title img(src="../../../assets/images/youtube-icon.png") - a(href="../youtube/youtube.html" data-localise="__MSG_youtube__" class=service == "youtube" ? "selected" : "") YouTube + a(href="#youtube" data-localise="__MSG_youtube__") YouTube .title img(src="../../../assets/images/youtube-music-icon.png") - a(href="../youtubeMusic/youtubeMusic.html" data-localise="__MSG_ytmusic__" class=service == "youtubeMusic" ? "selected" : "") YT Music + a(href="#youtubeMusic" data-localise="__MSG_ytmusic__") YT Music .title img(src="../../../assets/images/twitter-icon.png") - a(href="../twitter/twitter.html" class=service == "twitter" ? "selected" : "" data-localise="__MSG_twitter__") Twitter + a(href="#twitter" data-localise="__MSG_twitter__") Twitter .title img(src="../../../assets/images/instagram-icon.png") - a(href="../instagram/instagram.html" data-localise="__MSG_instagram__" class=service == "instagram" ? "selected" : "") Instagram + a(href="#instagram" data-localise="__MSG_instagram__") Instagram .title img(src="../../../assets/images/tiktok-icon.png") - a(href="../tiktok/tiktok.html" data-localise="__MSG_tiktok__" class=service == "tiktok" ? "selected" : "") TikTok + a(href="#tiktok" data-localise="__MSG_tiktok__") TikTok .title img(src="../../../assets/images/reddit-icon.png") - a(href="../reddit/reddit.html" data-localise="__MSG_reddit__" class=service == "reddit" ? "selected" : "") Reddit + a(href="#reddit" data-localise="__MSG_reddit__") Reddit .title img(src="../../../assets/images/imgur-icon.png") - a(href="../imgur/imgur.html" data-localise="__MSG_imgur__" class=service == "imgur" ? "selected" : "") Imgur + a(href="#imgur" data-localise="__MSG_imgur__") Imgur .title img(src="../../../assets/images/wikipedia-icon.svg") - a(href="../wikipedia/wikipedia.html" data-localise="__MSG_wikipedia__" class=service == "wikipedia" ? "selected" : "") Wikipedia + a(href="#wikipedia" data-localise="__MSG_wikipedia__") Wikipedia .title +medium - a(href="../medium/medium.html" data-localise="__MSG_medium__" class=service == "medium" ? "selected" : "") Medium + a(href="#medium" data-localise="__MSG_medium__") Medium .title img(src="../../../assets/images/peertube-icon.svg") - a(href="../peertube/peertube.html" data-localise="__MSG_peertube__" class=service == "peertube" ? "selected" : "") PeerTube + a(href="#peertube" data-localise="__MSG_peertube__") PeerTube .title img(src="../../../assets/images/lbry-icon.png") - a(href="../lbry/lbry.html" data-localise="__MSG_lbry__" class=service == "lbry" ? "selected" : "") LBRY/Odysee + a(href="#lbry" data-localise="__MSG_lbry__") LBRY/Odysee .title +search - a(href="../search/search.html" data-localise="__MSG_search__" class=service == "search" ? "selected" : "") Search + a(href="#search" data-localise="__MSG_search__") Search .title +translate - a(href="../translate/translate.html" data-localise="__MSG_translate__" class=service == "translate" ? "selected" : "") Translate + a(href="#translate" data-localise="__MSG_translate__") Translate .title +maps - a(href="../maps/maps.html" data-localise="__MSG_maps__" class=service == "maps" ? "selected" : "") Maps + a(href="#maps" data-localise="__MSG_maps__") Maps .title +send - a(href="../sendTargets/sendTargets.html" data-localise="__MSG_sendFiles__" class=service == "sendTargets" ? "selected" : "") Send Files \ No newline at end of file + a(href="#sendTargets" data-localise="__MSG_sendFiles__") Send Files \ No newline at end of file -- cgit 1.4.1