/* eslint-disable no-console, @typescript-eslint/no-explicit-any */ declare let remark_config: CommentsConfig; import { BASE_URL, NODE_ID, COMMENT_NODE_CLASSNAME_PREFIX } from '@app/common/constants.config'; import { UserInfo, Theme } from '@app/common/types'; import { CommentsConfig } from '@app/common/config-types'; const HOST = remark_config.host || BASE_URL; if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } function removeDomNode(node: HTMLElement | null) { if (node && node.parentNode) { node.parentNode.removeChild(node); } } function init(): void { const node = document.getElementById(remark_config.node || NODE_ID); if (!node) { console.error("Remark42: Can't find root node."); return; } try { remark_config = remark_config || {}; } catch (e) { console.error('Remark42: Config object is undefined.'); return; } if (!remark_config.site_id) { console.error('Remark42: Site ID is undefined.'); return; } remark_config.url = (remark_config.url || window.location.origin + window.location.pathname).split('#')[0]; (window as any).REMARK42 = (window as any).REMARK42 || {}; (window as any).REMARK42.changeTheme = changeTheme; const query = Object.keys(remark_config) .map((key: any) => `${encodeURIComponent(key)}=${encodeURIComponent((remark_config as any)[key])}`) .join('&'); node.innerHTML = ` `; const iframe = node.getElementsByTagName('iframe')[0]; window.addEventListener('message', receiveMessages); window.addEventListener('hashchange', postHashToIframe); document.addEventListener('click', postClickOutsideToIframe); const titleElement = document.querySelector('title'); if (titleElement) { new MutationObserver(mutations => postTitleToIframe(mutations[0].target.textContent!)).observe(titleElement, { subtree: true, characterData: true, childList: true, }); } const remarkRootId = 'remark-km423lmfdslkm34'; const userInfo: { node: HTMLElement | null; back: HTMLElement | null; closeEl: HTMLElement | null; iframe: HTMLIFrameElement | null; style: HTMLStyleElement | null; init: (user: UserInfo) => void; close: () => void; delay: number | null; events: string[]; onAnimationClose: () => void; onKeyDown: (e: KeyboardEvent) => void; animationStop: () => void; remove: () => void; } = { node: null, back: null, closeEl: null, iframe: null, style: null, init(user) { this.animationStop(); if (!this.style) { this.style = document.createElement('style'); this.style.setAttribute('rel', 'stylesheet'); this.style.setAttribute('type', 'text/css'); this.style.innerHTML = ` #${remarkRootId}-node { position: fixed; top: 0; right: 0; bottom: 0; width: 400px; transition: transform 0.4s ease-out; max-width: 100%; transform: translate(400px, 0); } #${remarkRootId}-node[data-animation] { transform: translate(0, 0); } #${remarkRootId}-back { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0,0,0,0.7); opacity: 0; transition: opacity 0.4s ease-out; } #${remarkRootId}-back[data-animation] { opacity: 1; } #${remarkRootId}-close { top: 0px; right: 400px; position: absolute; text-align: center; font-size: 25px; cursor: pointer; color: white; border-color: transparent; border-width: 0; padding: 0; margin-right: 4px; background-color: transparent; } @media all and (max-width: 430px) { #${remarkRootId}-close { right: 0px; font-size: 20px; color: black; } } `; } if (!this.node) { this.node = document.createElement('div'); this.node.id = remarkRootId + '-node'; } if (!this.back) { this.back = document.createElement('div'); this.back.id = remarkRootId + '-back'; this.back.onclick = () => this.close(); } if (!this.closeEl) { this.closeEl = document.createElement('button'); this.closeEl.id = remarkRootId + '-close'; this.closeEl.innerHTML = '✖'; this.closeEl.onclick = () => this.close(); } const queryUserInfo = query + '&page=user-info&' + `&id=${user.id}&name=${user.name}&picture=${user.picture || ''}&isDefaultPicture=${user.isDefaultPicture || 0}`; this.node.innerHTML = `