User:小躍/Tool/Tool.js
< User:小躍
注意:垃拉保存之后,侬作兴要清除浏览器个缓存才好看见改变。
- Firefox或Safari:揿牢“Shift”个同时点击“刷新”,或揿“Ctrl-F5”或“Ctrl-R”(Mac上是“⌘-R”)
- Google Chrome:揿“Ctrl-Shift-R”(Mac上是“⌘-Shift-R”)
- Internet Explorer / Edge:揿牢“Ctrl”个同时点击“刷新”,或揿“Ctrl-F5”
- Opera:去到菜单 → 设置(Mac上是Opera → 偏好设定),再转到隐私&安全 → 清除浏览数据 → 缓存个图片搭文件。
//[[en:User:Kaldari/wikilove.js]]變化版<nowiki>
if ((wgNamespaceNumber !== -1 && wgAction == 'view' && skin == 'vector' )) {
// Script depends on jQuery dialog widget
mw.loader.using( 'jquery.ui', function() {
// Construct object (to prevent namespace conflicts)
toolbox = {
displayProgress: function( form, message ) {
$('#'+form+' div').hide(); // remove everything else from the dialog box
$('#'+form).append ( $('<div style="text-align:center;margin:3em 0;"></div>').html( message+'<br/><img src="http://upload.wikimedia.org/wikipedia/commons/4/42/Loading.gif" />' ) );
},
displayError: function( form, error ) {
$('#'+form+' div').hide(); // remove everything else from the dialog box
$('#'+form).append ( $('<div style="color:#990000;margin-top:0.4em;"></div>').html( '錯誤: '+error ) );
},
getEditToken: function() {
$.ajax({
url: wgScriptPath + '/api.php?',
data: 'action=query&prop=info&intoken=edit&titles=Main%20Page&indexpageids&format=json',
dataType: 'json',
success: function( data ) {
if ( data.query.pages && data.query.pageids ) {
var pageid = data.query.pageids[0];
toolbox.editToken = data.query.pages[pageid].edittoken;
}
}
});
},
getEmailable: function() {
// Test to see if the 'E-mail this user' link exists
toolbox.emailable = $('#t-emailuser').length ? true : false;
},
editPage: function( form, summary, template ) {
$.ajax({
url: wgScriptPath + '/api.php?',
data: 'action=edit&title='+encodeURIComponent(mw.config.get('wgPageName'))+'§ion=0&summary=標記請求速刪模板('+$('#edittipsSelect').val()+'),使用[[User:小躍/Tool/Tool.js|Toolbox設置]]。&prependtext='+encodeURIComponent(template)+'&format=json&token='+encodeURIComponent(toolbox.editToken),
dataType: 'json',
type: 'POST',
success: function( data ) {
if ( data.edit.result == "Success" ) {
window.location.reload();
} else {
toolbox.displayError( form, 'API結果不明。請嘗試登出維基百科,再次登入維基百科並返回本頁再次加入重定向模板。' );
}
},
error: function( xhr ) {
toolbox.displayError( form, '編輯錯誤。請嘗試重新整理本頁,並再次加入重定向模板。' );
//console.debug( xhr.responseText );
}
});
},
sendEmail: function( form, subject, text ) {
$.ajax({
url: wgScriptPath + '/api.php?',
data: 'action=emailuser&target='+encodeURIComponent(wgTitle)+'&subject='+encodeURIComponent(subject)+'&text='+encodeURIComponent(text)+'&format=json&token='+encodeURIComponent(toolbox.editToken),
dataType: 'json',
type: 'POST'
});
},
launchDialog: function( interface, emailOption ) {
// If user is emailable, add email checkbox to forms that request it
if ( emailOption && typeof toolbox.emailable !== 'undefined' && toolbox.emailable ) {
if ( typeof interface.data('emailCheckboxAppended') == 'undefined' ) {
interface.append( $('<div style="margin-top:0.4em;"></div>').html('<input type="checkbox" name="notify"/> 用電郵通知這個用戶(注意:一般新用戶在編輯用戶討論頁時系統會有自動電郵)') );
interface.data('emailCheckboxAppended', true);
}
}
// Open the dialog box
interface.dialog('open');
// Retrieve the edit token so it will be available when the form is submitted
toolbox.getEditToken();
},
initialize: function() {
// Function to make a list of images selectable
$.fn.selectItem = function() {
return this.each(function() {
var containerId = this.id;
var customId = 0;
$('#'+containerId+' img').css('border', '8px solid transparent');
$('#'+containerId+' img').each(function() {
if (this.id == '') {
this.id = 'select_img_' + customId;
customId++;
}
$('#'+this.id).click(function() {
$('#'+containerId+'Selected').val(this.title);
$('#'+containerId+' img').css('border', '8px solid transparent');
$('#'+this.id).css('border', '8px solid #AED0EA');
})
});
});
};
// List of all available edittipss
var $edittipsList = [
'G1',
'G2',
'G3',
'G10',
'G11',
'G12',
'G13',
'G14',
'G15',
'G16',
'G17',
'A1',
'A2',
'A3',
'A5',
'A6',
'R2',
'R3',
'R5',
'F1',
'F3',
'F4',
'F5',
'F6',
'F7',
'O1',
'O3',
'O4'
];
// Define edittips interface
$wlEdittipss = $('<div id="edittipsForm" style="position:relative;"></div>')
.append( $('<div style="margin-top:0.4em;"></div>').html( '快速刪除種類: ' ).append( $('<select id="edittipsSelect" style="padding:1px;vertical-align:baseline;"></select>') ) )
.dialog({
width: 500,
autoOpen: false,
title: '工具箱模板',
modal: true,
buttons: { "儲存編輯": function() {
$(this).dialog({buttons:{}});
if ( typeof toolbox.editToken !== 'undefined' ) {
if ( $('#edittipsForm input[name="notify"]').attr('checked') ) {
// Send email
toolbox.sendEmail( 'edittipsForm', '維基百科重定向模板設置', '你好 '+wgTitle+'!\n\n有用戶給了你一個關於「'+$('#edittipsSelect').val()+'」的維基百科重定向模板設置,目前在你的中文維基百科用戶討論頁上待你查閱,希望你能積極參與維基百科。' );
}
// Perform edit to page
toolbox.displayProgress( 'edittipsForm', '正在儲存編輯,請稍後......' );
var template = '{{d|'+$('#edittipsSelect').val()+'}}' ;
toolbox.editPage( 'edittipsForm', '', template );
} else {
toolbox.displayError( 'edittipsForm', '無法完成編輯' );
}
}}
});
// Populate edittips select list
$.each( $edittipsList, function(index, value) { $('#edittipsSelect').append( $('<option></option>').val(value).html(value) ); });
// Insert new tab into page
var menuEdittips = '<li id="wl-edittips"><span><a onclick="toolbox.launchDialog( $wlEdittipss, true ); return false;" href="#">速刪</a></span></li>';
var toolboxMenu = '<div class="vectorMenu" id="p-toolbox"><a href="#" style="padding:0 0.4em;width:auto;"><span style="display:inline-block;height:2.5em;width:30px;margin-right:28px;background-position:0 60%;background-image:url(https://upload.wikimedia.org/wikipedia/commons/thumb/3/31/Redirect_arrow_without_text.svg/46px-Redirect_arrow_without_text.svg.png);background-repeat:no-repeat;"> </span></a><div class="menu"><ul>'+menuEdittips+'</ul></div></div>';
$('#p-cactions').after(toolboxMenu);
} // close initialize function
} // close toolbox object
toolbox.initialize();
toolbox.getEmailable();
}) // close mw.loader
} // close if
//</nowiki>