微件:SaltInPageCSSLoader:修订间差异

删除170字节 、​ 2021年1月10日 (星期日)
无编辑摘要
(// Edit via Wikiplus)
无编辑摘要
第16行: 第16行:
这个页面的标题(<h1>)变成了蓝字蓝底。
这个页面的标题(<h1>)变成了蓝字蓝底。
</noinclude><includeonly><style defer>
</noinclude><includeonly><style defer>
(/**
/**
* 搬运须知: 您必须在**显眼处**标识来源“MCBBS Wiki”与作者“Salt_lovely”, **不**接受任何形式的简称或不署名。
* 搬运须知: 您必须在**显眼处**标识来源“MCBBS Wiki”与作者“Salt_lovely”, **不**接受任何形式的简称或不署名。
*
* Notice: You have to mark origin "MCBBS Wiki" and author "Salt_lovely" in CONSPICUOS PLACE, abbreviation or omissions are NOT allowed.
* Notice: You have to mark origin "MCBBS Wiki" and author "Salt_lovely" in CONSPICUOS PLACE, abbreviation or omissions are NOT allowed.
*
* 许可证: CC BY-NC-SA 4.0
* 许可证: CC BY-NC-SA 4.0
*
* License: CC BY-NC-SA 4.0
* License: CC BY-NC-SA 4.0
*/
*/
    function () {
(function () {
        let ps = pageState() // 获取页面状态
    let ps = pageState() // 获取页面状态
        let elems = HTMLElemsFliter(Array.from(document.querySelectorAll('.salt.InPageCSSLoader')))
    let elems = HTMLElemsFliter(Array.from(document.querySelectorAll('.salt.InPageCSSLoader')))
        for (let el of elems) {
    if (elems.length < 1) { return } else { console.log('[SaltInPageCSSLoader]检测到页内CSS, 共计' + elems.length + '个') }
            // 去除标记
    for (let el of elems) {
            el.classList.remove('InPageCSSLoader')
        // 去除标记
            // 内容简单处理
        el.classList.remove('InPageCSSLoader')
            let text = (el.textContent || '').replace(/^\n+|\n+$/gm, '') // 去除首尾的空行
        // 内容简单处理
            el.textContent = text
        let text = (el.textContent || '').replace(/^\n+|\n+$/gm, '') // 去除首尾的空行
            let handler = () => {
        el.textContent = text
                // 处理这个元素
        let handler = () => {
                el.style.display = 'none'
            // 处理这个元素
                // 开始主要内容部分
            el.style.display = 'none'
                // 简单的查错
            // 开始主要内容部分
                if (text.length < 3 || text.indexOf('{') == -1 || text.indexOf('}') == -1) {
            // 简单的查错
                    highlightEl(el, '检测到不可用的CSS')
            if (text.length < 3 || text.indexOf('{') == -1 || text.indexOf('}') == -1) {
                    console.log('[SaltInPageCSSLoader]检测到不可用的CSS:' + text)
                highlightEl(el, '检测到不可用的CSS')
                    return
                console.log('[SaltInPageCSSLoader]检测到不可用的CSS:' + text)
                }
                return
                // 写入style
                let style = document.createElement('style')
                style.textContent = text
                // 搬运id
                if (el.hasAttribute('id')) {
                    style.setAttribute('id', el.getAttribute('id'))
                    el.removeAttribute('id')
                }
                document.head.appendChild(style)
             }
             }
             if (ps == 0) {
             // 写入style
                handler()
            let style = document.createElement('style')
             } else { // 页面编写者模式
            style.textContent = text
                 highlightEl(el, '点击应用CSS(页面编写完毕后CSS将默认启用)')
             // 搬运id
                 el.addEventListener('click', handler)
            if (el.hasAttribute('id')) {
                 style.setAttribute('id', el.getAttribute('id'))
                 el.removeAttribute('id')
             }
             }
             el.style.whiteSpace = 'pre'
             document.head.appendChild(style)
         }
         }
         /**滤出数组中所有HTMLElement */
         if (ps == 0) {
        function HTMLElemsFliter(els) {
             handler()
             let hel = []
        } else { // 页面编写者模式
             for (let el of els)
             highlightEl(el, '点击应用CSS(页面编写完毕后CSS将默认启用)')
                if (el instanceof HTMLElement)
            el.addEventListener('click', handler)
                    hel.push(el)
            return hel
         }
         }
         /** 0 - 默认, 浏览页面
         el.style.whiteSpace = 'pre'
        *  
    }
        *  1 - 编辑/预览页面 */
    /**滤出数组中所有HTMLElement */
        function pageState() {
    function HTMLElemsFliter(els) {
            if (mw && mw.config && typeof mw.config.get == 'function') {
        let hel = []
                switch (mw.config.get('wgAction')) {
        for (let el of els)
                    case 'view':
            if (el instanceof HTMLElement)
                        return 0
                hel.push(el)
                    case 'edit':
        return hel
                    case 'submit':
    }
                        return 1
    /** 0 - 默认, 浏览页面
                    default:
    *  
                        return 0
    *  1 - 编辑/预览页面 */
                }
    function pageState() {
            } else {
        if (mw && mw.config && typeof mw.config.get == 'function') {
                return 0
            switch (mw.config.get('wgAction')) {
                case 'view':
                    return 0
                case 'edit':
                case 'submit':
                    return 1
                default:
                    return 0
             }
             }
        } else {
            return 0
         }
         }
        /**高亮一个元素 */
        function highlightEl(el, title = '') {
            el.style.display = 'block'
            el.style.fontSize = '1rem'
            el.style.color = 'crimson'
            el.style.border = '1px solid crimson'
            el.style.paddingLeft = '.5rem'
            el.title = title
        }
     }
     }
)()
    /**高亮一个元素 */
    function highlightEl(el, title = '') {
        el.style.display = 'block'
        el.style.fontSize = '1rem'
        el.style.color = 'crimson'
        el.style.border = '1px solid crimson'
        el.style.paddingLeft = '.5rem'
        el.title = title
    }
})()
</style></includeonly>
</style></includeonly>