我正在尝试创建一个Chrome扩展程序,该扩展程序根据您所在的网站显示特定的代码/文本。举例来说,假设您在www.facebook.com上,则代码“ hello”,“ bye”和“ what”将显示,然后假设我们转到www.youtube.com,然后将出现不同的代码取决于我的JSON文件中的内容。
到目前为止,我还不知道如何实现此目标,因此我仅设法使扩展程序在我希望其运行的网站上工作。我相信这就是解决问题的方法。我还创建了一个“框”,将保存此代码/文本Box
我的清单代码: `{ “ manifest_version”:2 “ name”:“ Chahching”, “ version”:“ 1.0”,
"page_action": {
"default_icon": {
"16": "images/icon16.png",
"24": "images/icon24.png",
"32": "images/icon32.png"
},
"default_popup": "popup.html",
"default_title": "Chaching"
},
"background": {
"scripts": ["eventPage.js"],
"persistent": false
},
"content_scripts": [
{
"matches": ["https://www.g2a.com/*", "https://www.kinguin.net/*"],
"js": ["content.js", "jquery.js"]
}
],
"permissions": [
"tabs",
"https://www.g2a.com/*",
"https://www.kinguin.net/*"
]
HTML代码:
<html lang="en">
<head>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<header>
</header>
<section>
<div class="couponbg">
<div class="couponinfo">
<div id="unique-code">BRG</div>
<div id="description"></div>
</div>
</div>
</section>
</body>
</html>
JSON:
{
"www.g2a.com": [
{
"codes": ["BRG", "makehoney", "test1", "test2"],
"deals": ["https://www.g2a.com/best-deals/weeklysale?banner=main"]
}
]
}