Added buttons to the browser_action menu

This commit is contained in:
ManeraKai 2022-03-19 01:19:46 +03:00
parent 9de383439e
commit d333b96602
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
16 changed files with 97 additions and 72 deletions

View File

@ -90,7 +90,7 @@ function setProtocol(val) {
console.log("spotifyTargetsProtocol: ", val)
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let sojuList = [
@ -197,7 +197,7 @@ export default {
getSojuNormalCustomRedirects,
setSojuNormalCustomRedirects,
changeInstance,
switchInstance,
redirect,
init,

View File

@ -118,7 +118,7 @@ function redirect(url, type) {
return `${randomInstance}${url.pathname}${url.search}`;
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let imgurList = [
@ -207,5 +207,5 @@ export default {
redirect,
isImgur,
init,
changeInstance,
switchInstance,
};

View File

@ -120,7 +120,7 @@ function redirect(url, type, initiator) {
return `${randomInstance}/u${url.pathname}${url.search}`; // Likely a user profile, redirect to '/u/...'
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let instagramList = [
@ -266,5 +266,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -96,7 +96,7 @@ function setProtocol(val) {
console.log("lbryTargetsProtocol: ", val)
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let librarianList = [
@ -198,7 +198,7 @@ export default {
getLibrarianNormalCustomRedirects,
setLibrarianNormalCustomRedirects,
changeInstance,
switchInstance,
redirect,
init,

View File

@ -134,7 +134,7 @@ function redirect(url, type, initiator) {
return `${randomInstance}${url.pathname}${url.search}`;
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let mediumList = [
@ -221,5 +221,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -91,7 +91,7 @@ function setProtocol(val) {
console.log("peertubeTargetsProtocol: ", val)
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let simpleertubeList = [
@ -200,7 +200,7 @@ export default {
getSimpleertubeNormalCustomRedirects,
setSimpleertubeNormalCustomRedirects,
changeInstance,
switchInstance,
redirect,
init,

View File

@ -275,12 +275,12 @@ function redirect(url, type, initiator) {
if (
alwaysUsePreferred && frontend == 'teddit' &&
(isTeddit || isLibreddit) && !isCheckedTeddit
) return changeInstance(url);
) return switchInstance(url);
if (
alwaysUsePreferred && frontend == 'libreddit' &&
(isTeddit || isLibreddit) && !isCheckedLibreddit
) return changeInstance(url);
) return switchInstance(url);
if (!targets.some((rx) => rx.test(url.href))) return null;
@ -364,7 +364,7 @@ function redirect(url, type, initiator) {
}
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let isTeddit = [
@ -523,5 +523,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -269,7 +269,7 @@ function redirect(url) {
return `${randomInstance}${path}${searchQuery}`;
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let searchList = [
@ -409,5 +409,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -106,7 +106,7 @@ function setProtocol(val) {
console.log("sendTargetsProtocol: ", val)
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let sendList = [
@ -210,7 +210,7 @@ export default {
getSendNormalCustomRedirects,
setSendNormalCustomRedirects,
changeInstance,
switchInstance,
redirect,
init,

View File

@ -270,7 +270,7 @@ function redirect(url) {
}
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let translateList = [
@ -413,5 +413,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -116,7 +116,7 @@ function redirect(url, initiator) {
...nitterTorCustomRedirects
].includes(protocolHost);
if (alwaysUsePreferred && isNitter && !isCheckedNitter) return changeInstance(url);
if (alwaysUsePreferred && isNitter && !isCheckedNitter) return switchInstance(url);
if (disable) return null;
@ -158,7 +158,7 @@ function redirect(url, initiator) {
return `${randomInstance}${url.pathname}${url.search}`;
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let twitterList = [
@ -307,5 +307,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -156,7 +156,7 @@ function redirect(url) {
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
let wikipediaList = [
@ -250,5 +250,5 @@ export default {
redirect,
init,
changeInstance,
switchInstance,
};

View File

@ -347,12 +347,12 @@ function redirect(url, details, initiator) {
if (
alwaysUsePreferred && frontend == 'invidious' &&
(isInvidious || isPiped) && !isCheckedInvidious
) return changeInstance(url);
) return switchInstance(url);
if (
alwaysUsePreferred && frontend == 'piped' &&
(isInvidious || isPiped) && !isCheckedPiped
) return changeInstance(url);
) return switchInstance(url);
if (!targets.some((rx) => rx.test(url.href))) return null;
@ -447,7 +447,7 @@ function redirect(url, details, initiator) {
return 'CANCEL';
}
function changeInstance(url) {
function switchInstance(url) {
let protocolHost = `${url.protocol}//${url.host}`;
if (
protocol == 'normal' &&
@ -730,7 +730,7 @@ export default {
setPipedRedirects,
redirect,
changeInstance,
switchInstance,
isPipedorInvidious,

View File

@ -18,6 +18,7 @@
"webRequestBlocking",
"storage",
"cookies",
"menus",
"<all_urls>"
],
"browser_action": {
@ -47,11 +48,11 @@
}
},
"commands": {
"changeInstance": {
"switchInstance": {
"suggested_key": {
"default": "Alt+Shift+L"
},
"description": "Change Instance"
"description": "Switch Instance"
}
}
}

View File

@ -137,28 +137,28 @@ browser.webRequest.onResponseStarted.addListener(
const url = new URL(details.url);
let newUrl;
newUrl = youtubeHelper.changeInstance(url);
if (!newUrl) newUrl = twitterHelper.changeInstance(url);
newUrl = youtubeHelper.switchInstance(url);
if (!newUrl) newUrl = twitterHelper.switchInstance(url);
if (!newUrl) newUrl = instagramHelper.changeInstance(url);
if (!newUrl) newUrl = instagramHelper.switchInstance(url);
if (!newUrl) newUrl = redditHelper.changeInstance(url);
if (!newUrl) newUrl = redditHelper.switchInstance(url);
if (!newUrl) newUrl = searchHelper.changeInstance(url);
if (!newUrl) newUrl = searchHelper.switchInstance(url);
if (!newUrl) newUrl = translateHelper.changeInstance(url);
if (!newUrl) newUrl = translateHelper.switchInstance(url);
if (!newUrl) newUrl = mediumHelper.changeInstance(url);
if (!newUrl) newUrl = mediumHelper.switchInstance(url);
if (!newUrl) newUrl = imgurHelper.changeInstance(url);
if (!newUrl) newUrl = imgurHelper.switchInstance(url);
if (!newUrl) newUrl = wikipediaHelper.changeInstance(url);
if (!newUrl) newUrl = wikipediaHelper.switchInstance(url);
if (!newUrl) newUrl = peertubeHelper.changeInstance(url);
if (!newUrl) newUrl = peertubeHelper.switchInstance(url);
if (!newUrl) newUrl = lbryHelper.changeInstance(url);
if (!newUrl) newUrl = lbryHelper.switchInstance(url);
// if (!newUrl) newUrl = spotifyHelper.changeInstance(url);
// if (!newUrl) newUrl = spotifyHelper.switchInstance(url);
if (newUrl) browser.tabs.update(details.tabId, { url: `/pages/errors/instance_offline.html?url=${encodeURIComponent(newUrl)}` });
@ -181,34 +181,34 @@ browser.tabs.onUpdated.addListener(
});
function changeWholeInstance(url) {
let newUrl = youtubeHelper.changeInstance(url);
let newUrl = youtubeHelper.switchInstance(url);
if (!newUrl) newUrl = twitterHelper.changeInstance(url);
if (!newUrl) newUrl = twitterHelper.switchInstance(url);
if (!newUrl) newUrl = instagramHelper.changeInstance(url);
if (!newUrl) newUrl = instagramHelper.switchInstance(url);
if (!newUrl) newUrl = redditHelper.changeInstance(url);
if (!newUrl) newUrl = redditHelper.switchInstance(url);
if (!newUrl) newUrl = searchHelper.changeInstance(url);
if (!newUrl) newUrl = searchHelper.switchInstance(url);
if (!newUrl) newUrl = translateHelper.changeInstance(url);
if (!newUrl) newUrl = translateHelper.switchInstance(url);
if (!newUrl) newUrl = mediumHelper.changeInstance(url);
if (!newUrl) newUrl = mediumHelper.switchInstance(url);
if (!newUrl) newUrl = sendTargetsHelper.changeInstance(url);
if (!newUrl) newUrl = sendTargetsHelper.switchInstance(url);
if (!newUrl) newUrl = peertubeHelper.changeInstance(url);
if (!newUrl) newUrl = peertubeHelper.switchInstance(url);
if (!newUrl) newUrl = imgurHelper.changeInstance(url);
if (!newUrl) newUrl = imgurHelper.switchInstance(url);
if (!newUrl) newUrl = wikipediaHelper.changeInstance(url);
if (!newUrl) newUrl = wikipediaHelper.switchInstance(url);
return newUrl;
}
browser.commands.onCommand.addListener(
command => {
if (command === 'changeInstance')
if (command === 'switchInstance')
chrome.tabs.query(
{ active: true, currentWindow: true },
tabs => {
@ -220,4 +220,28 @@ browser.commands.onCommand.addListener(
}
);
}
)
)
browser.menus.create({
id: "settings",
title: "Settings",
contexts: ["browser_action"]
});
browser.menus.create({
id: "switchInstance",
title: "Switch Instance",
contexts: ["browser_action"]
});
browser.menus.onClicked.addListener((info, tab) => {
if (info.menuItemId == 'switchInstance') {
let url;
try { url = new URL(tab.url); }
catch (_) { return }
let newUrl = changeWholeInstance(url);
if (newUrl) browser.tabs.update({ url: newUrl });
}
else if (info.menuItemId == 'settings')
browser.runtime.openOptionsPage()
});

View File

@ -78,7 +78,7 @@ wholeInit().then(() => {
disableLbryElement.checked = !lbryHelper.getDisable();
let changeInstanceElement = document.getElementById("change-instance")
changeInstanceElement.addEventListener("click", changeInstance);
changeInstanceElement.addEventListener("click", switchInstance);
})
disableTwitterElement.addEventListener("change",
@ -154,7 +154,7 @@ document.getElementById("more-options").addEventListener("click",
);
function changeInstance() {
function switchInstance() {
browser.tabs.query({ active: true, currentWindow: true }, function (tabs) {
let currTab = tabs[0];
if (currTab) {
@ -164,29 +164,29 @@ function changeInstance() {
catch (_) { return false; }
let newUrl;
newUrl = youtubeHelper.changeInstance(tabUrl);
newUrl = youtubeHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = twitterHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = twitterHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = instagramHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = instagramHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = redditHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = redditHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = searchHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = searchHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = translateHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = translateHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = mediumHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = mediumHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = sendTargetsHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = sendTargetsHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = peertubeHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = peertubeHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = lbryHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = lbryHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = imgurHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = imgurHelper.switchInstance(tabUrl);
if (!newUrl) newUrl = wikipediaHelper.changeInstance(tabUrl);
if (!newUrl) newUrl = wikipediaHelper.switchInstance(tabUrl);
if (newUrl) {
browser.tabs.update({ url: newUrl });