代码之家  ›  专栏  ›  技术社区  ›  Hamdi Alp

带有dom元素的chrome扩展更新徽章

  •  0
  • Hamdi Alp  · 技术社区  · 6 年前

    所以你只需要数一数页面上的标签,并将其显示在徽章上

    所容纳之物js

    document.body.addEventListener('DOMContentLoaded', e => {
    var a=document.getElementsByTagName('a').length;
    
        chrome.runtime.sendMessage(a)
    
    });
    

    出身背景js

    chrome.runtime.onMessage.addListener(message => {
    var b=message
    chrome.browserAction.setBadgeText({"text":b.toString()})
    
    });
    

    显示json

    {
    "manifest_version": 2,
    "name": "The Chrome Link Counter",
    "version": "1.0",
    "description": "counter",
    "icons": {
        "48": "icons/icon_default.png"
    },
    "content_scripts": [
        {
            "matches": ["<all_urls>"],
            "all_frames": true,
            "js": ["content/main.js"]
        }
    ],
    "background": {
        "scripts": ["background/main.js"]
    },
    "options_ui": {
        "page": "options/main.html",
        "chrome_style": true
    },
    "browser_action": {
        "default_popup": "options/main.html",
        "chrome_style": true,
        "default_icon": {
            "16": "icons/icon_default.png"
        }
    },
    "web_accessible_resources": ["icons/icon.png", "icons/check.png"],
    "permissions": ["storage", "webRequest","tabs"]
    
    }
    

    但当我尝试我错过的东西时什么都没发生?

    编辑:添加清单。json也是如此

    0 回复  |  直到 6 年前