master
yutent 2023-03-13 10:49:50 +08:00
parent 34b5bcbdbd
commit c0682bff33
1 changed files with 29 additions and 31 deletions

View File

@ -4,44 +4,42 @@
* @date 2020/11/04 17:54:49 * @date 2020/11/04 17:54:49
*/ */
chrome.runtime.onInstalled.addListener(() => { chrome.action.onClicked.addListener(function (ctab) {
chrome.action.onClicked.addListener(function (ctab) { var cid = ctab.id
var cid = ctab.id var tid = null
var tid = null
var callback = function () { var callback = function () {
chrome.tabs.remove(tid) chrome.tabs.remove(tid)
chrome.scripting.executeScript({ chrome.scripting.executeScript({
target: { tabId: cid }, target: { tabId: cid },
files: ['done.js'] files: ['done.js']
}) })
}
chrome.tabs.query({}, function (tabs) {
var done = false
for (let i = 0, tab; (tab = tabs[i++]); ) {
if (/^chrome:\/\/net-internals/.test(tab.url)) {
tid = tab.id
chrome.scripting.executeScript(
{ target: { tabId: tab.id }, files: ['clean.js'] },
callback
)
done = true
break
}
} }
if (!done) {
chrome.tabs.query({}, function (tabs) { chrome.tabs.create(
var done = false { url: 'chrome://net-internals/#dns', active: false },
for (let i = 0, tab; (tab = tabs[i++]); ) { function (tab) {
if (/^chrome:\/\/net-internals/.test(tab.url)) {
tid = tab.id tid = tab.id
chrome.scripting.executeScript( chrome.scripting.executeScript(
{ target: { tabId: tab.id }, files: ['clean.js'] }, { target: { tabId: tab.id }, files: ['clean.js'] },
callback callback
) )
done = true
break
} }
} )
if (!done) { }
chrome.tabs.create(
{ url: 'chrome://net-internals/#dns', active: false },
function (tab) {
tid = tab.id
chrome.scripting.executeScript(
{ target: { tabId: tab.id }, files: ['clean.js'] },
callback
)
}
)
}
})
}) })
}) })