簡體   English   中英

我有一些簡單的 JavaScript 代碼,我想把它變成一個彈出擴展。 我該怎么做呢?

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

我嘗試創建一個指向 popup.js 文件的清單,並將以下代碼放入該文件中,但彈出窗口僅顯示為一個白色方塊。

這是我的 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); 
}

這是我的清單(很可能需要一些編輯)

{
  "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."
  }
}

發布您的清單會有所幫助。

但是,我建議您查看browerAction 文檔

基本上你還需要創建一個 HTML 頁面,並將你的 js 文件鏈接到它。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM