我是扩展大厦的新手。只是尝试构建一个扩展程序,该扩展程序将一直计数单击按钮的次数并在弹出窗口中显示该数字。感谢帮助。
manifest.json
{
"manifest_version": 2,
"name": "Audit counts",
"description": "Check your productivity",
"version": "1.0.0",
"icons": {
"128": "icon-128.png"
},
"permissions": [
"storage",
"activeTab"
],
"browser_action": {
"default_icon": "icon-128.png",
"default_title": "know your counts",
"default_popup": "popup.html"
},
"background": {
"scripts": [
"background.js"
],
"persistent": false
},
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": [
"content.js"
]
}
]
}
popup.html
<!DOCTYPE html>
<html>
<head>
<title>Audit counts</title>
<script src="popup.js"></script>
<script src="jquery-3.4.1.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body id="popup_body">
<h4 id="greet">Audit counts</h4>
<h2 id="counts">00</h2>
<button id="show">Show counts</button>
<button id="reset">Reset</button>
</body>
</html>
content.js
var button = document.getElementById("nav-logobar-greeting");
button.addEventListener("click", function () {
chrome.runtime.sendMessage("Hello, World");
}, false);
popup.js
chrome.runtime.onMessage.addListener(function (response, sender, sendResponse) {
alert("running");
$(document).ready(function () {
$("#counts").text(response);
});
});
我希望“ Hello,World”在弹出窗口中替换为“ 00”。