User:LuciferianThomas/js/EditSummaries.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
$.when( mw.loader.using('mediawiki.util'), $.ready ).then( async function () {
if ( /[\?\&]action=(edit(source)?|submit)/.test( window.location.href ) ) {
let summaryBox = $( "#wpSummary" );
let res = await fetch( 'https://zh.wikipedia.org/w/index.php?title=User:LuciferianThomas/js/EditSummaries.json&action=raw&ctype=application/json' );
let customSummaries = JSON.parse( await res.text() );
let customSummaryDiv = $( '<div/>', {
style: 'padding: .25em 0; font-size: .857em;',
text: "自訂編輯摘要:"
} );
let entries = Object.entries( customSummaries );
entries.forEach( function ( [ key, sum ], i ) {
let span = $( '<span/>', {
class: 'mw-summary-preset-item'
} );
let summaryItem = $( "<a/>", {
href: "#.",
text: key
} ).click( function () {
if ( typeof sum !== "string" ) {
for ( i = 1; i < sum.length; i++ ) {
let input = prompt( sum[i] );
sum[0] = sum[0].replace( new RegExp( "\\$" + i, "g" ), input );
}
sum = sum[0];
}
summaryBox.val( summaryBox.val() + (
summaryBox.val().length && !/^\/\* .*? \*\/\s*$/.test( summaryBox.val() ) ? ";" : ""
) + sum );
$( this ).addClass( "mw-selflink selflink" );
$( this ).off( "click" );
} ).appendTo( span );
span.appendTo( customSummaryDiv );
} );
customSummaryDiv.append( $( "<span/>", { class: 'mw-summary-preset-item' } ).html(
'<a href="https://zh.wikipedia.org/w/index.php?title=User:LuciferianThomas/js/EditSummaries.json&action=edit" target="_blank">(+)</span>'
) );
console.log( customSummaryDiv );
$( 'label.oo-ui-labelElement-label[for="wpSummary"]' ).after( customSummaryDiv );
}
} );
mw.hook( 've.activationComplete' ).add( function () {
$( '.ve-ui-toolbar-saveButton' ).click( async function () {
if ( $('#custom-edit-summaries').length ) return;
let summaryBox = $( ".ve-ui-mwSaveDialog-summary .oo-ui-inputWidget-input" );
let res = await fetch( 'https://zh.wikipedia.org/w/index.php?title=User:LuciferianThomas/js/EditSummaries.json&action=raw&ctype=application/json' );
let customSummaries = JSON.parse( await res.text() );
let customSummaryDiv = $( '<div/>', {
style: 'padding: .25em 0; font-size: .857em;',
text: "自訂編輯摘要:",
id: "custom-edit-summaries"
} );
let entries = Object.entries( customSummaries );
entries.forEach( function ( [ key, sum ], i ) {
let span = $( '<span/>', {
class: 'mw-summary-preset-item'
} );
let summaryItem = $( "<a/>", {
href: "#.",
text: key
} ).click( function () {
if ( typeof sum !== "string" ) {
for ( i = 1; i < sum.length; i++ ) {
let input = prompt( sum[i] );
sum[0] = sum[0].replace( new RegExp( "\\$" + i, "g" ), input );
}
sum = sum[0];
}
summaryBox.val( summaryBox.val() + (
summaryBox.val().length && !/^\/\* .*? \*\/\s*$/.test( summaryBox.val() ) ? ";" : ""
) + sum );
$( this ).addClass( "mw-selflink selflink" );
$( this ).off( "click" );
} ).appendTo( span );
span.appendTo( customSummaryDiv );
} );
customSummaryDiv.append( $( "<span/>", { class: 'mw-summary-preset-item' } ).html(
'<a href="https://zh.wikipedia.org/w/index.php?title=User:LuciferianThomas/js/EditSummaries.json&action=edit" target="_blank">(+)</span>'
) );
console.log( customSummaryDiv );
$( ".ve-ui-mwSaveDialog-summaryLabel" ).after( customSummaryDiv );
} );
} );