master
yutent 2023-03-13 10:09:41 +08:00
parent 0ed2c11370
commit 1fcc0ec2f8
10 changed files with 56 additions and 45 deletions

View File

@ -4,40 +4,44 @@
* @date 2020/11/04 17:54:49 * @date 2020/11/04 17:54:49
*/ */
chrome.browserAction.onClicked.addListener(function(ctab) { chrome.runtime.onInstalled.addListener(() => {
var cid = ctab.id chrome.action.onClicked.addListener(function (ctab) {
var tid = null var cid = ctab.id
var code = ` var tid = null
var script = document.createElement('script')
script.textContent = \`
chrome.send('clearHostResolverCache')
chrome.send('flushSocketPools')
\`
document.body.appendChild(script)
`
var callback = function() {
chrome.tabs.remove(tid)
chrome.tabs.executeScript(cid, { code: 'location.reload()' })
}
chrome.tabs.query({}, function(tabs) { var callback = function () {
var done = false chrome.tabs.remove(tid)
for (let i = 0, tab; (tab = tabs[i++]); ) { chrome.scripting.executeScript({
if (/^chrome:\/\/net-internals/.test(tab.url)) { target: { tabId: cid },
tid = tab.id files: ['done.js']
chrome.tabs.executeScript(tab.id, { code }, callback) })
done = true
break
}
} }
if (!done) {
chrome.tabs.create( chrome.tabs.query({}, function (tabs) {
{ url: 'chrome://net-internals/#dns', active: false }, var done = false
function(tab) { for (let i = 0, tab; (tab = tabs[i++]); ) {
if (/^chrome:\/\/net-internals/.test(tab.url)) {
tid = tab.id tid = tab.id
chrome.tabs.executeScript(tab.id, { code }, callback) 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) {
tid = tab.id
chrome.scripting.executeScript(
{ target: { tabId: tab.id }, files: ['clean.js'] },
callback
)
}
)
}
})
}) })
}) })

6
clean.js Normal file
View File

@ -0,0 +1,6 @@
console.log(chrome)
// chrome.send('clearHostResolverCache')
// chrome.send('flushSocketPools')
window['dns-view-clear-cache'].click()
window['sockets-view-flush-button'].click()

1
done.js Normal file
View File

@ -0,0 +1 @@
location.reload()

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.7 KiB

BIN
icons/128.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

BIN
icons/256.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

BIN
icons/64.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@ -1,24 +1,24 @@
{ {
"manifest_version": 2, "manifest_version": 3,
"name": "dns-killer", "name": "dns-killer",
"description": "DNS缓存杀手,一键清除chrome的DNS缓存, 并刷新当前选项卡。 web开发的利器。", "description": "DNS缓存杀手,一键清除chrome的DNS缓存, 并刷新当前选项卡。 web开发的利器。",
"version": "1.0.0", "version": "2.0.0",
"author": "yutent", "author": "yutent",
"icons": { "icons": {
"64": "icon64.png", "64": "icons/64.png",
"128": "icon128.png", "128": "icons/128.png",
"256": "icon256.png" "256": "icons/256.png"
}, },
"background": { "background": {
"scripts": ["background.js"] "service_worker": "background.js",
"type": "module"
}, },
"browser_action": { "action": {
"default_icon": "icon64.png" "default_icon": { "64": "icons/64.png", "128": "icons/128.png" },
"default_title": "点击清除DNS缓存"
}, },
"permissions": [ "permissions": ["tabs", "activeTab", "scripting"],
"tabs", "host_permissions": ["chrome://net-internals/#dns"],
"chrome://net-internals/#dns", "optional_host_permissions": ["chrome://extensions/"],
"chrome://extensions/" "homepage_url": "https://github.com/yutent"
],
"homepage_url": "https://yutent.top"
} }