Changed changeInstance() structure
This commit is contained in:
parent
01020800a2
commit
a15ba98b56
|
@ -141,43 +141,45 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
return new Promise((resolve) => {
|
||||
fetch('/instances/data.json').then(response => response.text()).then(data => {
|
||||
let dataJson = JSON.parse(data);
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableImgur",
|
||||
"imgurRedirects",
|
||||
return new Promise(resolve => {
|
||||
fetch('/instances/data.json')
|
||||
.then(response => response.text())
|
||||
.then(text => {
|
||||
let data = JSON.parse(text);
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"disableImgur",
|
||||
"imgurRedirects",
|
||||
|
||||
"rimgoNormalRedirectsChecks",
|
||||
"rimgoNormalCustomRedirects",
|
||||
"rimgoTorRedirectsChecks",
|
||||
"rimgoTorCustomRedirects",
|
||||
"rimgoNormalRedirectsChecks",
|
||||
"rimgoNormalCustomRedirects",
|
||||
"rimgoTorRedirectsChecks",
|
||||
"rimgoTorCustomRedirects",
|
||||
|
||||
"imgurProtocol",
|
||||
],
|
||||
(result) => {
|
||||
disable = result.disableImgur ?? false;
|
||||
"imgurProtocol",
|
||||
],
|
||||
r => { // r = result
|
||||
disable = r.disableImgur ?? false;
|
||||
|
||||
protocol = result.imgurProtocol ?? "normal";
|
||||
protocol = r.imgurProtocol ?? "normal";
|
||||
|
||||
redirects.rimgo = dataJson.rimgo;
|
||||
if (result.imgurRedirects) redirects = result.imgurRedirects;
|
||||
redirects.rimgo = data.rimgo;
|
||||
if (r.imgurRedirects) redirects = r.imgurRedirects;
|
||||
|
||||
rimgoNormalRedirectsChecks = result.rimgoNormalRedirectsChecks ?? [...redirects.rimgo.normal];
|
||||
rimgoNormalCustomRedirects = result.rimgoNormalCustomRedirects ?? [];
|
||||
rimgoNormalRedirectsChecks = r.rimgoNormalRedirectsChecks ?? [...redirects.rimgo.normal];
|
||||
rimgoNormalCustomRedirects = r.rimgoNormalCustomRedirects ?? [];
|
||||
|
||||
rimgoTorRedirectsChecks = result.rimgoTorRedirectsChecks ?? [...redirects.rimgo.tor];
|
||||
rimgoTorCustomRedirects = result.rimgoTorCustomRedirects ?? [];
|
||||
rimgoTorRedirectsChecks = r.rimgoTorRedirectsChecks ?? [...redirects.rimgo.tor];
|
||||
rimgoTorCustomRedirects = r.rimgoTorCustomRedirects ?? [];
|
||||
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
});
|
||||
resolve();
|
||||
}
|
||||
)
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -158,7 +158,7 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -152,7 +152,7 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
|
|
@ -222,7 +222,7 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
|
|
@ -265,8 +265,7 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
|
|
@ -179,7 +179,7 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
|
|
@ -157,7 +157,7 @@ function changeInstance(url) {
|
|||
if (instancesList.length === 0) return null;
|
||||
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
async function init() {
|
||||
|
@ -173,20 +173,19 @@ async function init() {
|
|||
"wikilessNormalCustomRedirects",
|
||||
"wikilessTorCustomRedirects",
|
||||
"wikipediaProtocol"
|
||||
], r => { // r = result
|
||||
disable = r.disableWikipedia ?? false;
|
||||
|
||||
], (result) => {
|
||||
disable = result.disableWikipedia ?? false;
|
||||
|
||||
protocol = result.wikipediaProtocol ?? "normal";
|
||||
protocol = r.wikipediaProtocol ?? "normal";
|
||||
|
||||
redirects.wikiless = dataJson.wikiless;
|
||||
if (result.wikipediaRedirects) redirects = result.wikipediaRedirects;
|
||||
if (r.wikipediaRedirects) redirects = r.wikipediaRedirects;
|
||||
|
||||
wikilessNormalRedirectsChecks = result.wikilessNormalRedirectsChecks ?? [...redirects.wikiless.normal];
|
||||
wikilessNormalCustomRedirects = result.wikilessNormalCustomRedirects ?? [];
|
||||
wikilessNormalRedirectsChecks = r.wikilessNormalRedirectsChecks ?? [...redirects.wikiless.normal];
|
||||
wikilessNormalCustomRedirects = r.wikilessNormalCustomRedirects ?? [];
|
||||
|
||||
wikilessTorRedirectsChecks = result.wikilessTorRedirectsChecks ?? [...redirects.wikiless.tor];
|
||||
wikilessTorCustomRedirects = result.wikilessTorCustomRedirects ?? [];
|
||||
wikilessTorRedirectsChecks = r.wikilessTorRedirectsChecks ?? [...redirects.wikiless.tor];
|
||||
wikilessTorCustomRedirects = r.wikilessTorCustomRedirects ?? [];
|
||||
|
||||
resolve();
|
||||
}
|
||||
|
|
|
@ -32,6 +32,13 @@ let redirects = {
|
|||
"tor": [
|
||||
"http://piped2bbch4xslbl2ckr6k62q56kon56ffowxaqzy42ai22a4sash3ad.onion"
|
||||
]
|
||||
},
|
||||
"pipedMaterial": {
|
||||
"normal": [
|
||||
"https://piped-material.১.net/",
|
||||
"https://piped-material.ftp.sh/",
|
||||
],
|
||||
"tor": []
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -418,7 +425,7 @@ function changeInstance(url) {
|
|||
|
||||
if (instancesList.length === 0) return null;
|
||||
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||
return randomInstance;
|
||||
return `${randomInstance}${url.pathname}${url.search}`;
|
||||
}
|
||||
|
||||
function isPipedorInvidious(url, type) {
|
||||
|
|
|
@ -98,6 +98,7 @@
|
|||
<select id="youtube-frontend">
|
||||
<option value="invidious">Invidious</option>
|
||||
<option value="piped">Piped</option>
|
||||
<option value="pipedMaterial">Piped-Material</option>
|
||||
<option value="freetube">FreeTube</option>
|
||||
<option value="yatte">Yattee</option>
|
||||
</select>
|
||||
|
|
|
@ -114,33 +114,29 @@ document.getElementById("change-instance").addEventListener("click",
|
|||
() => browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
|
||||
let currTab = tabs[0];
|
||||
if (currTab) {
|
||||
changeInstance(currTab.url)
|
||||
let url = currTab.url;
|
||||
let tabUrl = new URL(url);
|
||||
let newUrl;
|
||||
|
||||
newUrl = youtubeHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = twitterHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = instagramHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = redditHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = searchHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = translateHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = mediumHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = imgurHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = wikipediaHelper.changeInstance(tabUrl)
|
||||
|
||||
if (newUrl) browser.tabs.update({ url: newUrl });
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
function changeInstance(url) {
|
||||
var tabUrl = new URL(url);
|
||||
var protocolHost = `${tabUrl.protocol}//${tabUrl.host}`;
|
||||
var newUrl;
|
||||
|
||||
newUrl = youtubeHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = twitterHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = instagramHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = redditHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = searchHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = translateHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = mediumHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = imgurHelper.changeInstance(tabUrl);
|
||||
|
||||
if (!newUrl) newUrl = wikipediaHelper.changeInstance(tabUrl)
|
||||
|
||||
if (newUrl) browser.tabs.update({ url: tabUrl.href.replace(protocolHost, newUrl) });
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue