User:NhacNy2412/RedundantParameters.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
// Install with:
// <code><nowiki> importScript ('User:NhacNy2412/RedundantParameters.js'); // Backlink: [[m:User:NhacNy2412/RedundantParameters.js]] </nowiki></code>
// or with
// <code><nowiki> mw.loader.load('//meta.wikimedia.org/w/index.php?title=User:NhacNy2412/RedundantParameters.js&action=raw&ctype=text/javascript'); </nowiki></code>
//
// If forking this script, please note my contributions / give me credit
$(() => {
const RedundantParameters = {};
window.RedundantParameters = RedundantParameters;
RedundantParameters.config = {
name: '[[m:User:NhacNy2412/RedundantParameters.js|RedundantParameters.js]]',
debug: false
};
RedundantParameters.summary = (mw.config.get('wgDBname') == 'viwiki') ? "Xóa tham số thừa" : "Delete deprecated parameters";
RedundantParameters.run = function () {
if (RedundantParameters.config.debug) {
console.log (RedundantParameters.summary);
}
var api = new mw.Api();
api.get({
action: 'query',
titles: mw.config.get('wgPageName'),
prop: 'revisions',
rvprop: 'content',
rvslots: 'main',
formatversion: 2
}).done(
function (response) {
console.log(response);
var text = response.query.pages[0].revisions[0].slots.main.content;
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|laydate|separator|laysummary|lastauthoramp)\s*=[a-zA-Z0-9\sóô]*([^\b])/gi,
/\|\s*1\s*=\s*([^\b])/gi,
/\|\s*(writing|lyrics|music|arranger|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,
];
for (i = 0; i < textEdit.length; i++) {
text = text.replace(textEdit[i],'pages=');
}
for (i = 0; i < delpara.length; i++) {
text = text.replace(delpara[i],"$1");
}
text = text.replace(/isbn *= *ISBN/gi,'isbn=');
editionEdit = [
/\|edition\s*=[a-zA-Z\sứ]*(\d+)[a-zA-Z\s\.]*([^\b])/gi,
/\|edition\s*=([a-zA-Z0-9\sứ]*)ed\.([^\b])/gi,
/\|edition\s*=([a-zA-Z0-9\sứ]*)edition([^\b])/gi
];
for (let i = 0; i < editionEdit.length; i++) {
text = text.replace(editionEdit[i],"|edition =$1 $2");
}
//text = text.replace(/\|edition\s*=[a-zA-Z\sứ]*(\d+)[a-zA-Z\s\.]*([^\b])/gi, "|edition = $1 $2");
//text = text.replace(/\|edition\s*=(\w*)e|E/gi, "|edition = $1 $2");
api.postWithEditToken({
action: 'edit',
title: mw.config.get('wgPageName'),
text: text,
minor: true,
summary: RedundantParameters.summary
}).done(
function() {
location.reload();
}
);
}
);
};
});
$(document).ready (() => {
mw.loader.using(
[ 'mediawiki.util' ],
function () {
var link = mw.util.addPortletLink('p-cactions', '#', 'Xóa para thừa', 'ca-dlp');
$(link).click (function (event) {
event.preventDefault();
mw.loader.using('mediawiki.api', window.RedundantParameters.run);
});
}
);
});