aboutsummaryrefslogtreecommitdiff
path: root/files/fr/mozilla/add-ons/webextensions/api/notifications/create/index.md
diff options
context:
space:
mode:
Diffstat (limited to 'files/fr/mozilla/add-ons/webextensions/api/notifications/create/index.md')
-rw-r--r--files/fr/mozilla/add-ons/webextensions/api/notifications/create/index.md147
1 files changed, 147 insertions, 0 deletions
diff --git a/files/fr/mozilla/add-ons/webextensions/api/notifications/create/index.md b/files/fr/mozilla/add-ons/webextensions/api/notifications/create/index.md
new file mode 100644
index 0000000000..7180da2576
--- /dev/null
+++ b/files/fr/mozilla/add-ons/webextensions/api/notifications/create/index.md
@@ -0,0 +1,147 @@
+---
+title: notifications.create()
+slug: Mozilla/Add-ons/WebExtensions/API/notifications/create
+tags:
+ - API
+ - Add-ons
+ - Create
+ - Extensions
+ - Method
+ - Non-standard
+ - Notifications
+ - Reference
+ - WebExtensions
+translation_of: Mozilla/Add-ons/WebExtensions/API/notifications/create
+---
+<div>{{AddonSidebar()}}</div>
+
+<p>Crée et affiche une notification.</p>
+
+<p>Passez un {{WebExtAPIRef("notifications.NotificationOptions")}} pour définir le contenu et le comportement de la notification.</p>
+
+<p>Vous pouvez éventuellement fournir un ID pour la notification. Si vous omettez l'ID, un ID sera généré. Vous pouvez utiliser l'ID pour {{WebExtAPIRef("notifications.update()", "update")}} ou {{WebExtAPIRef("notifications.clear()", "clear")}} la notification.</p>
+
+<p>C'est une fonction asynchrone qui renvoie une <code><a href="/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise">Promise</a></code>.</p>
+
+<div class="warning">
+<p><strong>Attention :</strong> Si vous appelez <code>notifications.create()</code> plus d'une fois de suite, Firefox peut ne pas afficher de notification pour tout.</p>
+</div>
+
+<h2 id="Syntaxe">Syntaxe</h2>
+
+<pre class="brush: js">var creating = browser.notifications.create(
+ id, // optional string
+ options // NotificationOptions
+)
+</pre>
+
+<h3 id="Paramètres">Paramètres</h3>
+
+<dl>
+ <dt><code>id</code>{{optional_inline}}</dt>
+ <dd><code>string</code>. Ceci est utilisé pour faire référence à cette notification dans {{WebExtAPIRef("notifications.update()")}}, {{WebExtAPIRef("notifications.clear()")}}, et les écouteurs d'événements. Si vous omettez cet argument ou passez une chaîne vide, un nouvel ID sera généré pour cette notification. Si l'ID que vous fournissez correspond à l'ID d'une notification existante provenant de cette extension, l'autre notification sera effacée.</dd>
+ <dt><code>options</code></dt>
+ <dd>{{WebExtAPIRef('notifications.NotificationOptions')}}. Définit le contenu et le comportement de la notification.</dd>
+</dl>
+
+<h3 id="Valeur_retournée">Valeur retournée</h3>
+
+<p>Une <code><a href="/fr/docs/Web/JavaScript/Reference/Objets_globaux/Promise">Promise</a></code> qui sera remplie lorsque la notification est créée et que le processus d'affichage a été démarré, avant que la notification ne s'affiche réellement à l'utilisateur. Il est rempli avec une chaîne représentant l'identifiant de la notification.</p>
+
+<h2 id="Compatibilité_du_navigateur">Compatibilité du navigateur</h2>
+
+<p>{{Compat("webextensions.api.notifications.create")}}</p>
+
+<h2 id="Exemples">Exemples</h2>
+
+<p>Créez et affichez périodiquement une notification de base à l'aide d'un  {{WebExtAPIRef("alarms", "alarm")}}. En cliquant sur l'action du navigateur, la notification est rejetée.</p>
+
+<p>Notez que vous aurez besoin de la <a href="/fr/Add-ons/WebExtensions/manifest.json/permissions">permission</a> "alarms" pour créer des alarmes (ainsi que de la permission "notifications" pour créer des notifications).</p>
+
+<pre class="brush: js">var cakeNotification = "cake-notification"
+
+/*
+
+CAKE_INTERVAL is set to 6 seconds in this example.
+Such a short period is chosen to make the extension's behavior
+more obvious, but this is not recommended in real life.
+Note that in Chrome, alarms cannot be set for less
+than a minute.
+
+*/
+var CAKE_INTERVAL = 0.1;
+
+browser.alarms.create("", {periodInMinutes: CAKE_INTERVAL});
+
+browser.alarms.onAlarm.addListener(function(alarm) {
+ browser.notifications.create(cakeNotification, {
+ "type": "basic",
+ "iconUrl": browser.extension.getURL("icons/cake-96.png"),
+ "title": "Time for cake!",
+ "message": "Something something cake"
+ });
+});
+
+browser.browserAction.onClicked.addListener(()=&gt; {
+ var clearing = browser.notifications.clear(cakeNotification);
+ clearing.then(() =&gt; {
+ console.log("cleared");
+ });
+});</pre>
+
+<p>Affichez une notification similaire, mais ajoutez des boutons nommant des gâteaux et consignez le gâteau sélectionné lorsque vous cliquez sur un bouton :</p>
+
+<pre class="brush: js">var cakeNotification = "cake-notification"
+
+/*
+
+CAKE_INTERVAL is set to 6 seconds in this example.
+Such a short period is chosen to make the extension's behavior
+more obvious, but this is not recommended in real life.
+Note that in Chrome, alarms cannot be set for less
+than a minute.
+
+*/
+var CAKE_INTERVAL = 0.1;
+
+var buttons = [
+ {
+ "title": "Chocolate"
+ }, {
+ "title": "Battenberg"
+ }
+];
+
+browser.alarms.create("", {periodInMinutes: CAKE_INTERVAL});
+
+browser.alarms.onAlarm.addListener(function(alarm) {
+ browser.notifications.create(cakeNotification, {
+ "type": "basic",
+ "iconUrl": browser.extension.getURL("icons/cake-96.png"),
+ "title": "Time for cake!",
+ "message": "Something something cake",
+ "buttons": buttons
+ });
+});
+
+browser.browserAction.onClicked.addListener(()=&gt; {
+ var clearing = browser.notifications.clear(cakeNotification);
+ clearing.then(() =&gt; {
+ console.log("cleared");
+ });
+});
+
+browser.notifications.onButtonClicked.addListener((id, index) =&gt; {
+ browser.notifications.clear(id);
+ console.log("You chose: " + buttons[index].title);
+});
+</pre>
+
+<p>{{WebExtExamples}}</p>
+
+<div class="note"><p><strong>Note :</strong></p>
+
+<p>Cette API est basée sur l'API Chromium <a href="https://developer.chrome.com/extensions/notifications"><code>chrome.notifications</code></a>.</p>
+
+<p>Les données de compatibilité relatives à Microsoft Edge sont fournies par Microsoft Corporation et incluses ici sous la licence Creative Commons Attribution 3.0 pour les États-Unis.</p>
+</div>