LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/edit.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 |
||
第7行: | 第7行: | ||
contentmodel = mw.config.get( 'wgPageContentModel' ), |
contentmodel = mw.config.get( 'wgPageContentModel' ), |
||
skin = mw.config.get('skin'); |
skin = mw.config.get('skin'); |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
} |
|||
// 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] |
// 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] |
||
const states = [' |
const states = ['loading', 'loaded', 'executing', 'ready']; |
||
if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && |
if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && |
||
(states.includes( mw.loader.getState( 'ext.gadget.Wikiplus' ) ) || |
(states.includes( mw.loader.getState( 'ext.gadget.Wikiplus' ) ) || |
||
第35行: | 第27行: | ||
'<label>查找:<input type="text" id="quickEdit-replace-pattern"></label>' + |
'<label>查找:<input type="text" id="quickEdit-replace-pattern"></label>' + |
||
'<label>替换:<textarea id="quickEdit-replace-val"></textarea></label>' + |
'<label>替换:<textarea id="quickEdit-replace-val"></textarea></label>' + |
||
'<label id="quickEdit-replace-regex" |
'<label><input id="quickEdit-replace-regex" type="checkbox">正则</label>' + |
||
'<button id="quickEdit-replace_replaceBtn">替换</button>' + |
'<button id="quickEdit-replace_replaceBtn">替换</button>' + |
||
'<button id="quickEdit-replace_undoBtn" disabled="true">撤销</button>' + |
'<button id="quickEdit-replace_undoBtn" disabled="true">撤销</button>' + |
||
第45行: | 第37行: | ||
const ptn = $( '#quickEdit-replace-pattern' ).val(), |
const ptn = $( '#quickEdit-replace-pattern' ).val(), |
||
value = $( '#quickEdit-replace-val' ).val(), |
value = $( '#quickEdit-replace-val' ).val(), |
||
isRegex = $('#quickEdit-replace-regex |
isRegex = $( '#quickEdit-replace-regex' ).prop( 'checked' ); |
||
backup = textarea.val(); |
backup = textarea.val(); |
||
$( '#quickEdit-replace_undoBtn' ).prop('disabled', false); |
$( '#quickEdit-replace_undoBtn' ).prop('disabled', false); |
||
第60行: | 第52行: | ||
/* JavaScript编辑界面按tab键空4格 */ |
/* JavaScript编辑界面按tab键空4格 */ |
||
if (contentmodel == 'javascript' && skin == 'vector') { |
if (contentmodel == 'javascript' && skin == 'vector' && ['view', 'edit', 'submit'].includes(action)) { |
||
mw.loader.using( 'jquery.textSelection' ).then(() => { |
mw.loader.using( 'jquery.textSelection' ).then(() => { |
||
$('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e) { |
$('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e) { |
||
第71行: | 第63行: | ||
} |
} |
||
if (['edit', 'submit'].includes( |
if (['edit', 'submit'].includes(action)) { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
}); |
|||
⚫ | |||
// 修改templateSandbox的默认页面 |
// 修改templateSandbox的默认页面 |
||
$('body').on('click', '#wpTemplateSandboxPreview', () => { |
$('body').on('click', '#wpTemplateSandboxPreview', () => { |
||
$( 'input[name=wpTemplateSandboxPage]' ).val(function() { |
$( 'input[name=wpTemplateSandboxPage]' ).val(function() { |
||
const namespaces = mw.config.get( 'wgFormattedNamespaces' ), |
const namespaces = mw.config.get( 'wgFormattedNamespaces' ), |
||
ns = mw.config.get( 'wgNamespaceNumber' ) |
ns = mw.config.get( 'wgNamespaceNumber' ); |
||
return $(this).val() || (namespaces[ns] + (ns === 0 ? '' : ':') + mw.config.get('wgTitle')); |
|||
return $(this).val() || (namespaces[ns] + (ns === 0 ? '' : ':') + title); |
|||
}); |
}); |
||
}); |
}); |
||
⚫ | |||
if (contentmodel == 'javascript') { |
if (contentmodel == 'javascript') { |
||
⚫ | |||
const btns = '#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'; |
const btns = '#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'; |
||
$('body').on('click', btns, () => { |
$('body').on('click', btns, () => { |
2020年12月13日 (日) 05:05的版本
//<nowiki> // 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 "use strict"; /*global mw, $*/ (function() { const action = mw.config.get('wgAction'), contentmodel = mw.config.get( 'wgPageContentModel' ), skin = mw.config.get('skin'); // 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] const states = ['loading', 'loaded', 'executing', 'ready']; if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && (states.includes( mw.loader.getState( 'ext.gadget.Wikiplus' ) ) || states.includes( mw.loader.getState( 'ext.gadget.mobile-Wikiplus' ) ))) { mw.hook( 'wikiplus.dialog' ).add(() => { if ($( '#Wikiplus-Quickedit-Replace' ).length) { return; } console.log('Hook: wikiplus.dialog,开始添加替换按钮'); $('<span>', {id: "Wikiplus-Quickedit-Replace", class:"Wikiplus-Btn", text:'替换'}).click(() => { let dialog = $( '.quickEdit-replace' ); if (dialog.length) { dialog.show(); return; } let backup = ""; const textarea = $('#Wikiplus-Quickedit'); dialog = $('<div class="quickEdit-replace">' + '<label>查找:<input type="text" id="quickEdit-replace-pattern"></label>' + '<label>替换:<textarea id="quickEdit-replace-val"></textarea></label>' + '<label><input id="quickEdit-replace-regex" type="checkbox">正则</label>' + '<button id="quickEdit-replace_replaceBtn">替换</button>' + '<button id="quickEdit-replace_undoBtn" disabled="true">撤销</button>' + '<button id="quickEdit-replace_hideBtn">关闭</button>' + '</div>').appendTo( '.Wikiplus-InterBox' ) .on('click', '#quickEdit-replace_hideBtn', () => { dialog.hide(); }) .on('click', '#quickEdit-replace_undoBtn', () => { textarea.val(backup); }) .on('click', '#quickEdit-replace_replaceBtn', () => { const ptn = $( '#quickEdit-replace-pattern' ).val(), value = $( '#quickEdit-replace-val' ).val(), isRegex = $( '#quickEdit-replace-regex' ).prop( 'checked' ); backup = textarea.val(); $( '#quickEdit-replace_undoBtn' ).prop('disabled', false); mw.loader.using( 'mediawiki.util' ).then(() => { const regexp = new RegExp(isRegex ? ptn : mw.util.escapeRegExp(ptn), 'g'); textarea.val( backup.replace(regexp, value) ); }); }); if (skin == 'minerva') { return; } mw.loader.using( 'jquery.ui' ).then(() => { dialog.draggable(); }); }).insertAfter( '#Wikiplus-Quickedit-Jump' ); }); } /* JavaScript编辑界面按tab键空4格 */ if (contentmodel == 'javascript' && skin == 'vector' && ['view', 'edit', 'submit'].includes(action)) { mw.loader.using( 'jquery.textSelection' ).then(() => { $('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e) { if (e.keyCode == 9) { e.preventDefault(); $(this).textSelection( 'encapsulateSelection', {peri:' ', replace:true, selectPeri:false} ); } }); }); } if (['edit', 'submit'].includes(action)) { // 修改WikiEditor的替换文本框 if (skin == 'vector') { $('body').on('click', 'input#wikieditor-toolbar-replace-replace', function() { $(this).replaceWith( $('<textarea>', {id: "wikieditor-toolbar-replace-replace", tabindex:10}) .on('keydown keypress', e => { if (e.keyCode == '13') { e.stopPropagation(); } }) ); }); } // 修改templateSandbox的默认页面 $('body').on('click', '#wpTemplateSandboxPreview', () => { $( 'input[name=wpTemplateSandboxPage]' ).val(function() { const namespaces = mw.config.get( 'wgFormattedNamespaces' ), ns = mw.config.get( 'wgNamespaceNumber' ); return $(this).val() || (namespaces[ns] + (ns === 0 ? '' : ':') + mw.config.get('wgTitle')); }); }); // JS统一使用4个空格缩进 if (contentmodel == 'javascript') { const btns = '#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'; $('body').on('click', btns, () => { $( '#wpTextbox1' ).val(function() { return $(this).val().replace(/\t/g, " "); }); }); } } }) (); //</nowiki>