dns-killer/background.js

48 lines
1.1 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:09:41 +08:00
chrome.runtime.onInstalled.addListener(() => {
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:09:41 +08:00
var callback = function () {
chrome.tabs.remove(tid)
chrome.scripting.executeScript({
target: { tabId: cid },
files: ['done.js']
})
2018-07-29 14:09:34 +08:00
}
2023-03-13 10:09:41 +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)) {
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
)
done = true
break
2018-07-29 14:09:34 +08:00
}
2023-03-13 10:09:41 +08:00
}
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
)
}
)
}
})
2018-07-29 14:09:34 +08:00
})
2018-07-07 21:05:26 +08:00
})