Этот код определяет функцию S (), которая отображает строку с заданным заголовком в окне уведомления, которое остается на экране в течение 3 секунд.Код возвращает Обещание, которое ждет 1/2 секунды, пока на самом деле не появится окно.
Использование: S («строка, которую вы хотите отобразить», «заголовок окна уведомления»). Then (nextFunction);
// Wrap setTimeout in a Promise
function delay(msec,value)
{
return new Promise(function(OKFunction)
{
setTimeout(OKFunction,msec,value);
});
} // delay
// S: Promise to show string in notification box
// with delays before continuing and before clearing the box
function S(Msg,Title)
{
var p=browser.notifications.create({
"type": "basic",
"iconUrl": browser.extension.getURL("icons/link-48.png"), // change this as desired
"title": Title,
"message": Msg});
p.then(S1);
return delay(500); // Wait for notification to appear before continuing
} // S
function S1(ID)
{ delay(3000,ID).then(S2).catch(err); } // S1
function S2(ID)
{ browser.notifications.clear(ID).then(empty).catch(err); } // S2
function empty(valueIgnored)
{
console.log('doing nothing');
} // empty
function err(Msg)
{
console.log('*** '+Msg);
throw Error;
} // err