MediaWiki:Group-sysop.js:修订间差异
MediaWiki界面页面
更多操作
// Edit via Wikiplus |
无编辑摘要 |
||
| (未显示同一用户的10个中间版本) | |||
| 第2行: | 第2行: | ||
/* global mediaWiki */ | /* global mediaWiki */ | ||
//<pre> mw傻逼,不写<pre/>三个以上波浪号全都要替换,傻得要死 | //<pre> mw傻逼,不写<pre/>三个以上波浪号全都要替换,傻得要死 | ||
(function () { | (function(mw) { | ||
if (!String.prototype.includes) String.prototype.includes = function includes(search, start) { | if (!String.prototype.includes) String.prototype.includes = function includes(search, start) { | ||
'use strict'; | 'use strict'; | ||
| 第9行: | 第9行: | ||
return this.indexOf(search, start) !== -1; | return this.indexOf(search, start) !== -1; | ||
}; | }; | ||
function | mw.loader.implement('AnnToolsSendWelcomeMessage', function() { | ||
var message = '{{Template:欢迎}} ——~~~~{{clear}}', | var message = '{{Template:欢迎}} ——~~~~{{clear}}', | ||
errorFun = function errorFun( | errorFun = function errorFun(textStatus, self) { | ||
$('#welcomeAsk').empty().append('<span id="welcomeAskFinished">通信失败,请刷新或重试【' + textStatus + '】……</span>'); | |||
unbindFun(); | |||
self.addClass('unsend'); | |||
return false; | return false; | ||
}, | }, | ||
| 第18行: | 第20行: | ||
if ($('#welcomeClear').length > 0) $('#welcomeClear').remove(); | if ($('#welcomeClear').length > 0) $('#welcomeClear').remove(); | ||
$('#welcomeAsk').append('<span id="welcomeClear">返回</span>'); | $('#welcomeAsk').append('<span id="welcomeClear">返回</span>'); | ||
$('#welcomeClear'). | $('#welcomeClear').on('click.welcome', function() { | ||
$('#welcomeAsk').remove(); | $('#welcomeAsk').remove(); | ||
}); | }); | ||
} | }; | ||
if (mw.config.get('wgNamespaceIds').user_talk == mw.config.get('wgNamespaceNumber') && !mw.config.get('wgPageName').includes('/') && mw.config.get('wgEditMessage') == 'creating' && $('#wpTextbox1')[0] && !$('#wpTextbox1').val()) $('#wpTextbox1').val(message); | if (mw.config.get('wgNamespaceIds').user_talk == mw.config.get('wgNamespaceNumber') && !mw.config.get('wgPageName').includes('/') && mw.config.get('wgEditMessage') == 'creating' && $('#wpTextbox1')[0] && !$('#wpTextbox1').val()) $('#wpTextbox1').val(message); | ||
$('#mw-content-text a.new'). | |||
function check(that, onClick) { | |||
if (!$(that).is('#mw-content-text a.new')) return; | |||
if (!/(?=title\=用户讨论\:)[^\&]+/i.test(decodeURI(that.href))) return; | |||
try { | |||
var self = $(that), | |||
href = decodeURI(self.attr('href')), | |||
userName = href.match(/(?=用户讨论\:)[^\&]+/i)[0].replace(/用户讨论\:/i, ''); | |||
} catch (e) { | |||
return; | |||
} | |||
if (href.includes('用户讨论') && href.includes('redlink=1') && href.includes('action=edit') && !userName.includes('/')) { | |||
self.addClass('sendWelcomeMessageLink unsend nopopus').on('click.sendWelcomeMessage', function() { | |||
if ($('#welcomeAskFinished')[0]) $('#welcomeClear').click(); | |||
if ($('#welcomeAsk')[0]) { | |||
self.after('<span class="welcomeAsk">一次只能发送一份欢迎辞哦,不要太贪心了~<span id="welcomeClear2">返回</span></span>'); | |||
$('#welcomeClear2').on('click.welcome', function() { | |||
$(this).parent().remove(); | |||
}); | |||
return false; | |||
} | |||
if (/[&\/]+/.test(userName)) { | |||
window.open(href, '_blank'); | |||
return errorFun('地址解析出错!\n原地址:' + href + ',解析用户讨论页标题结果:User talk:' + userName); | |||
} | |||
self.removeClass('unsend').after('<span id="welcomeAsk">你想直接发送欢迎辞还是访问该未创建页面?<span id="welcomeYes">发送欢迎辞</span> · <span id="welcomeNo">访问该页面</span> · <span id="welcomeClear">返回</span></span>'); | |||
$('#welcomeNo').on('click.welcome', function() { | |||
window.open(href, '_blank'); | |||
}); | |||
$('#welcomeClear').on('click.welcome', function() { | |||
$('#welcomeAsk').remove(); | |||
}); | }); | ||
$('#welcomeYes').on('click.welcome', function() { | |||
var api = new mw.Api(); | |||
$('#welcomeAsk').empty().append('正在通信中……'); | |||
api.postWithToken('csrf', { | |||
'action': 'edit', | |||
'format': 'json', | |||
'title': '用户讨论:' + userName, | |||
'summary': 'Welcome to ZJSNR Wiki', | |||
'text': message | |||
}).then(function(data) { | |||
$('#welcomeAsk').empty().append('<span id="welcomeAskFinished">通信成功!继续努力哦~</span>'); | |||
console.debug('和萌百服务器通信成功,编辑成功! \n' + (data.error != 'internal_api_error_Exception' ? ('编辑详情:' + JSON.stringify(data).replace(/[{}\"]/g, '').replace(/\:\,/, ',')) : '萌百服务器返回"internal_api_error_Exception",你们都懂的_(:3 」∠ )_ ') + '。'); | |||
$('#welcomeAsk').empty().append(' | |||
unbindFun(); | unbindFun(); | ||
$('#mw-content-text a.new[href="' + encodeURI(href) + '"]').removeClass('new sendWelcomeMessageLink unsend').attr('href', '/User_talk:' + userName).unbind('click.sendWelcomeMessage'); //js<a>对象的href是绝对url…… | |||
}, function(textStatus, status) { | |||
if (textStatus === 'internal_api_error_Exception') { | |||
$('#welcomeAsk').empty().append('<span id="welcomeAskFinished">通信成功!继续努力哦~</span>'); | |||
console.debug('和萌百服务器通信成功,编辑成功! \n萌百服务器返回"internal_api_error_Exception",你们都懂的_(:3 」∠ )_ 。'); | |||
unbindFun(); | |||
$('#mw-content-text a.new[href="' + encodeURI(href) + '"]').removeClass('new sendWelcomeMessageLink unsend').attr('href', '/User_talk:' + userName).unbind('click.sendWelcomeMessage'); //js<a>对象的href是绝对url…… | |||
} else if ($.isPlainObject(status)) { | |||
$('#welcomeAsk').empty().append('<span id="welcomeAskFinished">正在通信中(2/2)……失败!请重试!</span>'); | |||
errorFun('和萌百服务器通信成功,但编辑失败!\n编辑详情:' + JSON.stringify(status).replace(/[{}\"]/g, '').replace(/\:\,/g, ',')); | |||
unbindFun(); | |||
self.addClass('unsend'); | |||
} else errorFun(textStatus, self); | |||
}); | |||
}); | |||
} | |||
}); | }); | ||
return false; | |||
}); | }); | ||
if (onClick) self.click(); | |||
return false; | return false; | ||
}) | } | ||
} | |||
$(document.body).on('click', function(event) { | |||
check(event.target, true); | |||
}); | |||
$('#mw-content-text a.new').each(function() { | |||
check(this); | |||
}); | }); | ||
$("<style id='sendWelcomeMessage'>#welcomeAsk,.welcomeAsk{border:#bbeeff 1px solid;margin:0 3px 0 7px} #welcomeYes,#welcomeNo,#welcomeClear,#welcomeClear2{cursor:pointer;color:purple}.sendWelcomeMessageLink.unsend:after{content:'S';color:purple;line-height:1;vertical-align:super;font-size:smaller}.sendWelcomeMessageLink{text-decoration:none!important}</style>").appendTo("head"); | |||
}); | }); | ||
})(); | })(mediaWiki); | ||
//</pre> | //</pre> | ||