мое расширение не работает после загрузки страницы - PullRequest
0 голосов
/ 08 февраля 2020

Я новичок в chrome расширении. Я создал расширение chrome, которое меняет курсор открываемого сайта. При открытии всплывающего окна вы можете выбрать предпочтительный курсор, и курсор сайта меняется вместе с ним. Мой код работает хорошо, но он не работает после загрузки страницы. Есть ли проблема в фоновом режиме. js?

background. js

chrome.runtime.onMessage.addListener(
    function({message, buttonCursor}, sender, sendResponse) {

      if (message === "hello"){
        let CursorColor = buttonCursor;
        chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
            chrome.tabs.sendMessage(tabs[0].id, {message: "showbuttonCursor", Cursor:CursorColor})
            console.log(CursorColor)
          });
      }

    });

content. js

chrome.runtime.onMessage.addListener(
    function({message, Cursor}, sender, sendResponse) {


      if (message === "showbuttonCursor"){
      $('body').css('cursor', `url(${Cursor}), auto`)
      }  
      document.addEventListener('DOMContentLoaded', function () {
        TabControl.listCurrentTabs();
      });
    });

popup. js

$(function() {
   const images = document.querySelectorAll('.image');

   for(let img of images){
       img.addEventListener('click', function(){
         let src= img.src;
         chrome.runtime.sendMessage({message: "hello", buttonCursor: src});
         console.log(src)
       })
   }
});

манифест. json

{
    "name": "Hello Extensions",
    "description" : "Base Level Extension",
    "version": "1.0",
    "icons":{
        "128":"./images/test.png",
        "48":"./images/test.png",
        "16":"./images/test.png"
    },

    "manifest_version": 2,
    "browser_action": {
      "default_icon": "./images/test.png",
      "default_popup": "popup.html"
    },

    "permissions": ["<all_urls>", "activeTab", "tabs", "storage", "http://*/",
      "https://*/"],

    "background": {
        "persistent": false,
        "scripts": ["./scripts/jquery.js", "./scripts/background.js"]
      },

    "content_scripts": [
        {
          "matches": ["<all_urls>"],
          "js": ["./scripts/jquery.js", "./scripts/content.js"]
        }
      ]   
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...