Thành viên:NhacNy2412/MassEdit.js
Chú ý: Sau khi lưu thay đổi trang, bạn phải xóa bộ nhớ đệm của trình duyệt để nhìn thấy các thay đổi. Google Chrome, Firefox, Internet Explorer và Safari: Giữ phím ⇧ Shift và nhấn nút Reload/Tải lại trên thanh công cụ của trình duyệt. Để biết chi tiết và hướng dẫn cho các trình duyệt khác, xem Trợ giúp:Xóa bộ nhớ đệm.
///Tim's Mass Edit Tool
/// Adapted from [[User:Animum/DelPara.js]]
function doDelPara() {
document.getElementById("wpDelParaSubmit").disabled = true;
var articles = document.getElementById("wpDelParaPages").value.split("\n");
if(articles.length == 0) return;
var wpDelParaType = document.getElementById("wpDelParaType").value,
wpDelParaSummary = document.getElementById("wpDelParaSummary").value,
edited = 0, failed = [], error = [],
wpDelParaMinor = document.getElementById("wpDelParaMinor").checked,
onSuccess = function () {
edited++;
if(edited < articles.length)
document.getElementById("wpDelParaSubmit").value = "(" + edited + ")";
else
document.getElementById("wpDelParaSubmit").value = "Done (" + edited + ")";
};
for (i = 0; i < articles.length; i++) {
var article = articles[i];
if (article.length > 0) {
var pagetext = gettext(article);
if(wpDelParaType == "delpara"){
textEdit = [
/pages? ?= ?t?r?\.? ?pages?\.?\:?/gi,
/pages? ?= ?t?r?\.? ?p+g?\.?\:?/gi,
/các trang ?= ?t?r?\.? ?pages?\.\:??/gi,
/các trang ?= ?t?r?\.? ?p+g?\.?\:?/gi
];
delpara = [
/\|\s*month\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*laydate\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*separator\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*laysummary\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*lastauthoramp\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
///\|\s*1\s*=\s*([^\b])/gi,
/\|\s*writing\wcredits\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*lyrics\wcredits\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*music\wcredits\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*arranger\wcredits\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*producer\wcredits\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*longnote\wcolumn\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*ref\s*=\s*harv\s*([^\b])/gi,
/\|\s*df\s*=\s*\-\s*all([^\b])/gi,
];
for (let i = 0; i < textEdit.length; i++) {
pagetext = pagetext.replace(textEdit[i],'pages=');
}
for (let i = 0; i < delpara.length; i++) {
pagetext = pagetext.replace(delpara[i],"$1");
}
pagetext = pagetext.replace(/(isbn|pmc|volume) *= *(isbn|pmc|volume|vol)\.?/gi,'$1=');
pagetext = pagetext.replace(/\|\s*(editor-last|editor|editor-surname|editor-last1|editor-surname1|editor1|editor1-last|editor1-surname|editor-first|editor-given|editor-first1|editor-given1|editor1-first|editor1-given) *=(.*)\(edi?t?o?r?s?.?\)/gi, "|$1=$2");
pagetext = pagetext.replace(/\|\s*(editor-last|editor|editor-surname|editor-last1|editor-surname1|editor1|editor1-last|editor1-surname|editor-first|editor-given|editor-first1|editor-given1|editor1-first|editor1-given) *=(.*)\, edi?t?o?r?s?.?/gi, "|$1=$2");
issueEdit = [
/\|\s*(no|issue|number|số) *= *(no|issue|number|số|nr)\.?\:?/gi,
];
for (let i = 0; i < issueEdit.length; i++) {
pagetext = pagetext.replace(issueEdit[i],"|issue=");
}
editionEdit = [
/\|\s*edition\s*=[a-zA-Z\sứ]*(\d+)[a-zA-Z\s\.]*([^\b])/gi,
/\|\s*edition\s*=[a-zA-Z\sứ]*(\d+)[a-zA-Z\s]*ed\.[a-zA-Z\s\.]*([^\b])/gi,
/\|\s*edition\s*=([a-zA-Z0-9\sứ]*)edition([^\b])/gi,
/\|\s*edition\s*=[a-zA-Z\sứ]*(\d+)[a-zA-Z\s]*edn[a-zA-Z\s\.]*([^\b])/gi
];
for (let i = 0; i < editionEdit.length; i++) {
pagetext = pagetext.replace(editionEdit[i],"|edition=$1 $2");
}
//pagetext = pagetext.replace(/=\s*:/gi,"=");
wpDelParaSummary = "Xóa tham số thừa, ký tự thừa trong tham số";
}
else if (wpDelParaType == "nulleditcat") {
if (ZeroEditAllPagesInThisCategory.config.debug) {
console.log (ZeroEditAllPagesInThisCategory.summary);
}
let api = new mw.Api();
api.get({
action: 'query',
meta: 'tokens'
}).done(function(data) {
console.log(data);
let token = data.query.tokens.csrftoken;
api.get({
action: 'query',
list: 'categorymembers',
cmtitle: article,
cmlimit: 'max'
}).done(function(data) {
$.each(data.query.categorymembers, function() {
let page = article;
api.post({
action: 'edit',
pageid: page.getArticleID(),
summary: 'Null edit',
appendtext: '',
token: token
}).done(function(data){
console.log(page.title + ' must have been zero-edited');
});
});
});
});
}
else if (wpDelParaType == "convertAlbumChart") {
enVer = [
/\|\s*australia\s*\|/gi,
/\|\s*austria\s*\|/gi,
/\|\s*norway\s*\|/gi,
/\|\s*switzerland\s*\|/gi,
/\|\s*netherlands\s*\|/gi,
/\|\s*sweden\s*\|/gi,
/\|\s*france\s*\|/gi,
/\|\s*finland\s*\|/gi,
/\|\s*italy\s*\|/gi,
/\|\s*spain\s*\|/gi,
/\|\s*poland\s*\|/gi,
/\|\s*portugal\s*\|/gi,
/\|\s*germany\s*\|/gi,
/\|\s*germany2\s*\|/gi,
/\|\s*germany3\s*\|/gi,
/\|\s*germany4\s*\|/gi,
/\|\s*denmark\s*\|/gi,
/\|\s*czech\s*\|/gi,
/\|\s*greece\s*\|/gi,
/\|\s*UK\s*\|/gi,
/\|\s*UK2\s*\|/gi,
/\|\s*korea\s*\|/gi,
/\|\s*KoreaInt\s*\|/gi,
/\|\s*KoreaNat\s*\|/gi,
/\|\s*flanders\s*\|/gi,
/\|\s*wallonia\s*\|/gi,
];
viVer = [
"|Úc|",
"|Áo|",
"|Na Uy|",
"|Thụy Sĩ|",
"|Hà Lan|",
"|Thụy Điển|",
"|Pháp|",
"|Phần Lan|",
"|Ý|",
"|Tây Ban Nha|",
"|Ba Lan|",
"|Bồ Đào Nha|",
"|Đức|",
"|Đức 2|",
"|Đức 3|",
"|Đức 4|",
"|Đan Mạch|",
"|Cộng hòa Séc|",
"|Hy Lạp|",
"|Anh Quốc|",
"|Anh Quốc 2|",
"|Hàn Quốc|",
"|Hàn Quốc (quốc tế)|",
"|Hàn Quốc (quốc gia)|",
"|Vlaanderen|",
"|Wallonie|",
];
for (let i = 0; i < enVer.length; i++) {
pagetext = pagetext.replace(enVer[i],viVer[i]);
}
wpDelParaSummary = "Chuyển đổi tham số trong bản mẫu Album Chart";
}
var api = new mw.Api();
api.postWithEditToken({
action: 'edit',
title: article,
text: pagetext,
minor: true,
summary: wpDelParaSummary,
bot: true,
}).done(onSuccess);
}
}
}
function gettext(title){
var req = new XMLHttpRequest();
req.open("GET", mw.config.get('wgScriptPath') + "/api.php?action=query&prop=revisions&rvprop=content&format=json&indexpageids=1&titles="+encodeURIComponent(title), false);
req.send(null);
var response = eval('(' + req.responseText + ')');
pageid = response.query.pageids[0];
if (pageid == "-1") {
return '';
}
var pagetext = response.query.pages[pageid].revisions[0]['*'];
return pagetext;
}
function DelParaform() {
var bodyContent;
switch (mw.config.get('skin')) {
case 'modern':
bodyContent = 'mw_contentholder';
break;
case 'cologneblue':
bodyContent = 'article';
break;
case 'vector':
case 'monobook':
case 'vector':
default:
bodyContent = 'bodyContent';
break;
}
document.getElementsByTagName("h1")[0].textContent = "Sửa đổi hàng loạt";
document.title = "Sửa đổi hàng loạt - Wikipedia tiếng Việt";
document.getElementById(bodyContent).innerHTML = '<h3 id="siteSub">From Wikipedia, the free encyclopedia</h3><br /><br />'
+ '<form id="wpDelPara" name="wpDelPara">'
+ '<p>Hiện tại, đây là công cụ phục vụ mục đích cá nhân. Nếu không hiểu rõ cách công cụ hoạt động, vui lòng không thử!<p>'
+ '<b>Nếu bạn lạm dụng công vụ này, nó là lỗi <i>của bạn</i>, không phải tôi.</b>'
+ '<div id="wpDelParaFailedContainer"></div>'
+ '<br />'
+ 'Danh sách trang cần sửa đổi (mỗi trang một dòng):<br />'
+ '<textarea tabindex="1" name="wpDelParaPages" id="wpDelParaPages" rows="10" cols="80"></textarea>'
+ '<br /><br /><table style="background-color:transparent">'
+ '<tr><td>Loại sửa đổi:</td>'
+ '<td><select id="wpDelParaType">'
+ '<option value="delpara">Xóa para thừa</option>'
+ '<option value="convertAlbumChart">Chuyển đổi tham số Album Chart</option>'
+ '<option value="nulleditcat">Null edit all in cat</option>'
+ '</select></td></tr>'
+ '<tr><td>Tóm lược sửa đổi:</td>'
+ '<td><input type="text" value="Xóa tham số thừa, ký tự thừa trong tham số" id="wpDelParaSummary" name="wpDelParaSummary" maxlength="255" /></td></tr>'
+ '<tr><td>Sửa đổi nhỏ:</td>'
+ '<td><input type="checkbox" checked="true" id="wpDelParaMinor" name="wpDelParaMinor"/></td></tr>'
+ '<tr><td><input type="button" id="wpDelParaSubmit" name="wpDelParaSubmit" value="Edit" onclick="doDelPara()" /></td>'
+ '</form>';
}
if (mw.config.get('wgNamespaceNumber') == -1 &&
mw.config.get('wgCanonicalSpecialPageName') === 'Blankpage' &&
mw.config.get('wgTitle').split('/',2)[1] === 'DelPara') {
$(DelParaform);
}
ZeroEditAllPagesInThisCategory.config = {
name: '[[m:User:NhacNy2412/ZeroEditAllPagesInThisCategory.js|ZeroEditAllPagesInThisCategory.js]]',
debug: false
};
ZeroEditAllPagesInThisCategory.run = function () {
};