gpt4 book ai didi

javascript - 如何让我的 chrome 扩展程序记住拨动开关或其他操作?

转载 作者:行者123 更新时间:2023-11-30 19:42:38 26 4
gpt4 key购买 nike

我的 chrome 扩展不记得拨动开关。我正在尝试进行扩展以在切换开关打开时阻止 youtube 提要和评论。我尝试在评论部分这样做,但它不起作用。

if(document.getElementById("input1").checked == true){
document.getElementByClassName("ytd-comments").style.display = "none";
}
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
</head>
<body>
<!-- Rounded switch -->
<div>
<label class="switch">
<input id="input0" type="checkbox">
<span class="slider round"></span>
</label>
<p class="ch-text">yotube feed<p>
</div>
<!-- switch for the comments -->
<div>
<label class="switch">
<input id= "input1" type="checkbox">
<span class="slider round"></span>
</label>
<p class="ch-text">comment section<p>
</div>
<link rel="stylesheet" href="style.css">
<script src="background.js"></script>
</body>
</html>

我的 list json:

  {
"name": "Youtube feed Blocker",
"description": "Removing the feed and comments from the youtube to stop wasting time",
"icons": {"128": "icon.png"},
"version": "1.0",
"permissions": [
"tabs", "http://*.youtube.com/*", "https://*.youtube.com/*"
],
"browser_action": {
"default_title": "Removed the recommended videos sections",
"default_popup": "popup.html",
"default_icon": "icon.png",
"persistent": true
},
"content_scripts": [{
"css": ["style.css"],
"matches": ["*://www.youtube.com/", "*://www.youtube.com/watch*", "*://www.youtube.com/*", "*://www.youtube.com/user*"],
"all_frames": true,
"run_at": "document_start"
}],

"manifest_version": 2
}

最佳答案

您可以使用 storage.sync API ,如此处解释:https://developer.chrome.com/extensions/options

虽然还有其他方法,但使用同步 API 会跨设备记住用户的设置。

关于javascript - 如何让我的 chrome 扩展程序记住拨动开关或其他操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55236700/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com