مدیاویکی:Gadget-close.js: تفاوت میان نسخهها
ظاهر
imported>Yamaha5 بدون خلاصۀ ویرایش |
imported>Yamaha5 بدون خلاصۀ ویرایش |
||
| خط ۱۳: | خط ۱۳: | ||
rvsection: sectionId | rvsection: sectionId | ||
}).then(function (data) { | }).then(function (data) { | ||
var editsummary = 'به کمک [[مدیاویکی:Gadget-close.js|ابزار جمعبندی]] | var editsummary = ' (به کمک [[مدیاویکی:Gadget-close.js|ابزار جمعبندی]])'; | ||
var str = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*']; | var str = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*']; | ||
var title = (str.match(/^(=+)[^=]*?(\1)$/m) || [''])[0]; | var title = (str.match(/^(=+)[^=]*?(\1)$/m) || [''])[0]; | ||
| خط ۲۷: | خط ۲۷: | ||
str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}\n'''" + the_reason + "'''\n"); | str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}\n'''" + the_reason + "'''\n"); | ||
str = str + "\n{{پایان بسته}}"; | str = str + "\n{{پایان بسته}}"; | ||
editsummary = | editsummary = 'جمعبندی شد' + editsummary; | ||
} else if (type === 'talk') { | } else if (type === 'talk') { | ||
the_reason = "|" + the_reason; | the_reason = "|" + the_reason; | ||
str = str.replace(title, title + "\n{{بحث بسته" + the_reason + "}}"); | str = str.replace(title, title + "\n{{بحث بسته" + the_reason + "}}"); | ||
str = str + "\n{{پایان بسته}}"; | str = str + "\n{{پایان بسته}}"; | ||
editsummary = | editsummary = 'جمعبندی شد' + editsummary; | ||
} else if (type === 'done') { | } else if (type === 'done') { | ||
str = str + "\n:{{شد}} " + the_reason + ' ~~' + '~~'; | str = str + "\n:{{شد}} " + the_reason + ' ~~' + '~~'; | ||
editsummary = | editsummary = 'انجام شد' + editsummary; | ||
} else if (type === 'approve') { | } else if (type === 'approve') { | ||
str = str + "\n:{{موافق}} " + the_reason + ' ~~' + '~~'; | str = str + "\n:{{موافق}} " + the_reason + ' ~~' + '~~'; | ||
editsummary = | editsummary = 'موافقم' + editsummary; | ||
} else if (type === 'appose') { | } else if (type === 'appose') { | ||
str = str + "\n:{{مخالف}} " + the_reason + ' ~~' + '~~'; | str = str + "\n:{{مخالف}} " + the_reason + ' ~~' + '~~'; | ||
editsummary = | editsummary = 'مخالفم' + editsummary; | ||
} | } | ||
new mw.Api().post({ | new mw.Api().post({ | ||
format: 'json', | format: 'json', | ||
| خط ۸۸: | خط ۸۸: | ||
$('.mw-headline').each(function (data) { | $('.mw-headline').each(function (data) { | ||
var section = $(this); | var section = $(this); | ||
addLink(section, data + 1, 'approve', '☺', '#090', ' | addLink(section, data + 1, 'approve', '☺', '#090', 'موافقم'); | ||
addLink(section, data + 1, 'appose', '☹', '#DF0101', ' | addLink(section, data + 1, 'appose', '☹', '#DF0101', 'مخالفم'); | ||
}); | }); | ||
}else if (mw.config.get('wgNamespaceNumber') % 2 != 0) {//برای صفحات بحث | }else if (mw.config.get('wgNamespaceNumber') % 2 != 0) {//برای صفحات بحث | ||
نسخهٔ ۲۱ ژانویهٔ ۲۰۱۵، ساعت ۲۰:۰۲
/* by Arash.pt & Ebraminio */
/*global $, mw, prompt, confirm*/
/*jslint white: true, regexp: true, vars: true*/
$(function () {
'use strict';
function answered(sectionId, type) {
new mw.Api().get({
format: 'json',
action: 'query',
titles: mw.config.get('wgPageName'),
prop: 'revisions',
rvprop: 'content',
rvsection: sectionId
}).then(function (data) {
var editsummary = ' (به کمک [[مدیاویکی:Gadget-close.js|ابزار جمعبندی]])';
var str = data.query.pages[Object.keys(data.query.pages)[0]].revisions[0]['*'];
var title = (str.match(/^(=+)[^=]*?(\1)$/m) || [''])[0];
var the_reason = prompt("توضیح در مورد بستن بحث؟");
if (the_reason.length <= 1) { the_reason = ""; }
if (type === 'request') {
var requestStatus = confirm('آیا درخواست انجام شده است؟ یا ناموفق بود؟');
var the_reason2 = "";
if (!requestStatus) {
the_reason2 = "|ناموفق=بله";
}
the_reason = the_reason + ' ~~' + '~~';
str = str.replace(title, title + "\n{{بسته" + the_reason2 + "}}\n'''" + the_reason + "'''\n");
str = str + "\n{{پایان بسته}}";
editsummary = 'جمعبندی شد' + editsummary;
} else if (type === 'talk') {
the_reason = "|" + the_reason;
str = str.replace(title, title + "\n{{بحث بسته" + the_reason + "}}");
str = str + "\n{{پایان بسته}}";
editsummary = 'جمعبندی شد' + editsummary;
} else if (type === 'done') {
str = str + "\n:{{شد}} " + the_reason + ' ~~' + '~~';
editsummary = 'انجام شد' + editsummary;
} else if (type === 'approve') {
str = str + "\n:{{موافق}} " + the_reason + ' ~~' + '~~';
editsummary = 'موافقم' + editsummary;
} else if (type === 'appose') {
str = str + "\n:{{مخالف}} " + the_reason + ' ~~' + '~~';
editsummary = 'مخالفم' + editsummary;
}
new mw.Api().post({
format: 'json',
action: 'edit',
title: mw.config.get('wgPageName'),
section: sectionId,
summary: editsummary,
text: str,
token: mw.user.tokens.get('editToken')
}).then(function () {
mw.notify('انجام شد');
location.reload(true);
});
});
}
function addLink(section, sectionId, type, html, color, title) {
$('<a>', {
id: 'answerIcon' + sectionId,
href: '#',
title: title,
style: 'float: left; color: ' + color,
html: html
}).click(function (e) {
e.preventDefault();
answered(sectionId, type);
}).insertBefore(section);
}
if (mw.config.get('wgNamespaceNumber') === 3 && mw.config.get('wgPageName').search(mw.config.get('wgUserName')) > 0) {
$('.mw-headline').each(function (data) {
var section = $(this);
addLink(section, data + 1, 'talk', '❐', '#090', 'جمعبندی بحث');
addLink(section, data + 1, 'done', '✓', '#003A5C', '✓ شد');
});
} else if (mw.config.get('wgNamespaceNumber') === 4){
if (mw.config.get('wgUserGroups').indexOf('sysop') > -1) {
$('.mw-headline').each(function (data) {
var section = $(this);
addLink(section, data + 1, 'request', '❐', '#090', 'جمعبندی بحث');
addLink(section, data + 1, 'done', '✓', '#003A5C', '✓ شد');
});
}
$('.mw-headline').each(function (data) {
var section = $(this);
addLink(section, data + 1, 'approve', '☺', '#090', 'موافقم');
addLink(section, data + 1, 'appose', '☹', '#DF0101', 'مخالفم');
});
}else if (mw.config.get('wgNamespaceNumber') % 2 != 0) {//برای صفحات بحث
$('.mw-headline').each(function (data) {
var section = $(this);
addLink(section, data + 1, 'done', '✓', '#003A5C', '✓ شد');
});
}
});