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.commands.onCommand.addListener(async command => {
|
||||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
||||||
const url = new URL(tabs[0].url)
|
const url = new URL(tabs[0].url)
|
||||||
if (command == "switchInstance") {
|
switch (command) {
|
||||||
const newUrl = await servicesHelper.switchInstance(url)
|
case "switchInstance":
|
||||||
if (newUrl) browser.tabs.update({ url: newUrl })
|
const newUrl = await servicesHelper.switchInstance(url)
|
||||||
}
|
if (newUrl) browser.tabs.update({ url: newUrl })
|
||||||
else if (command == "copyRaw") {
|
break
|
||||||
servicesHelper.copyRaw(url)
|
case "copyRaw": {
|
||||||
}
|
servicesHelper.copyRaw(url)
|
||||||
else if (command == "redirect") {
|
break
|
||||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
}
|
||||||
if (tabs[0].url) {
|
case "redirect": {
|
||||||
const url = new URL(tabs[0].url)
|
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.update(tabs[0].id, { url: newUrl }, () => {
|
const newUrl = servicesHelper.redirect(url, "main_frame", null, true)
|
||||||
tabIdRedirects[tabs[0].id] = true
|
if (newUrl) {
|
||||||
})
|
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
||||||
|
tabIdRedirects[tabs[0].id] = true
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
break
|
||||||
}
|
}
|
||||||
else if (command == "reverse") {
|
case "reverse": {
|
||||||
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
||||||
if (tabs[0].url) {
|
if (tabs[0].url) {
|
||||||
const url = new URL(tabs[0].url)
|
const url = new URL(tabs[0].url)
|
||||||
const newUrl = await servicesHelper.reverse(url)
|
const newUrl = await servicesHelper.reverse(url)
|
||||||
if (newUrl) {
|
if (newUrl) {
|
||||||
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
browser.tabs.update(tabs[0].id, { url: newUrl }, () => {
|
||||||
tabIdRedirects[tabs[0].id] = false
|
tabIdRedirects[tabs[0].id] = false
|
||||||
})
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
})
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -201,7 +206,6 @@ browser.contextMenus.onClicked.addListener(async (info) => {
|
||||||
|
|
||||||
case 'copyReverseLink': {
|
case 'copyReverseLink': {
|
||||||
const url = new URL(info.linkUrl)
|
const url = new URL(info.linkUrl)
|
||||||
console.log(url)
|
|
||||||
await servicesHelper.copyRaw(url)
|
await servicesHelper.copyRaw(url)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -250,7 +254,6 @@ browser.contextMenus.onClicked.addListener(async (info) => {
|
||||||
else browser.tabs.create({ url: newUrl })
|
else browser.tabs.create({ url: newUrl })
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
case 'reverseBookmark':
|
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 pingCache = await utils.getPingCache()
|
||||||
|
let redundancyList = {}
|
||||||
for (const element of instanceElements) {
|
for (const element of instanceElements) {
|
||||||
let span = element.getElementsByClassName('ping')[0]
|
let span = element.getElementsByClassName('ping')[0]
|
||||||
if (!span) span = document.createElement('span')
|
if (!span) span = document.createElement('span')
|
||||||
span.classList = ['ping']
|
span.classList = ['ping']
|
||||||
span.innerHTML = '<span style="color:lightblue">pinging...</span>'
|
span.innerHTML = '<span style="color:lightblue">pinging...</span>'
|
||||||
element.appendChild(span)
|
element.appendChild(span)
|
||||||
|
|
||||||
const href = element.getElementsByTagName('a')[0].href
|
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)
|
const { color, text } = processTime(time)
|
||||||
span.innerHTML = `<span style="color:${color};">${text}</span>`
|
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 })
|
browser.storage.local.set({ pingCache })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue