LLWiki正在建设中,欢迎加入我们

MediaWiki:Gadget-mainpage-edit.js

来自LLWiki
Bhsd讨论 | 贡献2021年2月20日 (六) 09:36的版本
跳转到导航 跳转到搜索

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

  • Firefox或Safari:按住Shift的同时单击刷新,或按Ctrl-F5Ctrl-R(Mac为⌘-R
  • Google Chrome:Ctrl-Shift-R(Mac为⌘-Shift-R
  • Internet Explorer:按住Ctrl的同时单击刷新,或按Ctrl-F5
  • Opera:前往菜单 → 设置(Mac为Opera → Preferences),然后隐私和安全 → 清除浏览数据 → 缓存的图片和文件
"use strict";
/* global OO */
if (mw.config.get( 'wgPageName' ).startsWith( 'LLWiki:首页/当年今日/' ) && mw.config.get( 'wgAction' ) == 'view') {
    let items = [];
    const $menu = mw.menu([ {text: "µ's", data: {color: '#e4007f', name: 'muse'}},
        {text: 'Aqours', data: {color: '#32aaff'}}, {text: 'Saint Snow', data: {color: '#cb3935'}},
        {text: '虹学', data: {color: '#f39800', name: 'nijigaku'}},
        {text: 'Liella!', data: {color: '#a5469c', name: 'liella'}},
        {text: 'SIF', data: {color: '#77d2af'}}, {text: 'AS', data: {color: '#ff91af'}}
    ], {}, 1),
        dict = {ll: 'muse', llss: 'aqours', llspst: 'liella'},
        getName = (ele) => $(ele).data( 'name' ) || ele.textContent.toLowerCase(),
        findSelected = (name) => [...$menu.children()].find(ele => getName( ele ) == (dict[name] || name));
    mw.loader.addStyleTag( `.mainpage-flex table { overflow: visible; }
        .mainpage-flex td:first-child { position: relative; }
        .mainpage-flex td:last-child { width: calc(${ $('#mw-content-text').width() * 0.32 - 36 }px - 1.2em); }
        .skin-minerva .mainpage-flex td:last-child { width: calc(${ $('#mw-content-text').width() - 36 }px - 3.2em); }
        .skin-minerva #body { position: relative; z-index: 1; }`
    );
    $menu.on('click', 'a', function() {
        $menu.prev( '.mainpage-tag' ).css('background-color', $(this).data( 'color' ));
        items[ $menu.closest( 'tr' ).index() ][0] = getName( this );
    }).css('z-index', 2);
    mw.standardQuery( new mw.Api() ).then(data => {
        items = [...data.query.pages[0].revisions[0].content.matchAll( /首[页頁]\/[标標][签籤]\|(.+?)}}(.+?)\n/g )]
            .map(ele => [ele[1].trim(), ele[2].trim()]);
        $('.mw-parser-output table').on('dblclick', 'td:first-child', function() {
            $menu.appendTo( this );
            $menu.setSelected( findSelected( items[ $(this).parent().index() ][0].toLowerCase() ) ).open();
        }).on('dblclick', 'td:last-child', function() {
            const $this = $(this),
                input = new OO.ui.MultilineTextInputWidget({autosize: true, value: items[ $this.parent().index() ][1]});
            $this.html( input.$element );
        });
    });
}