Fixed bugs in the context menus

This commit is contained in:
ManeraKai 2023-03-05 19:35:14 +03:00
parent abe83d3c68
commit c5cd80da59
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 46 additions and 27 deletions

View File

@ -807,7 +807,17 @@ async function copyRaw(url, test) {
const newUrl = await reverse(url) const newUrl = await reverse(url)
if (newUrl) { if (newUrl) {
if (!test) { if (!test) {
navigator.clipboard.writeText(newUrl) if (!window.chrome) {
navigator.clipboard.writeText(newUrl)
} else {
var copyFrom = document.createElement("textarea");
copyFrom.textContent = newUrl;
document.body.appendChild(copyFrom);
copyFrom.select()
document.execCommand('copy')
copyFrom.blur();
document.body.removeChild(copyFrom);
}
} }
return newUrl return newUrl
} }

View File

@ -31,7 +31,6 @@ let tabIdRedirects = {}
// true == Always redirect, false == Never redirect, null/undefined == follow options for services // true == Always redirect, false == Never redirect, null/undefined == follow options for services
browser.webRequest.onBeforeRequest.addListener( browser.webRequest.onBeforeRequest.addListener(
details => { details => {
console.log(details.url)
const url = new URL(details.url) const url = new URL(details.url)
if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest") return if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest") return
let initiator let initiator
@ -93,20 +92,20 @@ browser.commands.onCommand.addListener(async command => {
}) })
browser.contextMenus.create({ browser.contextMenus.create({
id: "settings", id: "settingsTab",
title: browser.i18n.getMessage("settings"), title: browser.i18n.getMessage("settings"),
contexts: ["browser_action"], contexts: ["browser_action"],
}) })
browser.contextMenus.create({ browser.contextMenus.create({
id: "switchInstance", id: "switchInstanceTab",
title: browser.i18n.getMessage("switchInstance"), title: browser.i18n.getMessage("switchInstance"),
contexts: ["browser_action"], contexts: ["browser_action"],
}) })
browser.contextMenus.create({ browser.contextMenus.create({
id: "copyReverse", id: "copyReverseTab",
title: 'Copy reverse', title: 'Copy Original',
contexts: ["browser_action"], contexts: ["browser_action"],
}) })
@ -118,7 +117,7 @@ browser.contextMenus.create({
browser.contextMenus.create({ browser.contextMenus.create({
id: "reverseTab", id: "reverseTab",
title: 'Reverse redirect', title: 'Redirect To Original',
contexts: ["browser_action"], contexts: ["browser_action"],
}) })
@ -130,13 +129,13 @@ browser.contextMenus.create({
browser.contextMenus.create({ browser.contextMenus.create({
id: "reverseLink", id: "reverseLink",
title: 'Reverse redirect', title: 'Redirect To Original',
contexts: ["link"], contexts: ["link"],
}) })
browser.contextMenus.create({ browser.contextMenus.create({
id: "copyReverseLink", id: "copyReverseLink",
title: 'Copy Reverse', title: 'Copy Original',
contexts: ["link"], contexts: ["link"],
}) })
@ -162,8 +161,9 @@ if (!window.chrome) {
browser.contextMenus.onClicked.addListener(async (info) => { browser.contextMenus.onClicked.addListener(async (info) => {
console.log(info)
switch (info.menuItemId) { switch (info.menuItemId) {
case 'switchInstance': { case 'switchInstanceTab': {
const url = new URL(info.pageUrl) const url = new URL(info.pageUrl)
const newUrl = await servicesHelper.switchInstance(url) const newUrl = await servicesHelper.switchInstance(url)
if (newUrl) { if (newUrl) {
@ -171,39 +171,48 @@ browser.contextMenus.onClicked.addListener(async (info) => {
} }
return return
} }
case 'settings': { case 'settingsTab': {
browser.runtime.openOptionsPage() browser.runtime.openOptionsPage()
return return
} }
case 'copyReverse': { case 'copyReverseTab': {
const url = new URL(info.pageUrl) const url = new URL(info.pageUrl)
servicesHelper.copyRaw(url) servicesHelper.copyRaw(url)
return return
} }
case 'reverseTab': { case 'reverseTab': {
const url = new URL(info.pageUrl) browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
const newUrl = await servicesHelper.reverse(url) if (tabs[0].url) {
if (newUrl) { const url = new URL(tabs[0].url)
browser.tabs.create({ url: newUrl }, tab => { const newUrl = await servicesHelper.reverse(url)
tabIdRedirects[tab.id] = false if (newUrl) {
}) browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
} tabIdRedirects[tabs[0].id] = false
})
}
}
})
return return
} }
case 'redirectTab': { case 'redirectTab': {
const url = new URL(info.pageUrl) browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
const newUrl = servicesHelper.redirect(url, "main_frame", null, true) if (tabs[0].url) {
if (newUrl) { const url = new URL(tabs[0].url)
browser.tabs.create({ url: newUrl }, tab => { const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
tabIdRedirects[tab.id] = false if (newUrl) {
}) browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
} tabIdRedirects[tabs[0].id] = true
})
}
}
})
return return
} }
case 'copyReverseLink': { case 'copyReverseLink': {
const url = new URL(info.linkUrl) const url = new URL(info.linkUrl)
servicesHelper.copyRaw(url) console.log(url)
await servicesHelper.copyRaw(url)
return return
} }
case 'redirectLink': { case 'redirectLink': {