修改点击逻辑

master
Liu Chao 2023-07-30 21:40:35 +08:00
parent ec251e8d0e
commit 0e27def107
2 changed files with 27 additions and 20 deletions

View File

@ -1,4 +1,13 @@
chrome.browserAction.onClicked.addListener(function(tab) { chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.create({ url: 'chrome://flags/#enable-force-dark' }); chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
var tab = tabs[0];
var url = tab.url;
if (url === 'chrome://flags/#enable-force-dark') {
chrome.tabs.update(tab.id, { url: 'chrome://flags/' });
} else {
chrome.tabs.update(tab.id, { url: 'chrome://flags/#enable-force-dark' });
}
});
}); });

View File

@ -1,21 +1,19 @@
{ {
"manifest_version": 2, "manifest_version": 2,
"name": "Auto Dark Mode Toggle", "name": "Auto Dark Mode Toggle",
"version": "1.0", "version": "1.0",
"description": "Toggle the 'Auto Dark Mode for Web Contents' flag in Chrome://flags", "description": "Toggle the 'Auto Dark Mode for Web Contents' flag in Chrome://flags",
"icons": { "icons": {
"16": "icon.png", "16": "icon.png",
"48": "icon.png", "48": "icon.png",
"128": "icon.png" "128": "icon.png"
}, },
"browser_action": { "background": {
"default_popup": "popup.html" "scripts": ["background.js"],
}, "persistent": false
"permissions": [ },
"tabs" "permissions": [
], "tabs"
"background": { ]
"scripts": ["background.js"],
"persistent": false
} }
}