Avoided Redundancy in ping test https://github.com/libredirect/browser_extension/issues/827
This commit is contained in:
parent
0710585ea3
commit
8649bad9b9
|
@ -90,38 +90,43 @@ browser.tabs.onRemoved.addListener(tabId => {
|
|||
browser.commands.onCommand.addListener(async command => {
|
||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
||||
const url = new URL(tabs[0].url)
|
||||
if (command == "switchInstance") {
|
||||
const newUrl = await servicesHelper.switchInstance(url)
|
||||
if (newUrl) browser.tabs.update({ url: newUrl })
|
||||
}
|
||||
else if (command == "copyRaw") {
|
||||
servicesHelper.copyRaw(url)
|
||||
}
|
||||
else if (command == "redirect") {
|
||||
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
|
||||
})
|
||||
switch (command) {
|
||||
case "switchInstance":
|
||||
const newUrl = await servicesHelper.switchInstance(url)
|
||||
if (newUrl) browser.tabs.update({ url: newUrl })
|
||||
break
|
||||
case "copyRaw": {
|
||||
servicesHelper.copyRaw(url)
|
||||
break
|
||||
}
|
||||
case "redirect": {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
else if (command == "reverse") {
|
||||
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
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
case "reverse": {
|
||||
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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
break
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -201,7 +206,6 @@ browser.contextMenus.onClicked.addListener(async (info) => {
|
|||
|
||||
case 'copyReverseLink': {
|
||||
const url = new URL(info.linkUrl)
|
||||
console.log(url)
|
||||
await servicesHelper.copyRaw(url)
|
||||
return
|
||||
}
|
||||
|
@ -250,7 +254,6 @@ browser.contextMenus.onClicked.addListener(async (info) => {
|
|||
else browser.tabs.create({ url: newUrl })
|
||||
}
|
||||
})
|
||||
|
||||
return
|
||||
}
|
||||
case 'reverseBookmark':
|
||||
|
@ -302,4 +305,4 @@ browser.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
|
@ -338,18 +338,21 @@ async function ping(frontend) {
|
|||
]
|
||||
|
||||
let pingCache = await utils.getPingCache()
|
||||
let redundancyList = {}
|
||||
for (const element of instanceElements) {
|
||||
let span = element.getElementsByClassName('ping')[0]
|
||||
if (!span) span = document.createElement('span')
|
||||
span.classList = ['ping']
|
||||
span.innerHTML = '<span style="color:lightblue">pinging...</span>'
|
||||
element.appendChild(span)
|
||||
|
||||
const href = element.getElementsByTagName('a')[0].href
|
||||
const time = await utils.ping(href)
|
||||
const innerHTML = element.getElementsByTagName('a')[0].innerHTML
|
||||
const time = redundancyList[innerHTML] ?? await utils.ping(href)
|
||||
const { color, text } = processTime(time)
|
||||
span.innerHTML = `<span style="color:${color};">${text}</span>`
|
||||
pingCache[element.getElementsByTagName('a')[0].innerHTML] = time
|
||||
pingCache[innerHTML] = time
|
||||
redundancyList[innerHTML] = time
|
||||
|
||||
browser.storage.local.set({ pingCache })
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue