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

“User:Bhsd/widget/list.js”的版本间差异

来自LLWiki
跳转到导航 跳转到搜索
(调整UI)
第33行: 第33行:
},
},
selectSet = [1, 2, 3, 4].map( buildSelect );
selectSet = [1, 2, 3, 4].map( buildSelect );
$(() => {
mw.hook( 'wikipage.content' ).add($content => {
$output = $('#mw-content-text pre');
$output = $content.find( 'pre' );
$('h2:has( .mw-headline )').after(i => selectSet[i]);
$content.find( 'h2:has(.mw-headline)' ).after(i => selectSet[i]);
});
});
},
},
init = () => {
init = () => {
mw.widget = mw.widget || {};
if (mw.widget.list) { return; }
Promise.all([ $.ajax({ dataType: 'json', cache: true,
Promise.all([ $.ajax({ dataType: 'json', cache: true,
url: '/zh?title=user:bhsd/widget/list.json&action=raw&ctype=application/json'
url: '/zh?title=user:bhsd/widget/list.json&action=raw&ctype=application/json'
}), mw.loader.using( 'oojs-ui-core' ) ]).then( main );
}), mw.loader.using( 'oojs-ui-core' ) ]).then( main );
mw.widget.list = true;
};
};
if (window.jQuery) { init(); }
if (window.jQuery) { init(); }

2021年4月22日 (四) 11:44的版本

"use strict";
/* global mw, $, OO */
(() => {
    const main = (data) => {
        mw.sifdata = data[0];
        let $output;
        const attr = ['s', 'p', 'c'],
            diff = ['easy', 'normal', 'hard', 'expert', 'exran', 'master'],
            convertTime = (t) => `${ Math.floor(t / 60) }:${ (t % 60).toString().padStart(2, 0) }`,
            buildOptions = (list, key) =>
            list.map(ele => ele[key]).filter(ele => ele)
                .map(ele => new OO.ui.MenuOptionWidget({data: ele, label: ele})),
            change = (value) => {
            const term = mw.sifdata.find(ele => ele.j == value || ele.c == value);
            if (!term) { return; }
            $output.text( `{{sif-song-tablerow|${ term.j }|${ attr[term.a] }|${ convertTime( term.t ) }` +
                term.s.map(ele => {
                    const level = diff[ele.d - 1];
                    return `|d-${ level }=${ ele.s }|c-${ level }=${ ele.c }`;
                }).join( '' ) + '|条件=}}'
            );
        },
            buildSelect = (group) => {
            const list = mw.sifdata.filter(ele => ele.g == group),
                optionsJa = buildOptions(list, 'j'),
                optionsZh = buildOptions(list, 'c'),
                select = new OO.ui.ComboBoxInputWidget({ menu: {items: [
                new OO.ui.MenuSectionOptionWidget({label: '原名'}), ...optionsJa,
                new OO.ui.MenuSectionOptionWidget({label: '中文名'}), ...optionsZh,
            ], width: '100%', filterFromInput: true, filterMode: 'substring'} }).on('change', change);
            optionsJa.forEach(ele => { ele.$element.attr('lang', 'ja'); });
            return select.$element.append( $('<i>', {class: 'fas fa-backspace'}).click(() => { select.setValue(''); }) );
        },
            selectSet = [1, 2, 3, 4].map( buildSelect );
        mw.hook( 'wikipage.content' ).add($content => {
            $output = $content.find( 'pre' );
            $content.find( 'h2:has(.mw-headline)' ).after(i => selectSet[i]);
        });
    },
        init = () => {
        mw.widget = mw.widget || {};
        if (mw.widget.list) { return; }
        Promise.all([ $.ajax({ dataType: 'json', cache: true,
            url: '/zh?title=user:bhsd/widget/list.json&action=raw&ctype=application/json'
        }), mw.loader.using( 'oojs-ui-core' ) ]).then( main );
        mw.widget.list = true;
    };
    if (window.jQuery) { init(); }
    else { window.addEventListener('jquery', init); }
}) ();