MediaWiki:Common.js:修订间差异
跳转到导航
跳转到搜索
无编辑摘要 |
无编辑摘要 |
||
| 第138行: | 第138行: | ||
</script> | </script> | ||
</div> | </div> | ||
//103.插入PIC按钮 | |||
mw.loader.using(['mediawiki.util']).then(function() { | |||
// 只在编辑页面生效 | |||
if (mw.config.get('wgAction') !== 'edit') return; | |||
if (mw.config.get('wgPageContentModel') !== 'wikitext') return; | |||
$('<button>') | |||
.text('插入PIC') | |||
.css({ | |||
position: 'fixed', | |||
top: '50px', | |||
right: '10px', | |||
'z-index': 9999, | |||
padding: '8px 16px', | |||
'font-size': '13px', | |||
background: '#f8f9fa', | |||
border: '1px solid #a2a9b1', | |||
'border-radius': '2px', | |||
cursor: 'pointer' | |||
}) | |||
.hover(function() { | |||
$(this).css('background', '#e0e0e0'); | |||
}, function() { | |||
$(this).css('background', '#f8f9fa'); | |||
}) | |||
.click(function() { | |||
var $textbox = $('#wpTextbox1'); | |||
var cursor = $textbox.textSelection('getCaretPosition'); | |||
// 准备要插入的模板(注意:故意把|后面加空格避免部分情况下触发预览bug) | |||
var toInsert = '{{pic|外链=\n|描述=\n}}'; | |||
// 在光标位置插入 | |||
$textbox.textSelection('encapsulateSelection', { | |||
pre: '', | |||
peri: toInsert, | |||
post: '', | |||
replace: false, // 不替换选中内容,只插入 | |||
selectPeri: false // 插入后不选中刚插入的内容 | |||
}); | |||
// 尝试把光标放在第一个参数里面比较友好 | |||
var newText = $textbox.textSelection('getContents'); | |||
var insertPos = cursor.start + toInsert.indexOf('= ') + 2; | |||
$textbox.textSelection('setSelection', { start: insertPos, end: insertPos }); | |||
// 可选:让编辑框重新获得焦点 | |||
$textbox.focus(); | |||
}) | |||
.appendTo('body'); | |||
}); | |||
2026年1月8日 (四) 00:04的最新版本
/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
/*加载ToolsWIKI的DiffTool 以逐字显示更改,0缓存,具体可见https://wiki.biligame.com/tools/%E4%BC%98%E5%8C%96%E7%89%88%E6%9C%AC%E5%B7%AE%E5%BC%82-DiffTools */
try { mw.loader.load("https://wiki.biligame.com/tools/MediaWiki:DiffTool.js?action=raw&ctype=text/javascript&rand="+Math.random(), "text/javascript");} catch(e) { console.log("Error, MediaWiki:DiffTool.js 加载失败");console.error(e, e.stack);}
/* 参见[[模板:ResourceLoader]]*/
//居中与右对齐,文本默认为左对齐,不用另外添加此按钮。(仅适用于源代码编辑模式)
/*居中*/
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Add a hook handler.
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
AlignCenter: {
label: '居中',
type: 'button',
oouiIcon: 'alignCenter',
action: {
type: 'encapsulate',
options: {
pre: "<center>",
post: "</center>"
}
}
}
}
} );
} );
}
/*右对齐*/
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
// Add a hook handler.
mw.hook( 'wikiEditor.toolbarReady' ).add( function ( $textarea ) {
// Configure a new toolbar entry on the given $textarea jQuery object.
$textarea.wikiEditor( 'addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
AlignCenter: {
label: '右对齐',
type: 'button',
oouiIcon: 'alignRight',
action: {
type: 'encapsulate',
options: {
pre: "<div align=right>",
post: "</div>"
}
}
}
}
} );
} );
}
// 101. 功能:快捷编辑理由。支持编辑摘要时,点击快捷选项填充编辑理由。(仅适用于源代码编辑模式)
//参考Wikipedia:MediaWiki:Common.js/edit.js
if (mw.config.get('wgAction') == "edit" || mw.config.get('wgAction') == "submit" || mw.config.get('wgCanonicalSpecialPageName') == 'Search') { // 编辑页面
( function( $, mw ) { $( function() {
if ( $( '#editform input[name=wpSection]' ).val() === 'new' ) {
if ( $( '#no-new-title' ).length ) {
$( '#wpSummary' ).attr( 'disabled', true );
}
return;
}
$( '#wpSummaryLabel .mw-summary-preset' ).on( 'click', '.mw-summary-preset-item a', function( e ) {
e.preventDefault();
var $this = $( this ), summary = $( '#wpSummary' ).val();
var $item = $this.parent( '.mw-summary-preset-item' );
summary = summary.replace( /\s+$/g, '' );
if ( summary != '' ) {
summary += ' ';
}
summary += $item.attr( 'title' ) || $this.text();
$this.replaceWith( $this.contents() );
$( '#wpSummary' ).val( summary ).focus();
} );
} ); } )( jQuery, mediaWiki );
}
// 102. 功能:封面画册JS代码
<script>
// 核心轮播逻辑
const slides = document.querySelectorAll('.carousel-slide');
const slideContainer = document.querySelector('.carousel-slides');
const prevBtn = document.querySelector('.prev');
const nextBtn = document.querySelector('.next');
const carouselContainer = document.getElementById('carousel-container');
let currentSlide = 0;
const slideCount = slides.length;
const intervalTime = 3000; // 轮播间隔3秒
let autoPlayInterval;
// 更新轮播显示
function updateSlidePosition() {
slideContainer.style.transform = `translateX(-${currentSlide * 100}%)`;
}
// 下一张
function nextSlide() {
currentSlide = (currentSlide + 1) % slideCount;
updateSlidePosition();
}
// 上一张
function prevSlide() {
currentSlide = (currentSlide - 1 + slideCount) % slideCount;
updateSlidePosition();
}
// 自动播放
function startAutoPlay() {
autoPlayInterval = setInterval(nextSlide, intervalTime);
}
// 暂停自动播放
function stopAutoPlay() {
clearInterval(autoPlayInterval);
}
// 绑定按钮事件
prevBtn.addEventListener('click', prevSlide);
nextBtn.addEventListener('click', nextSlide);
// 鼠标悬停暂停,离开继续
carouselContainer.addEventListener('mouseenter', stopAutoPlay);
carouselContainer.addEventListener('mouseleave', startAutoPlay);
// 初始化
updateSlidePosition();
startAutoPlay();
</script>
</div>
//103.插入PIC按钮
mw.loader.using(['mediawiki.util']).then(function() {
// 只在编辑页面生效
if (mw.config.get('wgAction') !== 'edit') return;
if (mw.config.get('wgPageContentModel') !== 'wikitext') return;
$('<button>')
.text('插入PIC')
.css({
position: 'fixed',
top: '50px',
right: '10px',
'z-index': 9999,
padding: '8px 16px',
'font-size': '13px',
background: '#f8f9fa',
border: '1px solid #a2a9b1',
'border-radius': '2px',
cursor: 'pointer'
})
.hover(function() {
$(this).css('background', '#e0e0e0');
}, function() {
$(this).css('background', '#f8f9fa');
})
.click(function() {
var $textbox = $('#wpTextbox1');
var cursor = $textbox.textSelection('getCaretPosition');
// 准备要插入的模板(注意:故意把|后面加空格避免部分情况下触发预览bug)
var toInsert = '{{pic|外链=\n|描述=\n}}';
// 在光标位置插入
$textbox.textSelection('encapsulateSelection', {
pre: '',
peri: toInsert,
post: '',
replace: false, // 不替换选中内容,只插入
selectPeri: false // 插入后不选中刚插入的内容
});
// 尝试把光标放在第一个参数里面比较友好
var newText = $textbox.textSelection('getContents');
var insertPos = cursor.start + toInsert.indexOf('= ') + 2;
$textbox.textSelection('setSelection', { start: insertPos, end: insertPos });
// 可选:让编辑框重新获得焦点
$textbox.focus();
})
.appendTo('body');
});