57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
/**
|
|
* @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 };
|
|
}
|
|
};
|
|
}
|