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

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

跳转到导航 跳转到搜索
"use strict";
/* global mw, $, OO */
(() => {
/**
const main = (data) => {
* @Function: 加载SIF歌曲数据
* @Output {Object} mw.sifdata = data[0];
const mapJa = mw.sifdata.map(ele => ele.j).filter(ele => ele).slice(0, 5),
*/
mapZh = mw.sifdata.map(ele => ele.c).filter(ele => ele).slice(0, 5),
$.ajax({dataType: 'json', cache: true, url: '/zh?title=user:bhsd/widget/list.json&action=raw&ctype=application/json'})
buildOptions = (map) =>
.then(x => { mw.sifdata = x; });
Object.keys( map ).sort().map(ele => new OO.ui.MenuOptionWidget({data: ele, label: ele}) ),
optionsJa = buildOptions( mapJa ),
optionsZh = buildOptions( mapZh ),
$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,
$.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); }
}) ();