Cleaned code. Fixed thing in CopyRaw #268
This commit is contained in:
parent
7c410432d5
commit
51b0df71b9
@ -11,7 +11,6 @@ let redirects = {
|
||||
"i2p": []
|
||||
}
|
||||
}
|
||||
const getRedirects = () => redirects;
|
||||
function setRedirects(val) {
|
||||
redirects.rimgo = val;
|
||||
browser.storage.local.set({ imgurRedirects: redirects })
|
||||
@ -98,28 +97,30 @@ function redirect(url, type, initiator) {
|
||||
}
|
||||
|
||||
async function reverse(url) {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"imgurRedirects",
|
||||
"rimgoNormalCustomRedirects",
|
||||
"rimgoTorCustomRedirects",
|
||||
"rimgoI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.imgurRedirects.rimgo.normal,
|
||||
...r.imgurRedirects.rimgo.tor,
|
||||
...r.imgurRedirects.rimgo.i2p,
|
||||
...r.rimgoNormalCustomRedirects,
|
||||
...r.rimgoTorCustomRedirects,
|
||||
...r.rimgoI2pCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) return;
|
||||
return `https://imgur.com${url.pathname}${url.search}`;
|
||||
}
|
||||
)
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"imgurRedirects",
|
||||
"rimgoNormalCustomRedirects",
|
||||
"rimgoTorCustomRedirects",
|
||||
"rimgoI2pCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.imgurRedirects.rimgo.normal,
|
||||
...r.imgurRedirects.rimgo.tor,
|
||||
...r.imgurRedirects.rimgo.i2p,
|
||||
...r.rimgoNormalCustomRedirects,
|
||||
...r.rimgoTorCustomRedirects,
|
||||
...r.rimgoI2pCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
resolve(`https://imgur.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
@ -197,7 +198,6 @@ async function initDefaults() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
|
@ -76,32 +76,36 @@ function redirect(url, type, initiator) {
|
||||
})
|
||||
}
|
||||
function reverse(url) {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"instagramRedirects",
|
||||
"bibliogramNormalCustomRedirects",
|
||||
"bibliogramTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.instagramRedirects.bibliogram.normal,
|
||||
...r.instagramRedirects.bibliogram.tor,
|
||||
...r.bibliogramNormalCustomRedirects,
|
||||
...r.bibliogramTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) return;
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"instagramRedirects",
|
||||
"bibliogramNormalCustomRedirects",
|
||||
"bibliogramTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.instagramRedirects.bibliogram.normal,
|
||||
...r.instagramRedirects.bibliogram.tor,
|
||||
...r.bibliogramNormalCustomRedirects,
|
||||
...r.bibliogramTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
|
||||
if (url.pathname.startsWith('/p'))
|
||||
return `https://instagram.com${url.pathname.replace('/p', '')}${url.search}`;
|
||||
if (url.pathname.startsWith('/p')) {
|
||||
resolve(`https://instagram.com${url.pathname.replace('/p', '')}${url.search}`); return;
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith('/u'))
|
||||
return `https://instagram.com${url.pathname.replace('/u', '')}${url.search}`;
|
||||
if (url.pathname.startsWith('/u')) {
|
||||
resolve(`https://instagram.com${url.pathname.replace('/u', '')}${url.search}`); return;
|
||||
}
|
||||
|
||||
return `https://instagram.com${url.pathname}${url.search}`;
|
||||
}
|
||||
)
|
||||
resolve(`https://instagram.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance(url) {
|
||||
|
@ -34,7 +34,6 @@ let redirects = {
|
||||
"tor": []
|
||||
}
|
||||
};
|
||||
const getRedirects = () => redirects;
|
||||
function setRedirects(val) {
|
||||
redirects.scribe = val;
|
||||
browser.storage.local.set({ mediumRedirects: redirects })
|
||||
@ -160,7 +159,6 @@ function initDefaults() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
|
@ -16,8 +16,6 @@ let redirects = {
|
||||
"tor": []
|
||||
}
|
||||
}
|
||||
|
||||
const getRedirects = () => redirects;
|
||||
function setRedirects(val) {
|
||||
redirects.simpleertube = val;
|
||||
browser.storage.local.set({ peertubeTargetsRedirects: redirects })
|
||||
@ -165,7 +163,6 @@ async function init() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setRedirects,
|
||||
|
||||
switchInstance,
|
||||
|
@ -16,8 +16,6 @@ let redirects = {
|
||||
"tor": []
|
||||
},
|
||||
};
|
||||
const getRedirects = () => redirects;
|
||||
|
||||
function setLibredditRedirects(val) {
|
||||
redirects.libreddit = val;
|
||||
browser.storage.local.set({ redditRedirects: redirects })
|
||||
@ -443,7 +441,6 @@ function initDefaults() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setTedditRedirects,
|
||||
setLibredditRedirects,
|
||||
|
||||
|
@ -14,8 +14,6 @@ let redirects = {
|
||||
"tor": []
|
||||
}
|
||||
}
|
||||
|
||||
const getRedirects = () => redirects;
|
||||
function setRedirects(val) {
|
||||
redirects.send = val;
|
||||
browser.storage.local.set({ sendTargetsRedirects: redirects })
|
||||
@ -158,7 +156,6 @@ async function init() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
|
@ -12,8 +12,6 @@ let redirects = {
|
||||
"tor": []
|
||||
}
|
||||
}
|
||||
|
||||
const getRedirects = () => redirects;
|
||||
function setRedirects(val) {
|
||||
redirects.proxiTok = val;
|
||||
browser.storage.local.set({ tiktokRedirects: redirects })
|
||||
@ -139,26 +137,28 @@ function redirect(url, type, initiator) {
|
||||
}
|
||||
|
||||
async function reverse(url) {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"tiktokRedirects",
|
||||
"proxiTokNormalCustomRedirects",
|
||||
"proxiTokTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.tiktokRedirects.proxiTok.normal,
|
||||
...r.tiktokRedirects.proxiTok.tor,
|
||||
...r.proxiTokNormalCustomRedirects,
|
||||
...r.proxiTokTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) return;
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
"tiktokRedirects",
|
||||
"proxiTokNormalCustomRedirects",
|
||||
"proxiTokTorCustomRedirects",
|
||||
],
|
||||
r => {
|
||||
let protocolHost = utils.protocolHost(url);
|
||||
if (
|
||||
![
|
||||
...r.tiktokRedirects.proxiTok.normal,
|
||||
...r.tiktokRedirects.proxiTok.tor,
|
||||
...r.proxiTokNormalCustomRedirects,
|
||||
...r.proxiTokTorCustomRedirects
|
||||
].includes(protocolHost)
|
||||
) { resolve(); return; }
|
||||
|
||||
return `https://tiktok.com${url.pathname}${url.search}`;
|
||||
}
|
||||
)
|
||||
resolve(`https://tiktok.com${url.pathname}${url.search}`);
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
async function initDefaults() {
|
||||
@ -184,7 +184,6 @@ async function initDefaults() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setRedirects,
|
||||
|
||||
redirect,
|
||||
|
@ -10,7 +10,7 @@ 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 tiktokHelper from "./tiktok.js";
|
||||
import imgurHelper from "./imgur.js";
|
||||
import localise from '../localise.js'
|
||||
|
||||
@ -30,7 +30,7 @@ async function initCloudflareList() {
|
||||
|
||||
async function wholeInit() {
|
||||
await sendTargetsHelper.init();
|
||||
await tikTokHelper.init();
|
||||
await tiktokHelper.init();
|
||||
await initCloudflareList();
|
||||
}
|
||||
|
||||
@ -64,8 +64,7 @@ async function updateInstances() {
|
||||
redditHelper.setTedditRedirects(instances.teddit);
|
||||
redditHelper.setLibredditRedirects(instances.libreddit);
|
||||
|
||||
translateHelper.setSimplyTranslateRedirects(instances.simplyTranslate);
|
||||
translateHelper.setLingvaRedirects(instances.lingva)
|
||||
translateHelper.setRedirects({ "simplyTranslate": instances.simplyTranslate, "lingva": instances.lingva });
|
||||
|
||||
searchHelper.setSearxRedirects(instances.searx);
|
||||
searchHelper.setSearxngRedirects(instances.searxng);
|
||||
@ -77,7 +76,7 @@ async function updateInstances() {
|
||||
|
||||
sendTargetsHelper.setRedirects(instances.send);
|
||||
|
||||
tikTokHelper.setRedirects(instances.proxiTok);
|
||||
tiktokHelper.setRedirects(instances.proxiTok);
|
||||
|
||||
console.info("Successfully updated Instances");
|
||||
return true;
|
||||
@ -336,69 +335,83 @@ function getCookiesFromStorage(frontend, to, name) {
|
||||
)
|
||||
}
|
||||
|
||||
function copyRaw() {
|
||||
browser.tabs.query(
|
||||
{ active: true, currentWindow: true }, tabs => {
|
||||
let currTab = tabs[0];
|
||||
if (currTab) {
|
||||
let url = new URL(currTab.url);
|
||||
let newUrl;
|
||||
newUrl = youtubeHelper.reverse(url);
|
||||
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;
|
||||
newUrl = await youtubeHelper.reverse(url);
|
||||
|
||||
if (!newUrl) newUrl = twitterHelper.reverse(url);
|
||||
if (!newUrl) newUrl = instagramHelper.reverse(url);
|
||||
if (!newUrl) newUrl = tiktokHelper.reverse(url);
|
||||
if (!newUrl) newUrl = imgurHelper.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) {
|
||||
navigator.clipboard.writeText(newUrl);
|
||||
const textElement = copyRawElement.getElementsByTagName('h4')[0]
|
||||
const oldHtml = textElement.innerHTML;
|
||||
textElement.innerHTML = 'Copied';
|
||||
setTimeout(() => textElement.innerHTML = oldHtml, 1000);
|
||||
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(unifyElement) {
|
||||
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; }
|
||||
|
||||
function unify() {
|
||||
browser.tabs.query(
|
||||
{ active: true, currentWindow: true },
|
||||
async tabs => {
|
||||
let currTab = tabs[0]
|
||||
if (currTab) {
|
||||
let url = new URL(currTab.url);
|
||||
let result = await youtubeHelper.initInvidiousCookies(url);
|
||||
if (!result) result = await youtubeHelper.initPipedLocalStorage(url, currTab.id);
|
||||
if (!result) result = await youtubeHelper.initPipedMaterialLocalStorage(url, currTab.id);
|
||||
|
||||
let result = await youtubeHelper.initInvidiousCookies(url);
|
||||
if (!result) result = await youtubeHelper.initPipedLocalStorage(url, currTab.id);
|
||||
if (!result) result = await youtubeHelper.initPipedMaterialLocalStorage(url, currTab.id);
|
||||
if (!result) result = await twitterHelper.initNitterCookies(url);
|
||||
|
||||
if (!result) result = await twitterHelper.initNitterCookies(url);
|
||||
if (!result) result = await redditHelper.initLibredditCookies(url);
|
||||
if (!result) result = await redditHelper.initTedditCookies(url);
|
||||
|
||||
if (!result) result = await redditHelper.initLibredditCookies(url);
|
||||
if (!result) result = await redditHelper.initTedditCookies(url);
|
||||
if (!result) result = await searchHelper.initSearxCookies(url);
|
||||
if (!result) result = await searchHelper.initSearxngCookies(url);
|
||||
|
||||
if (!result) result = await searchHelper.initSearxCookies(url);
|
||||
if (!result) result = await searchHelper.initSearxngCookies(url);
|
||||
if (!result) result = await tiktokHelper.initProxiTokCookies(url);
|
||||
|
||||
if (!result) result = await tiktokHelper.initProxiTokCookies(url);
|
||||
if (!result) result = await wikipediaHelper.initWikilessCookies(url);
|
||||
|
||||
if (!result) result = await wikipediaHelper.initWikilessCookies(url);
|
||||
if (!result) result = await translateHelper.initSimplyTranslateCookies(url);
|
||||
if (!result) result = await translateHelper.initLingvaLocalStorage(url);
|
||||
|
||||
if (!result) result = await translateHelper.initSimplyTranslateCookies(url);
|
||||
if (!result) result = await translateHelper.initLingvaLocalStorage(url);
|
||||
|
||||
if (result) {
|
||||
const textElement = unifyElement.getElementsByTagName('h4')[0]
|
||||
const oldHtml = textElement.innerHTML;
|
||||
textElement.innerHTML = 'Unified';
|
||||
setTimeout(() => textElement.innerHTML = oldHtml, 1000);
|
||||
if (result) {
|
||||
resolve(true);
|
||||
const textElement = unifyElement.getElementsByTagName('h4')[0]
|
||||
const oldHtml = textElement.innerHTML;
|
||||
textElement.innerHTML = 'Unified';
|
||||
setTimeout(() => textElement.innerHTML = oldHtml, 1000);
|
||||
} else resolve()
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
function switchInstance() {
|
||||
@ -462,8 +475,6 @@ function latency(name, frontend, document, location, splitNames) {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
export default {
|
||||
getRandomInstance,
|
||||
updateInstances,
|
||||
|
@ -11,7 +11,6 @@ let redirects = {
|
||||
"i2p": []
|
||||
}
|
||||
};
|
||||
const getRedirects = () => redirects;
|
||||
function setRedirects(val) {
|
||||
redirects.wikiless = val;
|
||||
browser.storage.local.set({ wikipediaRedirects: redirects })
|
||||
@ -238,7 +237,6 @@ async function initDefaults() {
|
||||
}
|
||||
|
||||
export default {
|
||||
getRedirects,
|
||||
setRedirects,
|
||||
|
||||
initWikilessCookies,
|
||||
|
@ -485,7 +485,7 @@ function setPipedLocalStorage(url, tabId) {
|
||||
})
|
||||
}
|
||||
|
||||
function initPipedMaterialLocalStorage(tabId) {
|
||||
function initPipedMaterialLocalStorage(url, tabId) {
|
||||
return new Promise(resolve => {
|
||||
browser.storage.local.get(
|
||||
[
|
||||
|
@ -94,12 +94,12 @@
|
||||
<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"></path>
|
||||
</svg>
|
||||
<h4>Settings</h4></a></div>
|
||||
<div class="some-block" title="Copy the original redirected link"> <a class="title button" id="copy_raw">
|
||||
<div class="some-block" id="copy_raw_div" title="Copy the original redirected link"> <a class="title button" id="copy_raw">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
||||
<path d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z"></path>
|
||||
</svg>
|
||||
<h4>Copy Raw</h4></a></div>
|
||||
<div class="some-block" title="Unify cookies across all selected instances"><a class="title button" id="unify">
|
||||
<div class="some-block" id="unify_div" title="Unify cookies across all selected instances"><a class="title button" id="unify">
|
||||
<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">
|
||||
<rect fill="none" height="24" width="24"></rect>
|
||||
<path d="M18,2H9C7.9,2,7,2.9,7,4v12c0,1.1,0.9,2,2,2h9c1.1,0,2-0.9,2-2V4C20,2.9,19.1,2,18,2z M18,16H9V4h9V16z M3,15v-2h2v2H3z M3,9.5h2v2H3V9.5z M10,20h2v2h-2V20z M3,18.5v-2h2v2H3z M5,22c-1.1,0-2-0.9-2-2h2V22z M8.5,22h-2v-2h2V22z M13.5,22L13.5,22l0-2h2 v0C15.5,21.1,14.6,22,13.5,22z M5,6L5,6l0,2H3v0C3,6.9,3.9,6,5,6z"></path>
|
||||
|
@ -78,9 +78,16 @@ document.addEventListener("change", () => {
|
||||
})
|
||||
|
||||
document.getElementById("change_instance").addEventListener("click", utils.switchInstance);
|
||||
document.getElementById('copy_raw').addEventListener("click", utils.copyRaw);
|
||||
let copyRawElement = document.getElementById('copy_raw');
|
||||
copyRawElement.addEventListener("click", () => utils.copyRaw(false, copyRawElement));
|
||||
|
||||
utils.copyRaw(true).then(r => { if (!r) document.getElementById('copy_raw_div').style.display = 'none'; })
|
||||
// utils.unify().then(r => { if (!r) document.getElementById('unify_div').style.display = 'none'; })
|
||||
|
||||
document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage());
|
||||
document.getElementById('unify').addEventListener("click", unify);
|
||||
|
||||
let unifyElement = document.getElementById('unify');
|
||||
unifyElement.addEventListener("click", () => utils.unify(unifyElement));
|
||||
|
||||
generalHelper.init().then(() => {
|
||||
let popupFrontends = generalHelper.getPopupFrontends();
|
||||
|
@ -108,12 +108,12 @@ html(lang="en")
|
||||
+settings
|
||||
h4 Settings
|
||||
|
||||
.some-block(title="Copy the original redirected link")
|
||||
#copy_raw_div.some-block(title="Copy the original redirected link")
|
||||
a#copy_raw.title.button
|
||||
+copy_raw
|
||||
h4 Copy Raw
|
||||
|
||||
.some-block(title="Unify cookies across all selected instances")
|
||||
#unify_div.some-block(title="Unify cookies across all selected instances")
|
||||
a#unify.title.button
|
||||
+unify
|
||||
h4 Unify Settings
|
||||
|
Loading…
x
Reference in New Issue
Block a user