Added context menu buttons to the popup

This commit is contained in:
ManeraKai 2023-03-10 13:12:17 +03:00
parent c8a6b7797a
commit fdfd940e63
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
8 changed files with 97 additions and 75 deletions

BIN
img/1.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 677 KiB

After

Width:  |  Height:  |  Size: 714 KiB

BIN
img/2.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 96 KiB

After

Width:  |  Height:  |  Size: 130 KiB

BIN
img/3.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 111 KiB

After

Width:  |  Height:  |  Size: 144 KiB

View File

@ -44,6 +44,11 @@ function regexArray(service, url, config, frontend) {
return false return false
} }
async function redirectAsync(url, type, initiator, forceRedirection) {
await init()
return redirect(url, type, initiator, forceRedirection)
}
function redirect(url, type, initiator, forceRedirection) { function redirect(url, type, initiator, forceRedirection) {
if (type != "main_frame" && type != "sub_frame" && type != "image") return if (type != "main_frame" && type != "sub_frame" && type != "image") return
let randomInstance let randomInstance
@ -846,6 +851,7 @@ async function copyRaw(url, test) {
export default { export default {
redirect, redirect,
redirectAsync,
computeService, computeService,
reverse, reverse,
initDefaults, initDefaults,

View File

@ -92,72 +92,20 @@ browser.commands.onCommand.addListener(async command => {
}) })
}) })
browser.contextMenus.create({ browser.contextMenus.create({ id: "settingsTab", title: browser.i18n.getMessage("settings"), contexts: ["browser_action"] })
id: "settingsTab", browser.contextMenus.create({ id: "switchInstanceTab", title: browser.i18n.getMessage("switchInstance"), contexts: ["browser_action"] })
title: browser.i18n.getMessage("settings"), browser.contextMenus.create({ id: "copyReverseTab", title: 'Copy Original', contexts: ["browser_action"] })
contexts: ["browser_action"], browser.contextMenus.create({ id: "redirectTab", title: 'Redirect', contexts: ["browser_action"] })
}) browser.contextMenus.create({ id: "reverseTab", title: 'Redirect To Original', contexts: ["browser_action"] })
browser.contextMenus.create({ browser.contextMenus.create({ id: "redirectLink", title: 'Redirect', contexts: ["link"] })
id: "switchInstanceTab", browser.contextMenus.create({ id: "reverseLink", title: 'Redirect To Original', contexts: ["link"] })
title: browser.i18n.getMessage("switchInstance"), browser.contextMenus.create({ id: "copyReverseLink", title: 'Copy Original', contexts: ["link"] })
contexts: ["browser_action"],
})
browser.contextMenus.create({
id: "copyReverseTab",
title: 'Copy Original',
contexts: ["browser_action"],
})
browser.contextMenus.create({
id: "redirectTab",
title: 'Redirect',
contexts: ["browser_action"],
})
browser.contextMenus.create({
id: "reverseTab",
title: 'Redirect To Original',
contexts: ["browser_action"],
})
browser.contextMenus.create({
id: "redirectLink",
title: 'Redirect',
contexts: ["link"],
})
browser.contextMenus.create({
id: "reverseLink",
title: 'Redirect To Original',
contexts: ["link"],
})
browser.contextMenus.create({
id: "copyReverseLink",
title: 'Copy Original',
contexts: ["link"],
})
if (!isChrome) { if (!isChrome) {
browser.contextMenus.create({ browser.contextMenus.create({ id: "redirectBookmark", title: 'Redirect', contexts: ["bookmark"] })
id: "redirectBookmark", browser.contextMenus.create({ id: "reverseBookmark", title: 'Redirect To Original', contexts: ["bookmark"] })
title: 'Redirect', browser.contextMenus.create({ id: "copyReverseBookmark", title: 'Copy Original', contexts: ["bookmark"] })
contexts: ["bookmark"],
})
browser.contextMenus.create({
id: "reverseBookmark",
title: 'Redirect To Original',
contexts: ["bookmark"],
})
browser.contextMenus.create({
id: "copyReverseBookmark",
title: 'Copy Original',
contexts: ["bookmark"],
})
} }
@ -276,3 +224,33 @@ browser.webRequest.onHeadersReceived.addListener(
{ urls: ["<all_urls>"] }, { urls: ["<all_urls>"] },
["blocking", "responseHeaders"] ["blocking", "responseHeaders"]
) )
browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request == "reverseTab") {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
if (tabs[0].url) {
const url = new URL(tabs[0].url)
const newUrl = await servicesHelper.reverse(url)
if (newUrl) {
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
tabIdRedirects[tabs[0].id] = false
})
}
}
})
}
else if (request == "redirectTab") {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
if (tabs[0].url) {
const url = new URL(tabs[0].url)
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
if (newUrl) {
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
tabIdRedirects[tabs[0].id] = true
})
}
}
})
}
});

View File

@ -19,16 +19,37 @@ browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
}) })
servicesHelper.copyRaw(url, true).then(r => { servicesHelper.copyRaw(url, true).then(r => {
if (!r) { if (!r) {
document.getElementById("copy_raw_div").style.display = "none" document.getElementById("copy_original_div").style.display = "none"
} }
else { else {
const copy_raw = document.getElementById("copy_raw") document.getElementById("copy_original").addEventListener("click", () => servicesHelper.copyRaw(url))
copy_raw.addEventListener("click", () => servicesHelper.copyRaw(url)) }
})
servicesHelper.reverse(url).then(r => {
if (!r) {
document.getElementById("redirect_to_original_div").style.display = "none"
} else {
document.getElementById("redirect_to_original").addEventListener("click", () => {
browser.runtime.sendMessage("reverseTab");
calcButtons()
})
}
})
servicesHelper.redirectAsync(url, "main_frame", null, true).then(r => {
if (!r) {
document.getElementById("redirect_div").style.display = "none"
} else {
document.getElementById("redirect").addEventListener("click", () => {
browser.runtime.sendMessage("redirectTab");
calcButtons()
})
} }
}) })
} else { } else {
document.getElementById("change_instance_div").style.display = "none" document.getElementById("change_instance_div").style.display = "none"
document.getElementById("copy_raw_div").style.display = "none" document.getElementById("copy_original_div").style.display = "none"
document.getElementById("redirect_div").style.display = "none"
document.getElementById("redirect_to_original_div").style.display = "none"
} }
}) })

View File

@ -18,21 +18,33 @@ html(lang="en")
div(class="some-block" id="change_instance_div") div(class="some-block" id="change_instance_div")
a(class="title button prevent" id="change_instance") a(class="title button prevent" id="change_instance")
h4(data-localise="__MSG_switchInstance__") Change Instance h4() Switch Instance
svg(xmlns="http://www.w3.org/2000/svg" height="26px" viewBox="0 0 24 24" width="26px" fill="currentColor") svg(xmlns="http://www.w3.org/2000/svg" height="26px" width="26px" fill="currentColor")
path(d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z") path(d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z")
div(class="some-block" id="copy_raw_div" title="Copy the original redirected link") div(class="some-block" id="copy_original_div" title="Copy the original redirected link")
a(class="title button prevent" id="copy_raw") a(class="title button prevent" id="copy_original")
h4(data-localise="__MSG_copyRaw__") Copy Raw h4() Copy Original
svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") svg(xmlns="http://www.w3.org/2000/svg" height="24px" 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(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")
div(class="some-block" id="redirect_div")
a(class="title button prevent" id="redirect")
h4 Redirect
svg(xmlns="http://www.w3.org/2000/svg" height="24" width="24" fill="currentColor")
path(d="M7 20v-9q0-.825.588-1.413Q8.175 9 9 9h8.2l-1.6-1.6L17 6l4 4-4 4-1.4-1.4 1.6-1.6H9v9Z")
div(class="some-block" id="redirect_to_original_div")
a(class="title button prevent" id="redirect_to_original")
h4 Redirect To Original
svg(xmlns="http://www.w3.org/2000/svg" height="24px" width="24px" fill="currentColor")
path(d="M 17,20 V 11 Q 17,10.175 16.412,9.587 15.825,9 15,9 H 6.8 L 8.4,7.4 7,6 3,10 7,14 8.4,12.6 6.8,11 H 15 v 9 z" id="path2")
div(class="some-block") div(class="some-block")
a(class="title button prevent" id="more-options") a(class="title button prevent" id="more-options")
h4(data-localise="__MSG_settings__") Settings h4(data-localise="__MSG_settings__") Settings
svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="26px" viewBox="0 0 24 24" width="26px" fill="currentColor") svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="26px" width="26px" fill="currentColor")
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(d="m9.25 22-.4-3.2q-.325-.125-.612-.3-.288-.175-.563-.375L4.7 19.375l-2.75-4.75 2.575-1.95Q4.5 12.5 4.5 12.337v-.675q0-.162.025-.337L1.95 9.375l2.75-4.75 2.975 1.25q.275-.2.575-.375.3-.175.6-.3l.4-3.2h5.5l.4 3.2q.325.125.613.3.287.175.562.375l2.975-1.25 2.75 4.75-2.575 1.95q.025.175.025.337v.675q0 .163-.05.338l2.575 1.95-2.75 4.75-2.95-1.25q-.275.2-.575.375-.3.175-.6.3l-.4 3.2Zm2.8-6.5q1.45 0 2.475-1.025Q15.55 13.45 15.55 12q0-1.45-1.025-2.475Q13.5 8.5 12.05 8.5q-1.475 0-2.488 1.025Q8.55 10.55 8.55 12q0 1.45 1.012 2.475Q10.575 15.5 12.05 15.5Z")
div(class="space") div(class="space")
script(type="module" src="../options/init.js") script(type="module" src="../options/init.js")

View File

@ -28,6 +28,11 @@ input {
width: 46px; width: 46px;
} }
.button h4 {
font-size: 16px;
max-width: 160px;
}
#instance { #instance {
max-width: 110px; max-width: 110px;
max-height: 22px; max-height: 22px;