User:魔琴/gadgets/Quick102/Quick102.js
外观
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google Chrome、Firefox、Microsoft Edge及Safari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
// Uses scripts from [[:en:Wikipedia:User_scripts/Guide]], [[:en:User:Evad37/MoveToDraft.js]] and [[:zh:User:Hamish/massmove.js]]
// v1.1.1-beta
// <nowiki>
$(document).ready( function () {
var API = new mw.Api();
function ShowQuick102() {
var username = mw.config.get( 'wgUserName' );
var userpage = mw.config.get( 'wgTitle' );
if ( userpage === username ) {
var really = 1;
}
var userpagebase = userpage.replace(/\/.*$/, "");
if ( userpagebase === username && mw.config.get( 'wgNamespaceNumber' ) === 2 && /autoconfirmed|confirmed/.test( mw.config.get('wgUserGroups')) ){
var link = mw.util.addPortletLink( 'p-cactions', '#', '快速102', 'ca-quick102', '快速发布草稿');
$( link ).click( function ( event ) {
event.preventDefault();
userpage = mw.config.get( 'wgPageName' );
var articlepage = userpage.replace(/^.*\//, "");
if (really === 1){
r = confirm ('您真的要把自己的用户页移走吗?');
if (!r){return}
articlepage = '';
}
articlepage = prompt("请输入条目名", articlepage);
if (articlepage === null) {return}
MovePage(userpage,articlepage);
} );
}
}
// 移动页面
function MovePage(userpage,articlepage) {
var promise = API.postWithToken( 'csrf', {
action: 'move',
from: userpage,
to: articlepage,
movetalk: 1,
noredirect: 1,
reason: "使用[[User:魔琴/gadgets/Quick102|快速102]]发布新条目"
} ).then( function ( result ) {
setTimeout( function () {
TagO1(userpage);
window.location.href = mw.util.getUrl( articlepage );
}, 5000 );
}, function ( err ) {
alert ("发布失败");
});
}
// 加入O1
function TagO1(o1page) {
if (!/sysop|patroller|rollbacker/.test(mw.config.get('wgUserGroups'))) {
API.postWithToken( 'csrf', {
action: 'edit',
title: o1page,
prependtext: '{'+'{d|O1}}\n',
summary: '条目已发布至主命名空间,请求快速删除([[WP:O1|CSD O1]])'
} );
}
}
mw.loader.using( 'mediawiki.util', function () {
ShowQuick102();
} );
} );
// </nowiki>