简体   繁体   English

我有一些简单的 JavaScript 代码,我想把它变成一个弹出扩展。 我该怎么做呢?

[英]I have some simple JavaScript code, and I want to turn it into a popup extension. How do I do this?

I tried creating a manifest that leads to a popup.js file and put the following code in that file but the popup showed up as just a white square.我尝试创建一个指向 popup.js 文件的清单,并将以下代码放入该文件中,但弹出窗口仅显示为一个白色方块。

This is My JavaScript code这是我的 JavaScript 代码

fill(0, 0, 0);
ellipse(200, 200, 375, 375);
fill(60, 0, 255);
triangle(200, 104, 280, 280, 120, 280);
fill(255, 255, 255);
var answer = floor(random(1, 20));

if (answer === 1) {
    text("As I see it,", 171, 200);
    text("yes", 189, 229); 
}
else if (answer === 2) {
    text("Ask again", 171, 200);
    text("later", 189, 229); 

...

else {
    text("You may", 175, 200);
    text("rely on it", 177, 229); 
}

This is my manifest (most likely needs some editing)这是我的清单(很可能需要一些编辑)

{
  "manifest_version": 2,
  "name": "8 ball popup",
  "version": "0.1",
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "js": ["content.js"]
    }
  ],
  "browser_action": {
    "default_popup": "popup.html",
    "default_title": "Your fortune will appear here."
  }
}

Posting your manifest would help.发布您的清单会有所帮助。

However, I recommend you checking the browerAction docs .但是,我建议您查看browerAction 文档

Basically you also need to create an HTML page, and link your js file to it.基本上你还需要创建一个 HTML 页面,并将你的 js 文件链接到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM