我即将完成我的扩展,我所需要的只是 popup.html 中的一个开/关开关,它将控制“chrome://extensions”选项卡中的相同开关。可能吗?
这就是我所做的: 弹出.html:
// on/off switch
<div class="center custom-control custom-switch">
<input type="checkbox" class="custom-control-input" id="customSwitch1">
<label class="custom-control-label" for="customSwitch1">PAUSE / START</label>
</div>
popup.js:
var ss = document.getElementById("customSwitch1");
$(ss).click(function() {
if($(ss).prop("checked")){
chrome.runtime.sendMessage({isOn: "true"}, function(response) {
console.log(response.farewell);
});
}
else{
chrome.runtime.sendMessage({isOn: "false"}, function(response) {
console.log(response.state);
});
}
});
背景.js:
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.isOn == "true")
sendResponse({state: "true"});
if (request.isOn == "false")
sendResponse({state: "false"});
});
最佳答案
您可以在 Chrome 中保留扩展程序的启用状态,并让弹出窗口仅控制扩展程序正在处理的内容的暂停/开始,而不是禁用整个扩展程序。
关于javascript - 是否可以在没有 chrome 的情况下从弹出窗口打开/关闭扩展 ://extensions tab?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55792406/