Ekstensi chrome saya tidak ingat sakelar sakelar. Saya mencoba membuat ekstensi yang memblokir umpan dan komentar youtube ketika sakelar sakelar aktif. Saya mencoba melakukannya untuk bagian komentar tetapi tidak berhasil.

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>

Json manifes saya:

  {
  "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
}
1
Vello 19 Maret 2019, 11:44

1 menjawab

Jawaban Terbaik

Anda dapat menggunakan storage.sync API, seperti yang dijelaskan di sini: https://developer.chrome.com/extensions/options

Meskipun ada metode lain, menggunakan API sinkronisasi akan mengingat setelan pengguna di seluruh perangkat.

1
julifos 19 Maret 2019, 09:47