2 * Prompts the user for their consent before displaying external media.
4 * @author Alexander Ebert
5 * @copyright 2001-2020 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/Ui/Message/UserConsent
10 import * as Ajax from "../../Ajax";
11 import * as Core from "../../Core";
12 import DomChangeListener from "../../Dom/Change/Listener";
13 import DomUtil from "../../Dom/Util";
14 import User from "../../User";
17 private enableAll = false;
18 private readonly knownButtons = new WeakSet();
21 if (window.sessionStorage.getItem(`${Core.getStoragePrefix()}user-consent`) === "all") {
22 this.enableAll = true;
25 this.registerEventListeners();
27 DomChangeListener.add("WoltLabSuite/Core/Ui/Message/UserConsent", () => this.registerEventListeners());
30 private registerEventListeners(): void {
32 this.enableAllExternalMedia();
34 document.querySelectorAll(".jsButtonMessageUserConsentEnable").forEach((button: HTMLAnchorElement) => {
35 if (!this.knownButtons.has(button)) {
36 this.knownButtons.add(button);
38 button.addEventListener("click", (ev) => this.click(ev));
44 private click(event: MouseEvent): void {
45 event.preventDefault();
47 this.enableAll = true;
49 this.enableAllExternalMedia();
54 actionName: "saveUserConsent",
55 className: "wcf\\data\\user\\UserAction",
60 window.sessionStorage.setItem(`${Core.getStoragePrefix()}user-consent`, "all");
64 private enableExternalMedia(container: HTMLElement): void {
65 const payload = atob(container.dataset.payload!);
67 DomUtil.insertHtml(payload, container, "before");
71 private enableAllExternalMedia(): void {
72 document.querySelectorAll(".messageUserConsent").forEach((el: HTMLElement) => this.enableExternalMedia(el));
76 let userConsent: UserConsent;
78 export function init(): void {
80 userConsent = new UserConsent();