0

我想在桌面上堆叠 chrome 通知。我的项目是chrome-extension,我想添加通知。

背景.js

let data = [{ name: 'hi', content: 'aaa' }, { name: 'hi2', content: 
'aaa2' }];

function init() {
  if (!localStorage.isInitialized) {
    localStorage.isActivated = true; // The display activation.
    localStorage.frequency = 1; // The display frequency, in 
       minutes.
    localStorage.isInitialized = true; // The option 
initialization.
  }
  // Test for notification support.
  if (window.Notification) {
    // While activated, show notifications at the display frequency.
     if (JSON.parse(localStorage.isActivated)) {
  show();
}
var interval = 0; // The display interval, in minutes.
setInterval(function() {
  interval++;
  if (
    JSON.parse(localStorage.isActivated) &&
    localStorage.frequency <= interval
  ) {
    data.forEach(v => show(v));
    interval = 0;
      }
    }, 1000);
  }
 }

init();

function show(data) {
  new Notification(data.name, {
    icon: '25.png',
    body: data.content
      });
    }

清单.json

 {
   "name": "ttt",
   "version": "1.0",
   "manifest_version": 2,
   "description": "TEST",
   "background": {
     "scripts": [
       "background.js"
     ]
   },
    "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
   "permissions": [
     "activeTab",
     "<all_urls>",
     "tabs",
     "cookies",
     "notifications"
   ]
 }

data.forEach(v => show(v)); 我想堆叠通知。但通知适用于数组内容的最后一个索引。只有一个。请帮我

4

0 回答 0