在Chrome扩展程序中使用NOTY JS通知库

时间:2019-12-10 02:26:42

标签: javascript google-chrome google-chrome-extension noty

我正在尝试在Chrome扩展程序中使用通知库Noty。

它说您可以通过以下方式安装:

<link href="lib/noty.css" rel="stylesheet">
<script src="lib/noty.js" type="text/javascript"></script>

我尝试将其添加到内容脚本.html中,但是,在.js页面中调用新通知失败。

{
  "name": "--",
  "version": "1.0",
  "description": "--",
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": ["-removed-"],
      "js": ["popup.js"]           **where I am trying to fire off a notification**
    }
  ],
  "manifest_version": 2,
  "browser_action": {
    "default_popup": "popup.html"  **where I added the script and link**
  },
  "permissions": [
    "storage",
    "notifications"
  ]
}

我已经阅读了一些不同的主题,但并不了解整个过程。这是一个完全的禁忌,还是这样做相当合理?我只需要能够在popup.js文件中调用通知即可。

1 个答案:

答案 0 :(得分:0)

由于您的问题不正确,因此我假设您在安装Noty.js时遇到困难,以作答。因此,为此,您首先需要使用npm(npm install noty)或yarn或bower下载noty.js文件,然后必须将.js和.css文件复制到目录中,然后需要通过脚本和样式进行添加标签。之后,您将可以调用Noty();。     如果我的回答不正确并且我弄错了,请清除我的内容,并随时询问您是否有任何问题。