MCBBS Wiki欢迎您共同参与编辑!在参与编辑之前请先阅读Wiki方针

如果在编辑的过程中遇到了什么问题,可以去讨论板提问。

为了您能够无阻碍地参与编辑 未验证/绑定过邮箱的用户,请尽快绑定/验证

MCBBS Wiki GitHub群组已上线!

您可以在回声洞中发表吐槽!

服务器状态监控。点击进入

本站由MCBBS用户自行搭建,与MCBBS及东银河系漫游指南(北京)科技有限公司没有从属关系。点此了解 MCBBS Wiki 不是什么>>

MediaWiki:Gadget-VectorLeftPanel.js

来自MCBBS Wiki
Litwak913留言 | 贡献2022年12月31日 (六) 21:37的版本 (// Edit via Wikiplus)
跳到导航 跳到搜索

注意:在发布之后,您可能需要清除浏览器缓存才能看到所作出的变更的影响。

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer或Edge:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:Ctrl-F5
"use strict";
/*
搬运须知: 您必须在**显眼处**标识来源“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.
许可证: CC BY-NC-SA 4.0
License: CC BY-NC-SA 4.0
*/
console.log('Start leftpanel');
(function () {
    // 主过程
    function main() {
        var panel = document.getElementById('mw-panel');
        if (!panel /*|| !(panel instanceof HTMLElement)*/) {
                return;
            }
        var portals = HTMLElementFliter(Array.from(panel.getElementsByClassName('portal')));
        // let screenHeight = document.documentElement.clientHeight, panelHeight = panel.offsetHeight
        /**左侧栏是不是比屏幕高度还要高了 */
        //let overHeight = document.documentElement.clientHeight < panel.offsetHeight + 36;
        /**是的话默认闭合,不是的话默认打开 */
        var defaultClass = 'salt-open'; // overHeight ? 'salt-close' : 'salt-open';
        var _iteratorNormalCompletion = true;
        var _didIteratorError = false;
        var _iteratorError = undefined;

        try {
            var _loop = function _loop() {
                var portal = _step.value;

                var h3 = portal.querySelector('h3,.vector-menu-heading');
                var body = portal.querySelector('.vector-menu-content');
                if (!h3 || !(h3 instanceof HTMLElement) || !body || !(body instanceof HTMLElement)) return 'continue'; // 没有的话就算了
                if (h3.textContent == '导航') return 'continue'; // 这个'导航'的h3是没不显示的
                var openHeight = body.offsetHeight; //, closeHeight = h3.offsetTop + h3.offsetHeight
                portal.style.setProperty('--salt-open-height', openHeight + 'px');
                // portal.style.setProperty('--salt-close-height', closeHeight + 'px')
                portal.classList.add(defaultClass);
                h3.addEventListener('click', function () {
                    portal.toggleClass('salt-open');
                    portal.toggleClass('salt-close');
                });
            };

            for (var _iterator = portals[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
                var _ret = _loop();

                if (_ret === 'continue') continue;
            }
        } catch (err) {
            _didIteratorError = true;
            _iteratorError = err;
        } finally {
            try {
                if (!_iteratorNormalCompletion && _iterator.return) {
                    _iterator.return();
                }
            } finally {
                if (_didIteratorError) {
                    throw _iteratorError;
                }
            }
        }
        panel.classList.add('leftpanel-started');
    }
    function HTMLElementFliter(el) {
        var hel = [];
        var _iteratorNormalCompletion2 = true;
        var _didIteratorError2 = false;
        var _iteratorError2 = undefined;

        try {
            for (var _iterator2 = el[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
                var e = _step2.value;

                if (e instanceof HTMLElement) hel.push(e);
            }
        } catch (err) {
            _didIteratorError2 = true;
            _iteratorError2 = err;
        } finally {
            try {
                if (!_iteratorNormalCompletion2 && _iterator2.return) {
                    _iterator2.return();
                }
            } finally {
                if (_didIteratorError2) {
                    throw _iteratorError2;
                }
            }
        }

        return hel;
    }
    // 执行
    function exec() {
        if (!HTMLElement.prototype.toggleClass) {
            HTMLElement.prototype.toggleClass = function (classes) {
                var cls = String(classes).replace(/[\s\,\;]+/gm, ',').split(',');
                var _iteratorNormalCompletion3 = true;
                var _didIteratorError3 = false;
                var _iteratorError3 = undefined;

                try {
                    for (var _iterator3 = cls[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
                        var c = _step3.value;

                        if (this.classList.contains(c)) {
                            this.classList.remove(c);
                        } else {
                            this.classList.add(c);
                        }
                    }
                } catch (err) {
                    _didIteratorError3 = true;
                    _iteratorError3 = err;
                } finally {
                    try {
                        if (!_iteratorNormalCompletion3 && _iterator3.return) {
                            _iterator3.return();
                        }
                    } finally {
                        if (_didIteratorError3) {
                            throw _iteratorError3;
                        }
                    }
                }
            };
        }
        if (document.readyState == 'loading') {
            document.addEventListener('DOMContentLoaded', function () {
                setTimeout(main, 500);
            });
        } else {
            setTimeout(main, 500);
        }
    }
    exec();
})();