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

“MediaWiki:Gadget-mainpage-edit.js”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
第26行: 第26行:
}).on('dblclick', 'td:last-child', function() {
}).on('dblclick', 'td:last-child', function() {
const $this = $(this),
const $this = $(this),
input = new OO.ui.MultilineTextInputWidget({value: items[ $this.parent().index() ][1]});
input = new OO.ui.MultilineTextInputWidget({autosize: true, value: items[ $this.parent().index() ][1]});
$this.html( input.$element );
$this.html( input.$element );
});
});

2021年2月20日 (六) 08:28的版本

"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 td:first-child { position: relative; }
        .mainpage-flex .oo-ui-textInputWidget { width: 277px; }` );
    $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);
    Promise.all([mw.request, mw.loader.using( 'oojs-ui-core' )]).then(data => {
        items = [...data[0].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 );
        });
    });
}