【问题标题】:How can I modify an extensions badge in jQuery?如何在 jQuery 中修改扩展徽章?
【发布时间】:2019-10-28 02:13:47
【问题描述】:

我可以使用 jQuery 来添加 Removed += 1 就像它在顶部函数中使用的一样吗?如果属性被删除,我可以让它只加1吗?

window.onload = function() {

    let Removed = 0
    const anchorElements = document.getElementsByTagName('A')

    for (element of anchorElements) {
        if (!element.getAttribute('ping')) continue
            console.log("Removed ping: " + element.getAttribute('ping'))
                element.removeAttribute('ping')
                Removed += 1
                chrome.extension.sendMessage(Removed)
    }
}

link();

function link(){

    jQuery("a[onclick*='ga']").removeAttr('onclick');
    jQuery("a[onclick*='_gaq.push']").removeAttr('onclick');
    jQuery("link[rel*='pingback']").removeAttr('rel');

}

【问题讨论】:

  • 不清楚你在问什么,因为我们不知道这段代码在哪里运行,也不知道你想让你的 jQuery 在哪里运行。

标签: google-chrome google-chrome-extension firefox-addon firefox-addon-webextensions browser-extension


【解决方案1】:

请注意,扩展程序使用专用 API browserAction.setBadgeText() 与特权脚本(而非内容脚本)的扩展程序徽章进行交互。

JQuery 在您的内容中使用,无权访问上述 API。

您可以使用runtime.sendMessage() 将请求传递给后台脚本。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多