Added proxiTok settings #197

This commit is contained in:
ManeraKai 2022-04-27 19:51:34 +03:00
parent cd0596c2eb
commit eb1d01b063
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
8 changed files with 308 additions and 233 deletions

View File

@ -18,8 +18,29 @@ body.option(dir="auto")
option(value="normal" data-localise="__MSG_normal__") Normal option(value="normal" data-localise="__MSG_normal__") Normal
option(value="tor" data-localise="__MSG_tor__") Tor option(value="tor" data-localise="__MSG_tor__") Tor
.some-block.option-block
h4(data-localise="__MSG_enableCustomSettings__") Enable Custom Settings (will use cookies)
input#enable-custom-settings(type="checkbox")
#proxiTok #proxiTok
hr hr
.custom-settings
.some-block.option-block
h2 General
.some-block.option-block
h4(data-localise="__MSG_theme__") Theme
select.theme
option(value="default") Default
option(value="card") Card
.some-block.option-block
h2 Api
.some-block.option-block
h4(data-localise="__MSG_legacyMode__") Legacy mode
select.api-legacy
option(value="on") On
option(value="off") Off
.normal .normal
include ../../widgets/instances.pug include ../../widgets/instances.pug
+instances('https://proxitok.com') +instances('https://proxitok.com')

View File

@ -7,18 +7,15 @@ const targets = [
/^https?:\/{2}(i\.|preview\.)redd\.it/, /^https?:\/{2}(i\.|preview\.)redd\.it/,
]; ];
let redirects = { let redirects = {
// modern UI
"libreddit": { "libreddit": {
"normal": [], "normal": [],
"tor": [] "tor": []
}, },
// old UI
"teddit": { "teddit": {
"normal": [], "normal": [],
"tor": [] "tor": []
}, },
"desktop": "https://old.reddit.com", // desktop "desktop": "https://old.reddit.com", // desktop
"mobile": "https://i.reddit.com", // mobile
}; };
const getRedirects = () => redirects; const getRedirects = () => redirects;
const getCustomRedirects = function () { const getCustomRedirects = function () {
@ -186,10 +183,7 @@ function initLibredditCookies() {
} }
} }
function initTedditCookies() { function initTedditCookies() {
let themeValue; if (enableCustom) {
if (theme == 'light') themeValue = 'white';
if (theme == 'dark') themeValue = 'dark';
if (enableCustom && themeValue) {
let checkedInstances = [ let checkedInstances = [
...tedditNormalRedirectsChecks, ...tedditNormalRedirectsChecks,
...tedditNormalCustomRedirects, ...tedditNormalCustomRedirects,
@ -200,13 +194,14 @@ function initTedditCookies() {
browser.cookies.set({ browser.cookies.set({
url: instanceUrl, url: instanceUrl,
name: "theme", name: "theme",
value: themeValue value: theme == 'dark' ? 'dark' : 'white'
}) })
} }
} }
let alwaysUsePreferred; let alwaysUsePreferred;
function redirect(url, type, initiator) {
// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4 // https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4
// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png // https://libreddit.exonip.de/img/4v3t1vgvrzk81.png
@ -218,8 +213,6 @@ let alwaysUsePreferred;
// https://v.redd.it/z08avb339n801/DASH_1_2_M // https://v.redd.it/z08avb339n801/DASH_1_2_M
// https://i.redd.it/bfkhs659tzk81.jpg // https://i.redd.it/bfkhs659tzk81.jpg
function redirect(url, type, initiator) {
if (disableReddit) return null; if (disableReddit) return null;
let protocolHost = commonHelper.protocolHost(url); let protocolHost = commonHelper.protocolHost(url);
@ -263,7 +256,6 @@ function redirect(url, type, initiator) {
if ( if (
bypassWatchOnReddit && bypassWatchOnReddit &&
initiator && initiator &&
(
[...redirects.libreddit.normal, [...redirects.libreddit.normal,
...redirects.libreddit.tor, ...redirects.libreddit.tor,
...libredditNormalCustomRedirects, ...libredditNormalCustomRedirects,
@ -273,7 +265,6 @@ function redirect(url, type, initiator) {
...tedditNormalCustomRedirects, ...tedditNormalCustomRedirects,
...tedditTorCustomRedirects, ...tedditTorCustomRedirects,
].includes(initiator.origin) ].includes(initiator.origin)
)
) return 'BYPASSTAB'; ) return 'BYPASSTAB';
if (type !== "main_frame" || url.pathname.match(bypassPaths)) return null; if (type !== "main_frame" || url.pathname.match(bypassPaths)) return null;

View File

@ -81,24 +81,43 @@ function setDisable(val) {
} }
let protocol; let protocol;
const getProtocol = () => protocol; let enableCustom;
function setProtocol(val) {
protocol = val; let theme;
browser.storage.local.set({ tiktokProtocol: val }) let api_legacy;
console.log("tiktokProtocol: ", val)
function initProxiTokCookies() {
console.log('initProxiTokCookies')
if (enableCustom) {
let checkedInstances = [
...proxiTokNormalRedirectsChecks,
...proxiTokNormalCustomRedirects,
...proxiTokTorRedirectsChecks,
...proxiTokTorCustomRedirects
]
for (const instance of checkedInstances) {
browser.cookies.set({ url: instance, name: "theme", value: theme })
browser.cookies.set({ url: instance, name: "api-legacy", value: api_legacy ? 'on' : 'off' })
}
}
} }
function isTiktok(url, initiator) { function redirect(url, type, initiator) {
if (disable) return false; if (disable) return;
if (initiator && ([...redirects.proxiTok.normal, ...proxiTokNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host))) return false; if (initiator &&
return targets.some(rx => rx.test(url.href)); (
} [
...redirects.proxiTok.normal,
function redirect(url, type) { ...proxiTokNormalCustomRedirects
// https://www.tiktok.com/@keysikaspol/video/7061265241887345946?for_redirection=@keysikaspol ].includes(initiator.origin) ||
// https://proxitok.pussthecat.org/video/7061265241887345946 targets.includes(initiator.host)
)
) return;
if (!targets.some(rx => rx.test(url.href))) return;
// https://www.tiktok.com/@keysikaspol/video/7061265241887345946
// https://www.tiktok.com/@keysikaspol // https://www.tiktok.com/@keysikaspol
// https://proxitok.herokuapp.com/video/7061265241887345946
if (type != "main_frame") return null; if (type != "main_frame") return null;
@ -108,8 +127,6 @@ function redirect(url, type) {
if (instancesList.length === 0) return null; if (instancesList.length === 0) return null;
let randomInstance = commonHelper.getRandomInstance(instancesList); let randomInstance = commonHelper.getRandomInstance(instancesList);
// let pathName = url.pathname.replace(/@.*\/(?=video)/, "");
return `${randomInstance}${url.pathname}`; return `${randomInstance}${url.pathname}`;
} }
@ -125,13 +142,43 @@ function reverse(url) {
return `https://tiktok.com${url.pathname}${url.search}`; return `https://tiktok.com${url.pathname}${url.search}`;
} }
async 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: {
'proxiTok': redirects.proxiTok,
},
proxiTokNormalRedirectsChecks: [...redirects.proxiTok.normal],
proxiTokNormalCustomRedirects: [],
proxiTokTorRedirectsChecks: [...redirects.proxiTok.tor],
proxiTokTorCustomRedirects: [],
enableTiktokCustomSettings: false,
proxiTokTheme: 'default',
proxiTokApiLegacy: 'off',
});
resolve();
});
})
}
async function init() { async function init() {
return new Promise(resolve => { return new Promise(resolve => {
fetch('/instances/data.json').then(response => response.text()).then(data => { console.log('redirects', redirects)
let dataJson = JSON.parse(data);
browser.storage.local.get( browser.storage.local.get(
[ [
"disableTiktok", "disableTiktok",
"tiktokProtocol",
"tiktokRedirects", "tiktokRedirects",
"proxiTokNormalRedirectsChecks", "proxiTokNormalRedirectsChecks",
@ -140,27 +187,31 @@ async function init() {
"proxiTokTorRedirectsChecks", "proxiTokTorRedirectsChecks",
"proxiTokTorCustomRedirects", "proxiTokTorCustomRedirects",
"tiktokProtocol" "enableTiktokCustomSettings",
"proxiTokTheme",
"proxiTokApiLegacy",
], ],
r => { r => {
redirects.proxiTok = dataJson.proxiTok; disable = r.disableTiktok;
disable = r.disableTiktok ?? false; protocol = r.tiktokProtocol;
redirects = r.tiktokRedirects;
protocol = r.tiktokProtocol ?? "normal"; proxiTokNormalRedirectsChecks = r.proxiTokNormalRedirectsChecks;
proxiTokNormalCustomRedirects = r.proxiTokNormalCustomRedirects;
if (r.tiktokRedirects) redirects = r.tiktokRedirects; proxiTokTorRedirectsChecks = r.proxiTokTorRedirectsChecks;
proxiTokTorCustomRedirects = r.proxiTokTorCustomRedirects;
proxiTokNormalRedirectsChecks = r.proxiTokNormalRedirectsChecks ?? [...redirects.proxiTok.normal]; enableCustom = r.enableTiktokCustomSettings;
proxiTokNormalCustomRedirects = r.proxiTokNormalCustomRedirects ?? [];
proxiTokTorRedirectsChecks = r.proxiTokTorRedirectsChecks ?? [...redirects.proxiTok.tor]; theme = r.proxiTokTheme;
proxiTokTorCustomRedirects = r.proxiTokTorCustomRedirects ?? []; api_legacy = r.proxiTokApiLegacy;
resolve(); resolve();
} }
) )
}); })
});
} }
export default { export default {
@ -174,9 +225,6 @@ export default {
reverse, reverse,
getProtocol,
setProtocol,
getProxiTokNormalRedirectsChecks, getProxiTokNormalRedirectsChecks,
setProxiTokNormalRedirectsChecks, setProxiTokNormalRedirectsChecks,
getProxiTokTorRedirectsChecks, getProxiTokTorRedirectsChecks,
@ -187,7 +235,9 @@ export default {
getProxiTokNormalCustomRedirects, getProxiTokNormalCustomRedirects,
setProxiTokNormalCustomRedirects, setProxiTokNormalCustomRedirects,
initProxiTokCookies,
redirect, redirect,
isTiktok, initDefaults,
init, init,
}; };

View File

@ -25,6 +25,7 @@ window.browser = window.browser || window.chrome;
browser.runtime.onInstalled.addListener(async details => { browser.runtime.onInstalled.addListener(async details => {
if (details.reason == 'install') { if (details.reason == 'install') {
await redditHelper.initDefaults(); await redditHelper.initDefaults();
await tiktokHelper.initDefaults();
await wholeInit(); await wholeInit();
} }
}); });
@ -85,7 +86,7 @@ browser.webRequest.onBeforeRequest.addListener(
if (imgurHelper.isImgur(url, initiator)) newUrl = imgurHelper.redirect(url, details.type); if (imgurHelper.isImgur(url, initiator)) newUrl = imgurHelper.redirect(url, details.type);
if (tiktokHelper.isTiktok(url, initiator)) newUrl = tiktokHelper.redirect(url, details.type); if (!newUrl) newUrl = tiktokHelper.redirect(url, details.type, initiator);
if (!newUrl) newUrl = pixivHelper.redirect(url, details.type, initiator); if (!newUrl) newUrl = pixivHelper.redirect(url, details.type, initiator);

View File

@ -47,7 +47,6 @@ document.addEventListener("change", async () => {
window.onblur = () => { window.onblur = () => {
console.log('initting cookies')
redditHelper.initLibredditCookies(); redditHelper.initLibredditCookies();
redditHelper.initTedditCookies(); redditHelper.initTedditCookies();
} }

View File

@ -69,8 +69,34 @@
<option value="tor" data-localise="__MSG_tor__">Tor</option> <option value="tor" data-localise="__MSG_tor__">Tor</option>
</select> </select>
</div> </div>
<div class="some-block option-block">
<h4 data-localise="__MSG_enableCustomSettings__">Enable Custom Settings (will use cookies)</h4>
<input id="enable-custom-settings" type="checkbox">
</div>
<div id="proxiTok"> <div id="proxiTok">
<hr> <hr>
<div class="custom-settings">
<div class="some-block option-block">
<h2>General</h2>
</div>
<div class="some-block option-block">
<h4 data-localise="__MSG_theme__">Theme</h4>
<select class="theme">
<option value="default">Default</option>
<option value="card">Card</option>
</select>
</div>
<div class="some-block option-block">
<h2>Api</h2>
</div>
<div class="some-block option-block">
<h4 data-localise="__MSG_legacyMode__">Legacy mode</h4>
<select class="api-legacy">
<option value="on">On</option>
<option value="off">Off</option>
</select>
</div>
</div>
<div class="normal"> <div class="normal">
<div class="some-block option-block"> <div class="some-block option-block">
<h4 data-localise="__MSG_defaultInstances__">Default Instances</h4> <h4 data-localise="__MSG_defaultInstances__">Default Instances</h4>

View File

@ -1,40 +1,67 @@
import tiktokHelper from "../../../assets/javascripts/helpers/tiktok.js"; import tiktokHelper from "../../../assets/javascripts/helpers/tiktok.js";
import commonHelper from "../../../assets/javascripts/helpers/common.js"; import commonHelper from "../../../assets/javascripts/helpers/common.js";
let disableTiktokElement = document.getElementById("disable-tiktok"); let disable = document.getElementById("disable-tiktok");
disableTiktokElement.addEventListener("change", let protocol = document.getElementById("protocol")
event => tiktokHelper.setDisable(!event.target.checked)
);
let protocolElement = document.getElementById("protocol") let enableCustomSettings = document.getElementById("enable-custom-settings");
protocolElement.addEventListener("change", let customSettingsDiv = document.getElementsByClassName("custom-settings")[0];
event => {
let protocol = event.target.options[protocolElement.selectedIndex].value
tiktokHelper.setProtocol(protocol);
changeProtocolSettings(protocol);
}
);
function changeProtocolSettings(protocol) { let theme = document.getElementById('proxiTok').getElementsByClassName('theme')[0];
let api_legacy = document.getElementById('proxiTok').getElementsByClassName('api-legacy')[0];
document.addEventListener("change", async () => {
await browser.storage.local.set({
disableTiktok: !disable.checked,
tiktokProtocol: protocol.value,
enableTiktokCustomSettings: enableCustomSettings.checked,
proxiTokTheme: theme.value,
proxiTokApiLegacy: api_legacy.value,
});
init();
})
window.onblur = tiktokHelper.initProxiTokCookies;
function init() {
tiktokHelper.init().then(() => {
browser.storage.local.get(
[
"disableTiktok",
"tiktokProtocol",
"enableTiktokCustomSettings",
"proxiTokTheme",
"proxiTokApiLegacy",
],
r => {
disable.checked = !r.disableTiktok;
protocol.value = r.tiktokProtocol;
let normalDiv = document.getElementsByClassName("normal")[0]; let normalDiv = document.getElementsByClassName("normal")[0];
let torDiv = document.getElementsByClassName("tor")[0]; let torDiv = document.getElementsByClassName("tor")[0];
if (protocol == 'normal') { if (r.tiktokProtocol == 'normal') {
normalDiv.style.display = 'block'; normalDiv.style.display = 'block';
torDiv.style.display = 'none'; torDiv.style.display = 'none';
} }
else if (protocol == 'tor') { else if (r.tiktokProtocol == 'tor') {
normalDiv.style.display = 'none'; normalDiv.style.display = 'none';
torDiv.style.display = 'block'; torDiv.style.display = 'block';
} }
enableCustomSettings.checked = r.enableTiktokCustomSettings;
if (r.enableTiktokCustomSettings)
customSettingsDiv.style.display = 'block';
else
customSettingsDiv.style.display = 'none';
theme.value = r.proxiTokTheme;
api_legacy.value = r.proxiTokApiLegacy
} }
)
tiktokHelper.init().then(() => {
disableTiktokElement.checked = !tiktokHelper.getDisable();
let protocol = tiktokHelper.getProtocol();
protocolElement.value = protocol;
changeProtocolSettings(protocol);
browser.storage.local.get("proxiTokLatency").then(r => { browser.storage.local.get("proxiTokLatency").then(r => {
commonHelper.processDefaultCustomInstances( commonHelper.processDefaultCustomInstances(
'proxiTok', 'proxiTok',
@ -59,6 +86,8 @@ tiktokHelper.init().then(() => {
tiktokHelper.setProxiTokTorCustomRedirects tiktokHelper.setProxiTokTorCustomRedirects
) )
}) })
}
init();
let latencyElement = document.getElementById("latency"); let latencyElement = document.getElementById("latency");
let latencyLabel = document.getElementById("latency-label"); let latencyLabel = document.getElementById("latency-label");

View File

@ -39,117 +39,75 @@ let disableTiktokElement = document.getElementById("disable-tiktok");
let disablePixivElement = document.getElementById("disable-pixiv"); let disablePixivElement = document.getElementById("disable-pixiv");
let disableSpotifyElement = document.getElementById("disable-spotify"); let disableSpotifyElement = document.getElementById("disable-spotify");
async function wholeInit() {
await youtubeHelper.init();
await youtubeMusicHelper.init();
await twitterHelper.init();
await instagramHelper.init();
await mapsHelper.init();
await redditHelper.init();
await searchHelper.init();
await translateHelper.init();
await wikipediaHelper.init();
await imgurHelper.init();
await tiktokHelper.init();
await pixivHelper.init();
await spotifyHelper.init();
await sendTargetsHelper.init();
await peertubeHelper.init();
await lbryHelper.init();
await mediumHelper.init();
};
let copyRawElement = document.getElementById('copy_raw'); let copyRawElement = document.getElementById('copy_raw');
wholeInit().then(() => { browser.storage.local.get(
disableTwitterElement.checked = !twitterHelper.getDisable(); [
disableYoutubeElement.checked = !youtubeHelper.getDisable(); "disableTwitter",
disableYoutubeMusicElement.checked = !youtubeMusicHelper.getDisable(); "disableYoutube",
disableInstagramElement.checked = !instagramHelper.getDisable(); "disableYoutubeMusic",
disableMapsElement.checked = !mapsHelper.getDisable(); "disableInstagram",
disableRedditElement.checked = !redditHelper.getDisableReddit(); "disableMaps",
disableSearchElement.checked = !searchHelper.getDisable(); "disableReddit",
disableElement.checked = !translateHelper.getDisable(); "disableSearch",
disableWikipediaElement.checked = !wikipediaHelper.getDisable(); "translateDisable",
disableImgurElement.checked = !imgurHelper.getDisable(); "disableWikipedia",
disableTiktokElement.checked = !tiktokHelper.getDisable(); "disableImgur",
disablePixivElement.checked = !pixivHelper.getDisable(); "disableTiktok",
disableSpotifyElement.checked = !spotifyHelper.getDisable(); "disablePixiv",
disableMediumElement.checked = !mediumHelper.getDisable(); "disableSpotifyTargets",
disablePeertubeElement.checked = !peertubeHelper.getDisable(); "disableMedium",
disableLbryElement.checked = !lbryHelper.getDisable(); "disablePeertubeTargets",
"disableLbryTargets",
"disableSendTarget",
],
r => {
disableTwitterElement.checked = !r.disableTwitter;
disableYoutubeElement.checked = !r.disableYoutube;
disableYoutubeMusicElement.checked = !r.disableYoutubeMusic;
disableInstagramElement.checked = !r.disableInstagram;
disableMapsElement.checked = !r.disableMaps;
disableRedditElement.checked = !r.disableReddit;
disableSearchElement.checked = !r.disableSearch;
disableElement.checked = !r.translateDisable;
disableWikipediaElement.checked = !r.disableWikipedia;
disableImgurElement.checked = !r.disableImgur;
disableTiktokElement.checked = !r.disableTiktok;
disablePixivElement.checked = !r.disablePixiv;
disableSpotifyElement.checked = !r.disableSpotifyTargets;
disableMediumElement.checked = !r.disableMedium;
disablePeertubeElement.checked = !r.disablePeertubeTargets;
disableLbryElement.checked = !r.disableLbryTargets;
disableSendTargetsElement.checked = r.disableSendTarget;
}
)
document.addEventListener("change", () => {
browser.storage.local.set({
disableTwitter: !disableTwitterElement.checked,
disableYoutube: !disableYoutubeElement.checked,
disableYoutubeMusic: !disableYoutubeMusicElement.checked,
disableInstagram: !disableInstagramElement.checked,
disableMaps: !disableMapsElement.checked,
disableReddit: !disableRedditElement.checked,
disableSearch: !disableSearchElement.checked,
translateDisable: !disableElement.checked,
disableWikipedia: !disableWikipediaElement.checked,
disableImgur: !disableImgurElement.checked,
disableTiktok: !disableTiktokElement.checked,
disablePixiv: !disablePixivElement.checked,
disableSpotifyTargets: !disableSpotifyElement.checked,
disableMedium: !disableMediumElement.checked,
disablePeertubeTargets: !disablePeertubeElement.checked,
disableLbryTargets: !disableLbryElement.checked,
disableSendTarget: !disableSendTargetsElement.checked,
});
})
let changeInstanceElement = document.getElementById("change-instance") let changeInstanceElement = document.getElementById("change-instance")
changeInstanceElement.addEventListener("click", switchInstance); changeInstanceElement.addEventListener("click", switchInstance);
copyRawElement.addEventListener("click", copyRaw); copyRawElement.addEventListener("click", copyRaw);
})
disableTwitterElement.addEventListener("change",
event => twitterHelper.setDisable(!event.target.checked)
);
disableYoutubeElement.addEventListener("change",
event => youtubeHelper.setDisable(!event.target.checked)
);
disableYoutubeMusicElement.addEventListener("change",
event => youtubeMusicHelper.setDisable(!event.target.checked)
);
disableInstagramElement.addEventListener("change",
event => instagramHelper.setDisable(!event.target.checked)
);
disableMapsElement.addEventListener("change",
event => mapsHelper.setDisable(!event.target.checked)
);
disableRedditElement.addEventListener("change",
event => redditHelper.setDisableReddit(!event.target.checked)
);
disableSearchElement.addEventListener("change",
event => searchHelper.setDisable(!event.target.checked)
);
disableElement.addEventListener("change",
event => translateHelper.setDisable(!event.target.checked)
);
disableWikipediaElement.addEventListener("change",
event => wikipediaHelper.setDisable(!event.target.checked)
);
disableImgurElement.addEventListener("change",
event => imgurHelper.setDisable(!event.target.checked)
);
disableTiktokElement.addEventListener("change",
event => tiktokHelper.setDisable(!event.target.checked)
);
disablePixivElement.addEventListener("change",
event => pixivHelper.setDisable(!event.target.checked)
);
disableSpotifyElement.addEventListener("change",
event => spotifyHelper.setDisable(!event.target.checked)
);
disableMediumElement.addEventListener("change",
event => mediumHelper.setDisable(!event.target.checked)
);
disablePeertubeElement.addEventListener("change",
event => peertubeHelper.setDisable(!event.target.checked)
);
disableLbryElement.addEventListener("change",
event => lbryHelper.setDisable(!event.target.checked)
);
disableSendTargetsElement.addEventListener("change",
event => sendTargetsHelper.setDisable(!event.target.checked)
);
document.getElementById("more-options").addEventListener("click", document.getElementById("more-options").addEventListener("click",
() => browser.runtime.openOptionsPage() () => browser.runtime.openOptionsPage()