MediaWiki:Gadget-AutoInsource.js: Difference between revisions
Jump to navigation
Jump to search
Chinaenglish (talk | contribs) Created page with "//viesz加入下面自动 insource 正则搜索的小工具,用 JavaScript 小工具自动转换查询 ( function ( $, mw ) { 'use strict'; $( function () { // 仅当页面存在自定义搜索框时才执行 var $customSearch = $( '#searchInput' ); // InputBox 生成的输入框ID通常是 searchInput if ( !$customSearch.length ) return; // 监听该表单的提交事件 $customSearch.closest( 'form' ).on( 'submit', fun..." |
Chinaenglish (talk | contribs) No edit summary |
||
| Line 4: | Line 4: | ||
$( function () { | $( function () { | ||
// 仅当页面存在自定义搜索框时才执行 | // 仅当页面存在自定义搜索框时才执行 | ||
var $customSearch = $( '# | var $customSearch = $( '#homeSearchInput' ); // InputBox 生成的输入框ID通常是 searchInput | ||
if ( !$customSearch.length ) return; | if ( !$customSearch.length ) return; | ||
Revision as of 15:52, 13 November 2026
//viesz加入下面自动 insource 正则搜索的小工具,用 JavaScript 小工具自动转换查询
( function ( $, mw ) {
'use strict';
$( function () {
// 仅当页面存在自定义搜索框时才执行
var $customSearch = $( '#homeSearchInput' ); // InputBox 生成的输入框ID通常是 searchInput
if ( !$customSearch.length ) return;
// 监听该表单的提交事件
$customSearch.closest( 'form' ).on( 'submit', function () {
var term = $customSearch.val().trim();
if ( term === '' || term.indexOf( 'insource:' ) === 0 ) return;
// 转义正则中的特殊字符(简化处理,实际需更严谨的转义)
var escaped = term.replace( /([.*+?^${}()|[\]\\])/g, '\\$1' );
// 自动包装为 insource 正则,并忽略大小写
$customSearch.val( 'insource:/' + escaped + '/i' );
} );
} );
}( jQuery, mediaWiki ) );