LLWiki正在建设中,欢迎加入我们!
“User:Bhsd/edit.js”的版本间差异
跳转到导航
跳转到搜索
小 |
小 (// 使用Wikiplus小工具快速编辑) 标签:移动版网页编辑 移动版编辑 |
||
(未显示同一用户的48个中间版本) | |||
第1行: | 第1行: | ||
//<nowiki> |
|||
$(function() { |
|||
// 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 |
|||
/* JavaScript编辑界面按tab键空4格 */ |
|||
"use strict"; |
|||
var editBox = $('#wpTextbox1'), |
|||
/*global mw, $*/ |
|||
title = mw.config.get('wgPageName'), |
|||
(() => { |
|||
btns = $('#wpSaveWidget, #wpPreviewWidget, #wpDiffWidget, #wpTemplateSandboxPreview'), |
|||
const action = mw.config.get( 'wgAction' ), |
|||
contentmodel = mw.config.get( 'wgPageContentModel' ), |
|||
skin = mw.config.get( 'skin' ), |
|||
$body = $(document.body); |
|||
// 引自[[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', function(){ |
|||
var timer = setInterval(function() { |
|||
if( $('#Wikiplus-Quickedit-Jump').length ) { |
|||
clearInterval(timer); |
|||
if( $('#Wikiplus-Quickedit-Replace').length ) { return; } |
|||
$('#Wikiplus-Quickedit-Jump').after( '<span id="Wikiplus-Quickedit-Replace" class="Wikiplus-Btn">替换</span>' ); |
|||
$('#Wikiplus-Quickedit-Replace').on('click', function() { |
|||
var dialog = $('<div class="quickEdit-replace"><label>查找:<input type="text" id="quickEdit-replace-pattern"></label><label>替换:<input type="text" id="quickEdit-replace-val"></label><button id="quickEdit-replace_replaceBtn">替换</button><button id="quickEdit-replace_hideBtn">关闭</button></div>') |
|||
.insertAfter('.Wikiplus-InterBox') |
|||
.on('click', '#quickEdit-replace_hideBtn', function(e) { |
|||
e.delegateTarget.remove(); |
|||
}) |
|||
.on('click', '#quickEdit-replace_replaceBtn', function() { |
|||
var textarea = $('#Wikiplus-Quickedit'), |
|||
ptn = $('#quickEdit-replace-pattern').val(), |
|||
value = $('#quickEdit-replace-val').val(); |
|||
mw.loader.using( 'mediawiki.util' ).then(function() { |
|||
textarea.val( textarea.val().replace(new RegExp( ptn, 'g' ), value) ); |
|||
}); |
|||
}); |
|||
}); |
|||
} |
|||
}, 100); |
|||
}); |
|||
} |
|||
if(mw.config.get('wgPageContentModel') == 'javascript') { |
|||
$('body').on('keydown', '#wpTextbox1, #Wikiplus-Quickedit', function(e){ |
|||
if(e.keyCode == 9){ |
|||
e.preventDefault(); |
|||
var position = this.selectionStart, |
|||
left = this.value.substring(0, position), |
|||
right = this.value.substring(position), |
|||
code = left + ' ' + right; |
|||
this.value = code; |
|||
this.selectionStart = this.selectionEnd = position + 4; |
|||
} |
|||
}); |
|||
} |
|||
// 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] |
|||
$( 'input[name=wpTemplateSandboxPage]' ).val(function() { return $(this).val() || mw.config.get('wgPageName') }); |
|||
if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && |
|||
(mw.isModule( 'Wikiplus', true ) || mw.isModule( 'mobile-Wikiplus', true ))) { |
|||
if(['edit', 'submit'].includes(action) && skin == 'vector') { |
|||
mw.hook( 'wikiplus.dialog' ).add(() => { |
|||
var timer = setInterval(function() { |
|||
if ($( '#Wikiplus-Quickedit-Replace' ).length) { return; } |
|||
console.log('Hook: wikiplus.dialog,开始添加替换按钮'); |
|||
clearInterval(timer); |
|||
$('<span>', {id: "Wikiplus-Quickedit-Replace", class:"Wikiplus-Btn", text:'替换'}).click(() => { |
|||
$( '#custom-editTools .mw-collapsible-toggle-collapsed' ).click(); |
|||
let dialog = $( '.quickEdit-replace' ); |
|||
} |
|||
if (dialog.length) { |
|||
}, 100); |
|||
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 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', () => { 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 > 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) ); |
|||
}); |
|||
}); |
|||
if (skin == 'minerva') { return; } |
|||
mw.loader.using( 'jquery.ui' ).then(() => { dialog.draggable(); }); |
|||
}).insertAfter( '#Wikiplus-Quickedit-Jump' ); |
|||
}); |
|||
} |
|||
if (['edit', 'submit'].includes(action)) { |
|||
// 由于以下代码的奇怪性质,本页面不应频繁修改,至少不能使用移动版皮肤修改 |
|||
// 修改WikiEditor的替换文本框 |
|||
btns.on('click', function() { |
|||
if (skin == 'vector') { |
|||
if(mw.config.get('wgPageContentModel') == 'javascript') { editBox.val(editBox.val().replace(/\t/g, " ")); } |
|||
$body.on('click', 'input#wikieditor-toolbar-replace-replace', function() { |
|||
if(skin == 'vector') { return; } |
|||
$(this).replaceWith( $('<textarea>', {id: "wikieditor-toolbar-replace-replace", tabindex:10}) |
|||
editBox.val(editBox.val().replace(/(‘|’)/g,"'")); |
|||
.on('keydown keypress', e => { if (e.key == 'Enter') { e.stopPropagation(); } }) ); |
|||
editBox.val(editBox.val().replace(/(“|”)/g,'"')); |
|||
}); |
|||
} |
|||
}); |
|||
// 修改templateSandbox的默认页面 |
|||
$body.on('click', '#wpTemplateSandboxPreview', () => { |
|||
const $sandbox = $( 'input[name = wpTemplateSandboxPage]' ); |
|||
if (!$sandbox.val()) { |
|||
$sandbox.val( mw.config.get( 'wgPageName' ) ); |
|||
} |
|||
}); |
|||
// 代码统一使用Tab缩进 |
|||
if (['javascript', 'css', 'Scribunto'].includes( contentmodel )) { |
|||
$body.on('submit', '#editform', () => { |
|||
$( '#wpTextbox1' ).val(function() { return $(this).val().replaceAll(' ', ' '); }); |
|||
}); |
|||
} |
|||
} |
|||
}) (); |
|||
//</nowiki> |
2022年1月15日 (六) 01:02的最新版本
//<nowiki> // 由[[Special:Mypage/common.js]]调用,可以使用ES6语法 "use strict"; /*global mw, $*/ (() => { const action = mw.config.get( 'wgAction' ), contentmodel = mw.config.get( 'wgPageContentModel' ), skin = mw.config.get( 'skin' ), $body = $(document.body); // 引自[[moegirl:User:東東君/js/Wikiplus-replace.js]] if (action == 'view' && mw.config.get( 'wgIsArticle' ) && mw.config.get( 'wgIsProbablyEditable' ) && (mw.isModule( 'Wikiplus', true ) || mw.isModule( 'mobile-Wikiplus', true ))) { 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 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', () => { 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 > 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) ); }); }); if (skin == 'minerva') { return; } mw.loader.using( 'jquery.ui' ).then(() => { dialog.draggable(); }); }).insertAfter( '#Wikiplus-Quickedit-Jump' ); }); } 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.key == 'Enter') { e.stopPropagation(); } }) ); }); } // 修改templateSandbox的默认页面 $body.on('click', '#wpTemplateSandboxPreview', () => { const $sandbox = $( 'input[name = wpTemplateSandboxPage]' ); if (!$sandbox.val()) { $sandbox.val( mw.config.get( 'wgPageName' ) ); } }); // 代码统一使用Tab缩进 if (['javascript', 'css', 'Scribunto'].includes( contentmodel )) { $body.on('submit', '#editform', () => { $( '#wpTextbox1' ).val(function() { return $(this).val().replaceAll(' ', ' '); }); }); } } }) (); //</nowiki>