💥 Tweak for moments theme

This commit is contained in:
zhbaor 2022-12-31 22:20:24 +08:00
parent 38b0fd865d
commit c49c8a8a91
8 changed files with 45 additions and 172 deletions

View file

@ -36,7 +36,7 @@ const REG_BD_HALF_CLOSE = `”’`
const REG_BD_HALF_START = `${REG_BD_HALF_OPEN}${REG_BD_HALF_CLOSE}`
class Heti {
constructor (rootSelector) {
constructor (rootDocument, rootSelector) {
let supportLookBehind = true
try {
@ -46,6 +46,7 @@ class Heti {
supportLookBehind = false
}
this.rootDocument = rootDocument
this.rootSelector = rootSelector || '.heti'
this.REG_FULL = new RegExp(supportLookBehind ? REG_CJK_FULL : REG_CJK_FULL_WITHOUT_LOOKBEHIND, 'g')
this.REG_START = new RegExp(REG_CJK_START, 'g')
@ -73,8 +74,8 @@ class Heti {
forceContext: this.funcForceContext,
filterElements: this.funcFilterElements,
}
const getWrapper = function (elementName, classList, text) {
const $$r = document.createElement(elementName)
const getWrapper = (elementName, classList, text) => {
const $$r = this.rootDocument.createElement(elementName)
$$r.className = classList
$$r.textContent = text.trim()
return $$r
@ -119,14 +120,18 @@ class Heti {
autoSpacing () {
const callback = () => {
const $$rootList = document.querySelectorAll(this.rootSelector)
const $$rootList = this.rootDocument.querySelectorAll(this.rootSelector)
for (let $$root of $$rootList) {
this.spacingElement($$root)
}
}
if (document.readyState === 'complete') setTimeout(callback)
else document.addEventListener('DOMContentLoaded', callback)
if (this.rootDocument == document) {
if (this.rootDocument.readyState === 'complete') setTimeout(callback)
else this.rootDocument.addEventListener('DOMContentLoaded', callback)
} else {
callback()
}
}
}