dns-killer/background.js

46 lines
1.0 KiB
JavaScript
Raw Normal View History

2018-07-07 21:05:26 +08:00
/**
2020-11-04 17:59:31 +08:00
* DNS缓存杀手
* @author yutent<yutent.io@gmail.com>
* @date 2020/11/04 17:54:49
2018-07-07 21:05:26 +08:00
*/
2023-03-13 10:49:50 +08:00
chrome.action.onClicked.addListener(function (ctab) {
var cid = ctab.id
var tid = null
2018-07-29 14:09:34 +08:00
2023-03-13 10:49:50 +08:00
var callback = function () {
chrome.tabs.remove(tid)
chrome.scripting.executeScript({
target: { tabId: cid },
files: ['done.js']
})
}
2023-03-13 10:09:41 +08:00
2023-03-13 10:49:50 +08:00
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.create(
{ url: 'chrome://net-internals/#dns', active: false },
function (tab) {
2018-07-29 14:09:34 +08:00
tid = tab.id
2023-03-13 10:09:41 +08:00
chrome.scripting.executeScript(
{ target: { tabId: tab.id }, files: ['clean.js'] },
callback
)
2018-07-29 14:09:34 +08:00
}
2023-03-13 10:49:50 +08:00
)
}
2018-07-29 14:09:34 +08:00
})
2018-07-07 21:05:26 +08:00
})