1class ScriptLifisherCopyright extends Script { 2 constructor(params) { 3 super(params) 4 this.$dom = document.querySelector(`#${this.attrId}`) 5 this.$template = document.querySelector(`#${this.attrId} template`) 6 this.expandContent = JSON.parse(this.utilts.htmlDecode(params.expandContent || '[]')) 7 this.utils = Utilts.ins() 8 } 9 10 /** åå§åï¼æ¯æå¼æ¥ */ 11 init() { 12 const unit = this.$dom 13 const utils = this.utils 14 const that = this 15 unit.setAttribute('data-lifisher-copyright', 'true') 16 if (utils.checkDesign()) { 17 const designInitCopyRight = function () { 18 setTimeout(function () { 19 const mceContainer = that.$dom.querySelector('[tinymce]') 20 const mceId = mceContainer ? mceContainer.getAttribute('id') : '' 21 if (mceId) { 22 const editor = tinymce.get(mceId) 23 editor.on('SetContent', function () { 24 that.render() 25 }) 26 that.render() 27 } 28 }, 500) 29 } 30 window.addEventListener('designAfterInitTinyMce', function () { 31 designInitCopyRight() 32 }, {once: true}) 33 window.addEventListener('appInitEnd', function () { 34 designInitCopyRight() 35 }) 36 } else { 37 that.render() 38 } 39 } 40 41 render() { 42 this.renderLifisherCopyright() 43 } 44 45 renderIconColor() { 46 const unit = this.$dom 47 const unitStyle = getComputedStyle(unit) 48 const unitItemStyle = getComputedStyle(unit.querySelector('.unit-text__item')) 49 const configColor = unitStyle.getPropertyValue('--lifisher-copyright-color').toLowerCase() 50 const defaultCopyrightColor = unitItemStyle.getPropertyValue('color') 51 const DEFAULT_OPACITY = '.6'; 52 const fetchRgbColor = function () { 53 let rgb = '' 54 if (/rgba?[(](.*)[)]$/.test(defaultCopyrightColor)) { 55 const matches = /rgba?[(](.*)[)]$/.exec(defaultCopyrightColor) 56 const rgba = matches && matches[1] 57 const arr = rgba.split(',') 58 if (arr.length === 4) { 59 arr[3] = DEFAULT_OPACITY 60 } else if (arr.length === 3) { 61 arr.push(DEFAULT_OPACITY) 62 } 63 rgb = arr.join(',') 64 } else if (/^#/.test(defaultCopyrightColor)) { 65 const hex = defaultCopyrightColor.replace('#', '') 66 if (hex.length === 6) { 67 rgb = parseInt('0x' + hex.slice(0, 2)).toString() + ',' 68 + parseInt('0x' + hex.slice(2, 4)).toString() + ',' 69 + parseInt('0x' + hex.slice(4, 5)).toString() 70 } else if (hex.length === 3) { 71 rgb = parseInt('0x' + hex[0] + hex[0]).toString() + ',' 72 + parseInt('0x' + hex[1] + hex[1]).toString() + ',' 73 + parseInt('0x' + hex[2] + hex[2]).toString() 74 } 75 rgb += ',' + DEFAULT_OPACITY 76 } 77 if (rgb) { 78 const color = 'rgba(' + rgb + ')' 79 unit.style.setProperty('--lifisher-copyright-color', color) 80 return 'rgba(' + rgb + ')' 81 } 82 return '' 83 } 84 return /^(rgb|#)/i.test(configColor) ? configColor : fetchRgbColor() || defaultCopyrightColor 85 } 86 87 renderShawRoot(){ 88 const SHADOW_CLASSNAME = 'lifisher-copyright-shadow' 89 const SHADOW_SELECTOR = '.' + SHADOW_CLASSNAME 90 const unit = this.$dom 91 const unitStyle = getComputedStyle(unit) 92 const configFontSize = unitStyle.getPropertyValue('--lifisher-copyright-font-size').toLowerCase() 93 const shadowElem = unit.querySelector(SHADOW_SELECTOR) 94 if (!shadowElem) { 95 const shadow = document.createElement('span') 96 shadow.classList.add(SHADOW_CLASSNAME) 97 shadow.style.display = 'inline-flex' 98 shadow.style.setProperty('min-height', '1.5em') 99 shadow.style.setProperty('text-transform', 'capitalize') 100 if (!configFontSize) shadow.style.setProperty('--lifisher-copyright-font-size', '1em') 101 const links = unit.querySelectorAll('.unit-text a') 102 const sitemap = Array.from(links).find(function (link) { 103 return /sitemap/i.test(link.getAttribute('href')) 104 }) 105 // æé¡ºåºæ£æ¥æ¾ç½®ä½ç½® sitemap, .unit-text__item > [tinymce] > div, .unit-text__item > [tinymce] 106 if (sitemap) { 107 sitemap.insertAdjacentElement('beforebegin', shadow) 108 } else { 109 let wrap = unit.querySelector('.unit-text__item [tinymce]') || unit.querySelector('.unit-text__item') 110 if (!wrap) { 111 wrap = unit 112 } else if (wrap.firstElementChild) { 113 wrap = wrap.firstElementChild 114 } 115 wrap.insertAdjacentElement('beforeend', shadow) 116 } 117 } 118 } 119 120 renderLifisherCopyright() { 121 const SHADOW_CLASSNAME = 'lifisher-copyright-shadow' 122 const SHADOW_SELECTOR = '.' + SHADOW_CLASSNAME 123 const elem = this.$dom.querySelector(SHADOW_SELECTOR) 124 if (elem && elem.shadowRoot) { 125 return 126 } else if (elem) {
127 this.$dom.querySelectorAll(SHADOW_SELECTOR).forEach(function (node, i) { 128 node.remove() 129 }) 130 } 131 this.renderShawRoot() 132 const shadowElem = this.$dom.querySelector(SHADOW_SELECTOR) 133 if (shadowElem) { 134 const shadowRoot = shadowElem.shadowRoot ? shadowElem.shadowRoot : shadowElem.attachShadow({mode: 'open'}) 135 const div = document.createElement('div') 136 div.innerHTML = this.$template.innerHTML 137 const contentList = this.expandContent 138 if (div.querySelector('.lifisher-copyright')) { 139 contentList.push({ 140 class: 'lifisher-copyright', 141 icon: '1', 142 order: '1' 143 }) 144 } 145 contentList.forEach(item => { 146 const atag = div.querySelector(`.${item.class}__link`) 147 148 const href = atag?.getAttribute('href') ? atag.getAttribute('href').trim() : '' 149 if (atag && !href) { 150 // remove <a> 151 div.querySelector(`.${item.class}`).innerHTML = atag.innerHTML 152 } 153 const style = div.querySelector(`.${item.class}`).style 154 if (item.icon) { 155 const color = this.renderIconColor() 156 style.setProperty('color', color) 157 style.setProperty(`--${item.class}-color`, color) 158 } 159 style.setProperty('display', 'inline-flex') 160 style.setProperty('align-items', 'center') 161 style.setProperty('order', item.order) 162 style.setProperty('margin-left', '0.6ch') 163 }) 164 shadowRoot.append.apply(shadowRoot, div.children) 165 } 166 } 167}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.