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

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

跳转到导航 跳转到搜索
添加1,072字节 、​ 2021年1月10日 (日) 06:47
无编辑摘要
*/
"use strict";
/*global mw, $, OO, CodeMirror, wgULS, wgUCS*/
$(() => { // 避免全局变量
const id = mw.config.get( 'wgArticleId' ),
mw.sections = mw.sections || [];
mw.sections[ section ] = mw.sections[ section ] || mw.timedQuery(api, {action: 'parse', oldid: curRevid,
prop: 'wikitext', section: section}, wgULS('章节段落Wikitext', '章節Wikitext'));
mw.sections[ section ].then(r => { editor.setValue( r.parse.wikitext ); }, () => {});
});
regexps = {0: /\[\[\s*:?([^|[\]{}<>]*)$/i, 10: /{{\s*([^|[\]{}<>#]*)$/i,
828: /{{\s*#invoke:\s*([^|[\]{}<>#:]*)$/i, 274: /{{\s*#widget:\s*([^|[\]{}<>#:]*)$/i},
$noHint = $('<divspan>', {class: 'error', text: wgULS('不存在对应页面!', '不存在對應頁面!')}),
nsPrefixes = {0: '', 10: 'Template:', 828: '模块:', 274: 'Widget:'},
autocomplete = isGadget('autocomplete') ? e => {
if (![9, 27].includes( e.keyCode )) { return; } // tab和esc
let $cursor, before, sections, title;
const cursorActivity = () => {
const newCursor = editor.getCursor(),
$cursor = $wrapper.find( '.CodeMirror-cursor' );
prefix = before.match( regexps[ns] )[1];
if (prefix === "" || prefix.startsWith('#')) { return; }
if (ns === 0 && prefix.includes('#')) {
const capture = prefix.match(/(.+)#(.*)$/);
prefix = capture[2];
(title == capture[1] ? Promise.resolve() : mw.timedQuery(api, {action: 'parse', page: title,
prop: 'sections'}, wgULS('段落标题', '段落標題')).then(r => {
title = capture[1];
sections = r.parse.sections.map(ele => $('<div>', {class: 'inspector-hint', text: ele.line}));
}, () => { throw null; })).then(() => {
$hints.html( sections.filter(ele => ele.text().startsWith( prefix )) )
.show().position({my: 'left top', of: $cursor, within: $wrapper, collision: 'fit'});
if ($hints.children().length === 0) {
$noHint.text(wgULS('不存在对应段落!', '不存在對應段落!')).appendTo( $hints );
}
}, stop);
return;
}
mw.timedQuery(api, {list: 'prefixsearch', pssearch: prefix, psnamespace: ns},
wgULS('前缀相符的页面', '前綴相符的頁面')).then(r => {
$('<div>', {class: 'inspector-hint', text: ele.title.slice( nsPrefixes[ns].length )})
) ).show().position({my: 'left top', of: $cursor, within: $wrapper, collision: 'fit'});
if ($hints.children().length === 0) { $hints.append( $noHint ); }
$noHint.text(wgULS('不存在对应页面!', '不存在對應頁面!')).appendTo( $hints );
}
}, stop);
});
16,874

个编辑

导航菜单