From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../components/messagepreview/messagepreview.js | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 browser/components/messagepreview/messagepreview.js (limited to 'browser/components/messagepreview/messagepreview.js') diff --git a/browser/components/messagepreview/messagepreview.js b/browser/components/messagepreview/messagepreview.js new file mode 100644 index 0000000000..48e5fb1ff5 --- /dev/null +++ b/browser/components/messagepreview/messagepreview.js @@ -0,0 +1,39 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +/* global MPShowMessage, MPIsEnabled, MPShouldShowHint */ + +"use strict"; + +function decodeMessageFromUrl() { + const url = new URL(document.location.href); + + if (url.searchParams.has("json")) { + const encodedMessage = url.searchParams.get("json"); + + return atob(encodedMessage); + } + return null; +} + +function showHint() { + document.body.classList.add("hint-box"); + document.body.innerHTML = `
Message preview is not enabled. Enable it in about:config by setting browser.newtabpage.activity-stream.asrouter.devtoolsEnabled to true.
`; +} + +const message = decodeMessageFromUrl(); + +if (message) { + // If message preview is enabled, show the message. + if (MPIsEnabled()) { + MPShowMessage(message); + } else if (MPShouldShowHint()) { + // If running in a local build, show a hint about how to enable preview. + if (document.body) { + showHint(); + } else { + document.addEventListener("DOMContentLoaded", showHint, { once: true }); + } + } +} -- cgit v1.2.3