Backed out changeset aa5fc411278d (bug 1876522) for causing failures on browser_tab_t...
[gecko.git] / browser / components / messagepreview / messagepreview.js
blob48e5fb1ff571f70993d944d44f4c8f5767ca3a58
1 /* This Source Code Form is subject to the terms of the Mozilla Public
2  * License, v. 2.0. If a copy of the MPL was not distributed with this
3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 /* global MPShowMessage, MPIsEnabled, MPShouldShowHint */
7 "use strict";
9 function decodeMessageFromUrl() {
10   const url = new URL(document.location.href);
12   if (url.searchParams.has("json")) {
13     const encodedMessage = url.searchParams.get("json");
15     return atob(encodedMessage);
16   }
17   return null;
20 function showHint() {
21   document.body.classList.add("hint-box");
22   document.body.innerHTML = `<div class="hint">Message preview is not enabled. Enable it in about:config by setting <code>browser.newtabpage.activity-stream.asrouter.devtoolsEnabled</code> to true.</div>`;
25 const message = decodeMessageFromUrl();
27 if (message) {
28   // If message preview is enabled, show the message.
29   if (MPIsEnabled()) {
30     MPShowMessage(message);
31   } else if (MPShouldShowHint()) {
32     // If running in a local build, show a hint about how to enable preview.
33     if (document.body) {
34       showHint();
35     } else {
36       document.addEventListener("DOMContentLoaded", showHint, { once: true });
37     }
38   }