LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/widget/list.js”的版本间差异
跳转到导航
跳转到搜索
小 |
|||
第4行: | 第4行: | ||
const main = (data) => { |
const main = (data) => { |
||
mw.sifdata = data[0]; |
mw.sifdata = data[0]; |
||
const |
const buildOptions = (key) => |
||
mw.sifdata.map(ele => ele[key]).filter(ele => ele).slice(0, 5).sort() |
|||
.map(ele => new OO.ui.MenuOptionWidget({data: ele, label: ele})), |
|||
⚫ | |||
Object.keys( map ).sort().map(ele => new OO.ui.MenuOptionWidget({data: ele, label: ele}) ), |
|||
optionsZh = buildOptions( 'c' ), |
|||
⚫ | |||
$output = $('<div>'), |
$output = $('<div>'), |
||
attr = ['s', 'p', 'c'], |
attr = ['s', 'p', 'c'], |
2021年4月22日 (四) 08:59的版本
"use strict"; /* global mw, $, OO */ (() => { const main = (data) => { mw.sifdata = data[0]; const buildOptions = (key) => mw.sifdata.map(ele => ele[key]).filter(ele => ele).slice(0, 5).sort() .map(ele => new OO.ui.MenuOptionWidget({data: ele, label: ele})), optionsJa = buildOptions( 'j' ), optionsZh = buildOptions( 'c' ), $output = $('<div>'), attr = ['s', 'p', 'c'], diff = ['easy', 'normal', 'hard', 'expert', 'exran', 'master'], 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', value => { const term = mw.sifdata.find(ele => ele.j == value || ele.c == value); $output.text( `{{sif-song-tablerow|${ term.j }|${ attr[term.a] }|${ term.t }` + term.s.map(ele => { const level = diff[ ele.d ]; return `|d-${ level }=${ ele.s }|c-${ level }=${ ele.c }`; }).join( '' ) ); }); $(() => { select.$element.prependTo( '#mw-content-text .mw-parser-output' ) .append( $('<i>', {class: 'fas fa-backspace'}).click(() => { select.setValue(''); }) ) .after( $output ); optionsJa.forEach(ele => { ele.$element.attr('lang', 'ja'); }); }); }, init = () => { 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 ); }; if (window.jQuery) { init(); } else { window.addEventListener('jquery', init); } }) ();