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

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

来自LLWiki
跳转到导航 跳转到搜索
第18行: 第18行:
items[ $menu.closest( 'tr' ).index() ][0] = getName( this );
items[ $menu.closest( 'tr' ).index() ][0] = getName( this );
}).css('z-index', 2);
}).css('z-index', 2);
Promise.all([mw.standardQuery(), mw.loader.using( 'oojs-ui-core' )]).then(data => {
mw.loader.using( 'mediawiki.api' ).then(() => {
Promise.all([mw.standardQuery( new mw.Api() ), mw.loader.using( 'oojs-ui-core' )]).then(data => {
items = [...data[0].query.pages[0].revisions[0].content.matchAll( /首[页頁]\/[标標][签籤]\|(.+?)}}(.+?)\n/g )]
items = [...data[0].query.pages[0].revisions[0].content.matchAll( /首[页頁]\/[标標][签籤]\|(.+?)}}(.+?)\n/g )]
.map(ele => [ele[1].trim(), ele[2].trim()]);
.map(ele => [ele[1].trim(), ele[2].trim()]);
$('.mw-parser-output table').on('dblclick', 'td:first-child', function() {
$menu.appendTo( this );
$('.mw-parser-output table').on('dblclick', 'td:first-child', function() {
$menu.setSelected( findSelected( items[ $(this).parent().index() ][0].toLowerCase() ) ).open();
$menu.appendTo( this );
$menu.setSelected( findSelected( items[ $(this).parent().index() ][0].toLowerCase() ) ).open();
}).on('dblclick', 'td:last-child', function() {
const $this = $(this),
}).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 );
input = new OO.ui.MultilineTextInputWidget({ autosize: true,
value: items[ $this.parent().index() ][1]
});
$this.html( input.$element );
});
});
});
});
});

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

"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);
    mw.loader.using( 'mediawiki.api' ).then(() => {
        Promise.all([mw.standardQuery( new mw.Api() ), 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 );
            });
        });
    });
}