アドオンがあり、デスクトップで通知を発行したいのですが、ユーザーがコンピューターをアクティブに使用している場合にのみ (たとえば、マウス ポインターがブラウザー ウィンドウ内だけでなく、どこにでも移動しています)。
WebExtensions を使用してこれを行うことは可能ですか?
私はそれが次のようなものになると信じています:
script.js
function Notify(id, title, message) { var props = { "type": "basic", "title": title, "iconUrl": "images/icon-128px.png", "message": message }; var propsCopy = JSON.parse(JSON.stringify(props)); propsCopy.requireInteraction = true; //Prevent exception in Firefox try { chrome.notifications.create(id, propsCopy, function() {}); } catch (ee) { chrome.notifications.create(id, props, function() {}); } }
background.js
var standByNotifications = []; function registerNotification(id, title, message) { if ([user is inactive]) { standByNotifications.push({ "id": id, "title": title, "message": message }); } else { Notify(id, title, message); } } setInterval(function() { if ([user is inactive] === false) { var tmp = standByNotifications.reverse(); for (var i = tmp.length - 1; i >= 0; i--) { Notify(tmp[i].id, tmp[i].title, tmp[i].message); } standByNotifications = []; //Clear } }, 1000);