MediaWiki:Common.js:修订间差异
MediaWiki界面页面
更多操作
小无编辑摘要 |
小无编辑摘要 |
||
| 第64行: | 第64行: | ||
// 隐藏模板调用产生的空行 | // 隐藏模板调用产生的空行 | ||
document.querySelectorAll('.mw-parser-output p').forEach(p => { | // document.querySelectorAll('.mw-parser-output p').forEach(p => { | ||
if (p.innerHTML.trim().toLowerCase() === '<br>') { | // if (p.innerHTML.trim().toLowerCase() === '<br>') { | ||
p.style.display = 'none'; | // p.style.display = 'none'; | ||
} | // } | ||
}); | // }); | ||
2026年6月10日 (三) 23:17的版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/* 为表格自动加载默认排序规则 */
jQuery( document ).ready( function ( $ ) {
// 确保 MediaWiki 自带的表格排序模块已加载
mw.loader.using( 'jquery.tablesorter', function () {
// 遍历页面中所有可排序表格
$( 'table.sortable' ).each( function () {
var $table = $( this );
// 如果表格已经指定了默认排序(例如通过 data-sort-initial)
// 则尊重作者意图,不进行干预
if ( $table.data( 'sort-initialized' ) ) {
return;
}
// 对表格设置默认排序:
// 第一列,升序
$table.tablesorter( {
sortList: [ [ 0, 0 ] ]
} );
// 标记该表格已被初始化,避免重复执行
$table.data( 'sort-initialized', true );
} );
} );
} );
/* 提供外部搜索推荐 */
$(function () {
if (mw.config.get("wgCanonicalSpecialPageName") !== "Search") {
return;
}
// 当前搜索词
const searchTerm = mw.util.getParamValue("search");
if (!searchTerm) {
return;
}
// 构造外部搜索链接
const googleUrl = "https://www.google.com/search?q=" + encodeURIComponent(searchTerm);
const bingUrl = "https://www.bing.com/search?q=" + encodeURIComponent(searchTerm);
const baiduUrl = "https://www.baidu.com/s?wd=" + encodeURIComponent(searchTerm);
const $externalLinks = $("<p>").html(
`你也可以使用外部搜索:<a href="${googleUrl}" target="_blank" rel="noopener">Google</a> / ` +
`<a href="${bingUrl}" target="_blank" rel="noopener">Bing</a> / ` +
`<a href="${baiduUrl}" target="_blank" rel="noopener">百度</a> 来查找“${searchTerm}”。`
).addClass("mw-search-external");
// 优先插入到有搜索结果的地方
if ($(".mw-search-results").length) {
$externalLinks.insertAfter(".mw-search-results");
}
// 否则插入到没有结果提示后
else if ($(".mw-search-nonefound").length) {
$externalLinks.insertAfter(".mw-search-nonefound");
}
});
// 隐藏模板调用产生的空行
// document.querySelectorAll('.mw-parser-output p').forEach(p => {
// if (p.innerHTML.trim().toLowerCase() === '<br>') {
// p.style.display = 'none';
// }
// });