LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/edit.js”的版本间差异
跳转到导航
跳转到搜索
小 |
|||
第1行: | 第1行: | ||
// 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 |
|||
"use strict"; |
|||
$(function() { |
$(function() { |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
btns = $('#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'), |
btns = $('#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'), |
||
action = mw.config.get('wgAction'), |
action = mw.config.get('wgAction'), |
||
contentmodel = mw.config.get('wgPageContentModel'), |
contentmodel = mw.config.get( 'wgPageContentModel' ), |
||
skin = mw.config.get('skin') |
skin = mw.config.get('skin'), |
||
ns = mw.config.get( 'wgNamespaceNumber' ); |
|||
// 修改WikiEditor的替换文本框 |
|||
if(['edit', 'submit'].includes(action)) { |
if (['edit', 'submit'].includes( action )) { |
||
$('#wpTextbox1').on( 'wikiEditor-toolbar-doneInitialSections', function() { |
|||
$('#wpTextbox1').on( 'wikiEditor-toolbar-doneInitialSections', () => { |
|||
$( '.oo-ui-icon-articleSearch' ).one('click', () => { |
|||
var timer = setInterval(function() { |
|||
const timer = setInterval(() => { |
|||
if ($( '#wikieditor-toolbar-replace-replace' ).length === 0) { return; } |
|||
clearInterval(timer); |
|||
const ele = $( '<textarea id="wikieditor-toolbar-replace-replace" tabindex="10">' ) |
|||
.keydown(e => { |
|||
if (e.keyCode == '13') { |
|||
const text = ele.val(), |
|||
before = text.substring(0, ele.prop( 'selectionStart' )), |
|||
ele. |
after = text.substring(ele.prop( 'selectionEnd' )); |
||
ele.val(before + '\n' + after); |
|||
} |
} |
||
}); |
|||
$( 'input#wikieditor-toolbar-replace-replace' ).replaceWith(ele); |
|||
}, 100); |
}, 100); |
||
}); |
}); |
||
}); |
} ); |
||
} |
} |
||
// 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] |
// 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] |
||
if |
if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && |
||
(mw.loader.getState( 'ext.gadget.Wikiplus' ) == 'ready' || mw.loader.getState( 'ext.gadget.mobile-Wikiplus' ) == 'ready') |
(mw.loader.getState( 'ext.gadget.Wikiplus' ) == 'ready' || mw.loader.getState( 'ext.gadget.mobile-Wikiplus' ) == 'ready')) { |
||
$('body').on('click', '#Wikiplus-Edit-TopBtn, .Wikiplus-Edit-SectionBtn', |
$('body').on('click', '#Wikiplus-Edit-TopBtn, .Wikiplus-Edit-SectionBtn', () => { |
||
const timer = setInterval(() => { |
|||
if |
if ($( '#Wikiplus-Quickedit-Jump' ).length === 0) { return; } |
||
clearInterval(timer); |
|||
if ($( '#Wikiplus-Quickedit-Replace' ).length) { return; } |
|||
$( '<span id="Wikiplus-Quickedit-Replace" class="Wikiplus-Btn">替换</span>' ) |
|||
.on('click', () => { |
|||
if ($( '.quickEdit-replace' ).length) { |
|||
$( '.quickEdit-replace' ).css('display', 'initial'); |
|||
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 id="quickEdit-replace-regex"><input type="checkbox">正则</label><button id="quickEdit-replace_replaceBtn">替换</button><button id="quickEdit-replace_undoBtn" disabled="true">撤销</button><button id="quickEdit-replace_hideBtn">关闭</button></div>') |
||
$(e.delegateTarget).css('display', 'none'); |
|||
.appendTo('.Wikiplus-InterBox') |
|||
.on('click', '#quickEdit-replace_hideBtn', e => { |
|||
$( e.delegateTarget ).css('display', 'none'); |
|||
}) |
|||
.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 input').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) ); |
|||
}); |
|||
⚫ | |||
}); |
|||
⚫ | |||
else { |
|||
$('.quickEdit-replace').css('display', 'initial'); |
|||
} |
|||
}); |
}); |
||
⚫ | |||
⚫ | |||
}).insertAfter( '#Wikiplus-Quickedit-Jump' ); |
|||
}, 100); |
}, 100); |
||
}); |
}); |
||
} |
} |
||
⚫ | |||
⚫ | |||
if (contentmodel == 'javascript') { |
|||
$('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e){ |
$('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e) { |
||
if(e.keyCode == 9){ |
if (e.keyCode == 9) { |
||
e.preventDefault(); |
e.preventDefault(); |
||
const text = this.value, |
|||
position = this.selectionStart, |
|||
left = text.substring(0, position), |
|||
right = text.substring( this.selectionEnd ); |
|||
this.value = |
this.value = left + ' ' + right; |
||
this.selectionStart = this.selectionEnd = position + 4; |
this.selectionStart = this.selectionEnd = position + 4; |
||
} |
} |
||
第88行: | 第85行: | ||
} |
} |
||
// 修改templateSandbox的默认页面 |
|||
$( 'input[name=wpTemplateSandboxPage]' ).val(function() { |
$( 'input[name=wpTemplateSandboxPage]' ).val(function() { |
||
const namespaces = mw.config.get( 'wgFormattedNamespaces' ), |
|||
⚫ | |||
return $(this).val() || (namespaces[ns] + (ns === 0 ? '' : ':') + title); |
|||
}); |
|||
// 由于以下代码的奇怪性质,本页面不应频繁修改,至少不能使用移动版皮肤修改 |
// 自动替换文本。由于以下代码的奇怪性质,本页面不应频繁修改,至少不能使用移动版皮肤修改 |
||
btns.on('click', |
btns.on('click', () => { |
||
if(contentmodel == 'javascript') { |
if (contentmodel == 'javascript') { |
||
editBox.val(function() { return $(this).val().replace(/\t/g, " "); }); |
|||
⚫ | |||
⚫ | |||
if (skin == 'vector' || contentmodel == 'wikitext') { return; } |
|||
editBox.val(editBox.val().replace(/(“|”)/g,'"')); |
|||
⚫ | |||
}); |
}); |
||
}); |
}); |
2020年11月19日 (四) 05:37的版本
// 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 "use strict"; $(function() { const editBox = $('#wpTextbox1'), btns = $('#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'), action = mw.config.get('wgAction'), contentmodel = mw.config.get( 'wgPageContentModel' ), skin = mw.config.get('skin'), ns = mw.config.get( 'wgNamespaceNumber' ); // 修改WikiEditor的替换文本框 if (['edit', 'submit'].includes( action )) { $('#wpTextbox1').on( 'wikiEditor-toolbar-doneInitialSections', () => { $( '.oo-ui-icon-articleSearch' ).one('click', () => { const timer = setInterval(() => { if ($( '#wikieditor-toolbar-replace-replace' ).length === 0) { return; } clearInterval(timer); const ele = $( '<textarea id="wikieditor-toolbar-replace-replace" tabindex="10">' ) .keydown(e => { if (e.keyCode == '13') { const text = ele.val(), before = text.substring(0, ele.prop( 'selectionStart' )), after = text.substring(ele.prop( 'selectionEnd' )); ele.val(before + '\n' + after); } }); $( 'input#wikieditor-toolbar-replace-replace' ).replaceWith(ele); }, 100); }); } ); } // 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && (mw.loader.getState( 'ext.gadget.Wikiplus' ) == 'ready' || mw.loader.getState( 'ext.gadget.mobile-Wikiplus' ) == 'ready')) { $('body').on('click', '#Wikiplus-Edit-TopBtn, .Wikiplus-Edit-SectionBtn', () => { const timer = setInterval(() => { if ($( '#Wikiplus-Quickedit-Jump' ).length === 0) { return; } clearInterval(timer); if ($( '#Wikiplus-Quickedit-Replace' ).length) { return; } $( '<span id="Wikiplus-Quickedit-Replace" class="Wikiplus-Btn">替换</span>' ) .on('click', () => { if ($( '.quickEdit-replace' ).length) { $( '.quickEdit-replace' ).css('display', 'initial'); 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 id="quickEdit-replace-regex"><input 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', e => { $( e.delegateTarget ).css('display', 'none'); }) .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 input').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) ); }); }); mw.loader.using( 'jquery.ui' ).then(() => { dialog.draggable(); }); }).insertAfter( '#Wikiplus-Quickedit-Jump' ); }, 100); }); } /* JavaScript编辑界面按tab键空4格 */ if (contentmodel == 'javascript') { $('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e) { if (e.keyCode == 9) { e.preventDefault(); const text = this.value, position = this.selectionStart, left = text.substring(0, position), right = text.substring( this.selectionEnd ); this.value = left + ' ' + right; this.selectionStart = this.selectionEnd = position + 4; } }); } // 修改templateSandbox的默认页面 $( 'input[name=wpTemplateSandboxPage]' ).val(function() { const namespaces = mw.config.get( 'wgFormattedNamespaces' ), title = mw.config.get('wgTitle'); return $(this).val() || (namespaces[ns] + (ns === 0 ? '' : ':') + title); }); // 自动替换文本。由于以下代码的奇怪性质,本页面不应频繁修改,至少不能使用移动版皮肤修改 btns.on('click', () => { if (contentmodel == 'javascript') { editBox.val(function() { return $(this).val().replace(/\t/g, " "); }); } if (skin == 'vector' || contentmodel == 'wikitext') { return; } editBox.val(function() { return $(this).val().replace(/[‘’]/g, "'").replace(/[“”]/g, '"'); }); }); });