mirror of
https://codeberg.org/LibRedirect/libredirect.git
synced 2025-01-31 19:44:54 +01:00
Unify Settings on Import #285
This commit is contained in:
parent
5c06fc561d
commit
4d0c773cf6
@ -119,7 +119,7 @@ function initLibredditCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setLibredditCookies() {
|
||||
function pasteLibredditCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableReddit || redditFrontend != 'libreddit' || redditProtocol === undefined) { resolve(); return; }
|
||||
@ -172,7 +172,7 @@ function initTedditCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setTedditCookies() {
|
||||
function pasteTedditCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableReddit || redditFrontend != 'teddit' || redditProtocol === undefined) { resolve(); return; }
|
||||
@ -361,9 +361,9 @@ function initDefaults() {
|
||||
export default {
|
||||
setRedirects,
|
||||
initLibredditCookies,
|
||||
setLibredditCookies,
|
||||
pasteLibredditCookies,
|
||||
initTedditCookies,
|
||||
setTedditCookies,
|
||||
pasteTedditCookies,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
|
@ -175,7 +175,7 @@ function initSearxCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setSearxCookies() {
|
||||
function pasteSearxCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableSearch || searchFrontend != 'searx') { resolve(); return; }
|
||||
@ -245,7 +245,7 @@ function initSearxngCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setSearxngCookies() {
|
||||
function pasteSearxngCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableSearch || searchFrontend != 'searxng', searchProtocol === undefined) { resolve(); return; }
|
||||
@ -453,9 +453,9 @@ function initDefaults() {
|
||||
export default {
|
||||
setRedirects,
|
||||
initSearxCookies,
|
||||
setSearxCookies,
|
||||
pasteSearxCookies,
|
||||
initSearxngCookies,
|
||||
setSearxngCookies,
|
||||
pasteSearxngCookies,
|
||||
redirect,
|
||||
initDefaults,
|
||||
switchInstance,
|
||||
|
@ -49,7 +49,7 @@ function initProxiTokCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setProxiTokCookies() {
|
||||
function pasteProxiTokCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableTiktok || tiktokProtocol === undefined) { resolve(); return; }
|
||||
@ -166,7 +166,7 @@ export default {
|
||||
reverse,
|
||||
|
||||
initProxiTokCookies,
|
||||
setProxiTokCookies,
|
||||
pasteProxiTokCookies,
|
||||
|
||||
initDefaults
|
||||
};
|
||||
|
@ -2,9 +2,11 @@ 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'),
|
||||
['lingva_chakra-ui-color-mode']: localStorage.getItem('chakra-ui-color-mode'),
|
||||
lingva_isauto: localStorage.getItem('isauto'),
|
||||
lingva_source: localStorage.getItem('source'),
|
||||
lingva_target: localStorage.getItem('target'),
|
||||
}
|
||||
)
|
||||
|
||||
console.log(localStorage.getItem('target'));
|
@ -10,10 +10,8 @@ browser.storage.local.get(
|
||||
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();
|
||||
}
|
||||
)
|
||||
|
@ -94,7 +94,7 @@ function setRedirects(val) {
|
||||
})
|
||||
}
|
||||
|
||||
function initLingvaLocalStorage(test, url, tabId) {
|
||||
function copyPasteLingvaLocalStorage(test, url, tabId) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (translateDisable || translateFrontend != 'lingva') { resolve(); return; }
|
||||
@ -129,7 +129,21 @@ function initLingvaLocalStorage(test, url, tabId) {
|
||||
)
|
||||
}
|
||||
|
||||
function initSimplyTranslateCookies(test, from) {
|
||||
function pasteLingvaLocalStorage() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (translateDisable || translateFrontend != 'lingva') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (translateProtocol == 'normal') checkedInstances = [...lingvaNormalRedirectsChecks, ...lingvaNormalCustomRedirects];
|
||||
if (translateProtocol == 'tor') checkedInstances = [...lingvaTorRedirectsChecks, ...lingvaTorCustomRedirects];
|
||||
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();
|
||||
})
|
||||
}
|
||||
|
||||
function copyPasteSimplyTranslateCookies(test, from) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
const protocolHost = utils.protocolHost(from);
|
||||
@ -153,7 +167,7 @@ function initSimplyTranslateCookies(test, from) {
|
||||
)
|
||||
}
|
||||
|
||||
function setSimplyTranslateCookies() {
|
||||
function pasteSimplyTranslateCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (translateDisable || translateFrontend != 'simplyTranslate') { resolve(); return; }
|
||||
@ -281,9 +295,10 @@ function initDefaults() {
|
||||
}
|
||||
|
||||
export default {
|
||||
initSimplyTranslateCookies,
|
||||
setSimplyTranslateCookies,
|
||||
initLingvaLocalStorage,
|
||||
copyPasteSimplyTranslateCookies,
|
||||
pasteSimplyTranslateCookies,
|
||||
copyPasteLingvaLocalStorage,
|
||||
pasteLingvaLocalStorage,
|
||||
setRedirects,
|
||||
redirect,
|
||||
initDefaults,
|
||||
|
@ -170,7 +170,7 @@ function initNitterCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setNitterCookies() {
|
||||
function pasteNitterCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableTwitter || twitterProtocol === undefined) { resolve(); return; }
|
||||
@ -231,6 +231,6 @@ export default {
|
||||
reverse,
|
||||
removeXFrameOptions,
|
||||
initNitterCookies,
|
||||
setNitterCookies,
|
||||
pasteNitterCookies,
|
||||
initDefaults,
|
||||
};
|
||||
|
@ -382,9 +382,9 @@ function unify(test) {
|
||||
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);
|
||||
let result = await youtubeHelper.copyPasteInvidiousCookies(test, url);
|
||||
if (!result) result = await youtubeHelper.copyPastePipedLocalStorage(test, url, currTab.id);
|
||||
if (!result) result = await youtubeHelper.copyPastePipedMaterialLocalStorage(test, url, currTab.id);
|
||||
|
||||
if (!result) result = await twitterHelper.initNitterCookies(test, url);
|
||||
|
||||
@ -398,8 +398,8 @@ function unify(test) {
|
||||
|
||||
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) result = await translateHelper.copyPasteSimplyTranslateCookies(test, url);
|
||||
if (!result) result = await translateHelper.copyPasteLingvaLocalStorage(test, url);
|
||||
|
||||
if (result) {
|
||||
resolve(true);
|
||||
|
@ -97,7 +97,7 @@ function initWikilessCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setWikilessCookies() {
|
||||
function pasteWikilessCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableWikipedia || wikipediaProtocol === undefined) { resolve(); return; }
|
||||
@ -207,7 +207,7 @@ export default {
|
||||
setRedirects,
|
||||
|
||||
initWikilessCookies,
|
||||
setWikilessCookies,
|
||||
pasteWikilessCookies,
|
||||
|
||||
redirect,
|
||||
initDefaults,
|
||||
|
@ -298,7 +298,7 @@ function initDefaults() {
|
||||
})
|
||||
}
|
||||
|
||||
function initInvidiousCookies(test, from) {
|
||||
function copyPasteInvidiousCookies(test, from) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; }
|
||||
@ -321,7 +321,7 @@ function initInvidiousCookies(test, from) {
|
||||
})
|
||||
}
|
||||
|
||||
function setInvidiousCookies() {
|
||||
function pasteInvidiousCookies() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'invidious') { resolve(); return; }
|
||||
@ -333,7 +333,7 @@ function setInvidiousCookies() {
|
||||
})
|
||||
}
|
||||
|
||||
function initPipedLocalStorage(test, url, tabId) {
|
||||
function copyPastePipedLocalStorage(test, url, tabId) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'piped') { resolve(); return; }
|
||||
@ -361,8 +361,22 @@ function initPipedLocalStorage(test, url, tabId) {
|
||||
resolve(true);
|
||||
})
|
||||
}
|
||||
function pastePipedLocalStorage() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'piped') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (youtubeProtocol == 'normal') checkedInstances = [...pipedNormalCustomRedirects, ...pipedNormalRedirectsChecks]
|
||||
else if (youtubeProtocol == 'tor') checkedInstances = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects]
|
||||
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();
|
||||
})
|
||||
}
|
||||
|
||||
function initPipedMaterialLocalStorage(test, url, tabId,) {
|
||||
function copyPastePipedMaterialLocalStorage(test, url, tabId,) {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'pipedMaterial') { resolve(); return; }
|
||||
@ -392,6 +406,22 @@ function initPipedMaterialLocalStorage(test, url, tabId,) {
|
||||
})
|
||||
}
|
||||
|
||||
function pastePipedMaterialLocalStorage() {
|
||||
return new Promise(async resolve => {
|
||||
await init();
|
||||
if (disableYoutube || youtubeFrontend != 'pipedMaterial') { resolve(); return; }
|
||||
let checkedInstances;
|
||||
if (youtubeProtocol == 'normal') checkedInstances = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects]
|
||||
else if (youtubeProtocol == 'tor') checkedInstances = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects]
|
||||
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();
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function removeXFrameOptions(e) {
|
||||
if (e.type != 'sub_frame') return;
|
||||
const url = new URL(e.url);
|
||||
@ -409,10 +439,12 @@ function removeXFrameOptions(e) {
|
||||
|
||||
export default {
|
||||
setRedirects,
|
||||
initPipedLocalStorage,
|
||||
initPipedMaterialLocalStorage,
|
||||
initInvidiousCookies,
|
||||
setInvidiousCookies,
|
||||
copyPastePipedLocalStorage,
|
||||
pastePipedLocalStorage,
|
||||
copyPastePipedMaterialLocalStorage,
|
||||
pastePipedMaterialLocalStorage,
|
||||
copyPasteInvidiousCookies,
|
||||
pasteInvidiousCookies,
|
||||
redirect,
|
||||
reverse,
|
||||
switchInstance,
|
||||
|
@ -50,16 +50,24 @@ browser.runtime.onInstalled.addListener(
|
||||
}
|
||||
)
|
||||
|
||||
youtubeHelper.setInvidiousCookies();
|
||||
translateHelper.setSimplyTranslateCookies();
|
||||
twitterHelper.setNitterCookies();
|
||||
wikipediaHelper.setWikilessCookies();
|
||||
searchHelper.setSearxCookies();
|
||||
searchHelper.setSearxngCookies();
|
||||
redditHelper.setLibredditCookies();
|
||||
redditHelper.setTedditCookies();
|
||||
tiktokHelper.setProxiTokCookies();
|
||||
youtubeHelper.pasteInvidiousCookies();
|
||||
youtubeHelper.pastePipedLocalStorage();
|
||||
youtubeHelper.pastePipedMaterialLocalStorage();
|
||||
|
||||
translateHelper.pasteSimplyTranslateCookies();
|
||||
translateHelper.pasteLingvaLocalStorage();
|
||||
|
||||
twitterHelper.pasteNitterCookies();
|
||||
|
||||
wikipediaHelper.pasteWikilessCookies();
|
||||
|
||||
searchHelper.pasteSearxCookies();
|
||||
searchHelper.pasteSearxngCookies();
|
||||
|
||||
redditHelper.pasteLibredditCookies();
|
||||
redditHelper.pasteTedditCookies();
|
||||
|
||||
tiktokHelper.pasteProxiTokCookies();
|
||||
|
||||
|
||||
let BYPASSTABs = [];
|
||||
|
@ -8,14 +8,14 @@ import tiktokHelper from "../../assets/javascripts/tiktok.js";
|
||||
|
||||
window.browser = window.browser || window.chrome;
|
||||
|
||||
await youtubeHelper.setInvidiousCookies();
|
||||
await translateHelper.setSimplyTranslateCookies();
|
||||
await twitterHelper.setNitterCookies();
|
||||
await wikipediaHelper.setWikilessCookies();
|
||||
await searchHelper.setSearxCookies();
|
||||
await searchHelper.setSearxngCookies();
|
||||
await redditHelper.setLibredditCookies();
|
||||
await redditHelper.setTedditCookies();
|
||||
await tiktokHelper.setProxiTokCookies();
|
||||
await youtubeHelper.pasteInvidiousCookies();
|
||||
await translateHelper.pasteSimplyTranslateCookies();
|
||||
await twitterHelper.pasteNitterCookies();
|
||||
await wikipediaHelper.pasteWikilessCookies();
|
||||
await searchHelper.pasteSearxCookies();
|
||||
await searchHelper.pasteSearxngCookies();
|
||||
await redditHelper.pasteLibredditCookies();
|
||||
await redditHelper.pasteTedditCookies();
|
||||
await tiktokHelper.pasteProxiTokCookies();
|
||||
|
||||
window.close()
|
@ -95,7 +95,8 @@
|
||||
<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"></path>
|
||||
</svg>
|
||||
<x data-localise="__MSG_updateInstances__">Update Instances</x></a>
|
||||
<x data-localise="__MSG_updateInstances__">Update Instances</x></a> </div>
|
||||
<div class="buttons buttons-inline">
|
||||
<label class="button button-inline" id="import_settings_text" 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"></path>
|
||||
|
@ -54,6 +54,7 @@ let importSettingsElement = document.getElementById("import-settings");
|
||||
let importSettingsElementText = document.getElementById('import_settings_text');
|
||||
importSettingsElement.addEventListener("change",
|
||||
() => {
|
||||
importSettingsElementText.innerHTML = '...';
|
||||
let file = importSettingsElement.files[0];
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
@ -67,6 +68,24 @@ importSettingsElement.addEventListener("change",
|
||||
) {
|
||||
await browser.storage.local.clear();
|
||||
await browser.storage.local.set({ ...data })
|
||||
await youtubeHelper.pasteInvidiousCookies();
|
||||
await youtubeHelper.pastePipedLocalStorage();
|
||||
await youtubeHelper.pastePipedMaterialLocalStorage();
|
||||
|
||||
await translateHelper.pasteSimplyTranslateCookies();
|
||||
await translateHelper.pasteLingvaLocalStorage();
|
||||
|
||||
await twitterHelper.pasteNitterCookies();
|
||||
|
||||
await wikipediaHelper.pasteWikilessCookies();
|
||||
|
||||
await searchHelper.pasteSearxCookies();
|
||||
await searchHelper.pasteSearxngCookies();
|
||||
|
||||
await redditHelper.pasteLibredditCookies();
|
||||
await redditHelper.pasteTedditCookies();
|
||||
|
||||
await tiktokHelper.pasteProxiTokCookies();
|
||||
location.reload();
|
||||
} else
|
||||
importError()
|
||||
@ -80,8 +99,10 @@ function importError() {
|
||||
setTimeout(() => importSettingsElementText.innerHTML = oldHTML, 1000);
|
||||
}
|
||||
|
||||
document.getElementById("reset-settings").addEventListener("click",
|
||||
const resetSettings = document.getElementById("reset-settings");
|
||||
resetSettings.addEventListener("click",
|
||||
async () => {
|
||||
resetSettings.innerHTML = '...'
|
||||
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) })
|
||||
|
@ -40,6 +40,8 @@ section#general_page.option-block
|
||||
|
||||
|
|
||||
|
||||
.buttons.buttons-inline
|
||||
|
||||
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")
|
||||
|
Loading…
x
Reference in New Issue
Block a user