summaryrefslogtreecommitdiffstats
path: root/docusaurus/static/ajax/libs/wolfree/23.7.8/js/Pods.js
blob: 7b31e48b29ff3cba5aa8a26f66ab49bfa3e29a47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
 * @license
 * SPDX-License-Identifier: AGPL-3.0-or-later
 * This file is part of Wolfree.
 * This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 */

// @ts-check

export default class Pods {
  insert = ({
    container = document.querySelector("main > div:nth-of-type(1)"),
    html = String(),
  } = {}) => {
    try {
      /**
       * https://www.npmjs.com/package/@types/dompurify
       * @type {import('DOMPurify')}
       */
      return (
        container instanceof HTMLDivElement
          ? container.insertAdjacentHTML(
              "afterend",
              globalThis.DOMPurify.sanitize(html)
            )
          : console.error({ container }),
        { container, html }
      );
    } catch (error) {
      return (
        console.error(
          { error },
          "Fail to insert the results of the calculation."
        ),
        { error }
      );
    }
  };

  remove = ({
    pods = document.querySelectorAll("main > div.wolfree-pods"),
  } = {}) => {
    try {
      pods.forEach((element) => {
        element.remove();
      });
      return { pods };
    } catch (error) {
      console.error(
        "Fail to remove the results of the previous calculation.",
        error
      );
      return { error };
    }
  };
}