सदस्य:SM7/DiscussionCloser.js
सूचना: यह पृष्ठ सुरक्षित करने बाद, परिवर्तनों को देखने लिए ब्राउज़र का कैश ख़ाली करने की आवश्यकता हो सकती है।
- मोज़िला / फ़ायरफ़ॉक्स / सफ़ारी: shift hold करें जब आप reload क्लिक करते है, या Ctrl-Shift-R (अपल मैक में Cmd-Shift-R) दबाएँ;
- गूगल क्रोम: Ctrl-shift-R (मैक में Cmd-Shift-R) दबाएँ
- इंटरनेट एक्सप्लोरर: Ctrl hold करें जब आप refresh क्लिक करते हैं, या Ctrl-F5 क्लिक करते हैं;
- कॉङ्करर: सिर्फ़ Reload बटन पर क्लिक करें, या F5 क्लिक करें;
- ऑपरा सदस्य को Tools→Preferences में सम्पूर्ण कैश ख़ाली करने की ज़रूरत हो सकती है।
//<nowiki>
//Credits to Equazcion, Evad37, and Abelmoschus Esculentus and DannyS712
//Original on enwiki:
//Date: 6 Mar 2019
//Forked from [[User:Abelmoschus Esculentus/DiscussionCloser.js]
//Maintained by DannyS712
//On hiwiki:
//Date: 25 Dec 2021
//Imported from [[:en:User:DannyS712/DiscussionCloser.js]
//Maintained by SM7
var DiscussionCloser_config = {
name: '[[User:SM7/DiscussionCloser|DiscussionCloser]]',
version: '1.7.3',
debug: false
};
var DiscussionCloser_ending = ' (' + DiscussionCloser_config.name + ' v.' + DiscussionCloser_config.version + ')';
/* HELPER FUNCTIONS */
function dc_make_bottom(template){
var bottom;
switch (template) {
case "subst:dtop":
bottom = "subst:dbot";
break;
case "atop":
case "atopr":
case "atopy":
case "atopg":
case "subst:RMT":
bottom = "abot";
break;
case "hat":
bottom = "hab";
break;
}
bottom = "{{" + bottom + "}}";
return bottom;
}
function alreadyClosed ( content ){
content = content.toLowerCase();
if (content.includes('{{dtop') ||
content.includes('{{atop') ||
content.includes('{{hat') ||
content.includes('{{abot') ||
content.includes('{{archive') ||
content.includes('{{archive bottom') ||
content.includes('{{hidden archive bottom') ||
content.includes('{{चर्चा शीर्ष') ||
content.includes('{{चर्चा तल') ||
content.includes('<!-- साँचा:चर्चा शीर्ष से -->') ||
content.includes('<!-- साँचा:चर्चा तल से -->') ||
content.includes('<!-- साँचा:Rm top से -->')
) return true;
return false;
}
function dc_radio(i) {
$('#DC-e').val("");
if (i == 1) {
$('#DC-e').prop('disabled', false);
}
if (i == 2) {
$('#DC-e').prop('disabled', true);
}
}
/* MAIN FUNCTIONs */
function dc_init(){
if ((($('#ca-addsection').length > 0) ||
(mw.config.get('wgPageName') == 'विकिपीडिया:प्रबन्धक_सूचनापट') ||
(mw.config.get('wgPageName') == 'विकिपीडिया:समाचार/उम्मीदवार')) &&
(mw.config.get('wgAction') == 'view')) {
dc_run();
}
}
function dc_run() {
$('span.mw-headline').each(function(index, value){
var editSectionUrl = $(this).parent().find('.mw-editsection a:first').attr('href');
var sectionReg = /§ion=(.*)/;
var sectionRaw = sectionReg.exec(editSectionUrl);
if ((sectionRaw !== null) && (sectionRaw[1].indexOf('T') < 0)){
var section = parseInt(sectionRaw[1]);
var sectionLevel = false;
switch ($(this).parent().prop("tagName")) {
case 'H2':
sectionLevel = 'h2';
break;
case 'H3':
sectionLevel = 'h3';
break;
case 'H4':
sectionLevel = 'h4';
break;
default:
break;
}
if (sectionLevel && sectionLevel !== false) {
$(this).parent(sectionLevel).append(' <div style="font-size:.6em;font-weight:bold;float:right"> | <a id="' + section +
'" class="closeLink">' + 'चर्चा बंद करें' + '</a></div>');
$(this).parent(sectionLevel).find('a.closeLink').click(function(){
$('body').prepend('<div id="DC-modal">'+
'<div id="DC-interface">'+
'<h4 id="DC-interface-header"></h4>'+
'<hr>'+
'<div id="DC-interface-content"></div>'+
'<hr>'+
'<div id="DC-interface-footer"></div>'+
'</div>'+
'</div>');
$("#DC-interface-header, #DC-interface-content, #DC-interface-footer").empty();
$("#DC-interface-header").text("चर्चा समापन उपकरण");
$("#DC-interface-content").append(
$('<div class="DC-bottom">').append(
$('<label>').attr({'id':'DC-label'}).text('विकल्प: '),
$('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio1','value':'subst:dtop','checked':'true','onchange':'dc_radio(2)'}),
$('<label>').text('सामान्य चर्चा'),
$('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio2','value':'atop', 'onchange':'dc_radio(1)'}),
$('<label>').text('पुरालेखन (नीला) '),
/* $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio3','value':'atopg','onchange':'dc_radio(1)'}),
$('<label>').text('पुरालेखन (हरा) '),
$('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio4','value':'atopy','onchange':'dc_radio(1)'}),
$('<label>').text('पुरालेखन (पीला) '),
$('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'atopr','onchange':'dc_radio(1)'}),
$('<label>').text('पुरालेखन (लाल) '),
*/ $('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio6','value':'hat','onchange':'dc_radio(2)'}),
$('<label>').text('छुपा पुरालेख '),
$('<input>').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio7','value':'subst:RMT','onchange':'dc_radio(2)'}),
$('<label>').text('नाम बदलाव समापन')
),
$('<div class="DC-bottom">').append(
$('<label>').text('स्टेटस (वैकल्पिक): '),
$('<input>').attr({'type':'text','name':'DC-e','id':'DC-e'})
),
$('<div class="DC-bottom">').append(
$('<label>').text('समापन टिप्पणी:'),
$('<textarea>').css({'resize':'none'}).attr({'name':'DC-com','id':'DC-com','rows':'17','cols':'30'})
),
$('<div class="DC-bottom">').append(
$('<label>').text('संपादन सारांश ("चर्चा बंद की जा रही" होगा अगर आप कुछ नहीं लिखते): '),
$('<input>').attr({'type':'text','name':'DC-es','id':'DC-es'})
),
$('<div class="DC-bottom">').attr('id','DC-prevt'),
$('<div class="DC-bottom">').attr('id','DC-prevdiv'),
$('<button>').attr('id', 'DC-closeprev').text('झलक बंद करें').hide()
);
$("#DC-interface-footer").append(
$('<button>').attr({'name':'DC-done', 'id':'DC-done'}).text('चर्चा बंद करें'),
$('<button>').attr({'name':'DC-prev', 'id':'DC-prev'}).text('झलक'),
$('<button>').attr('id', 'DC-cancel').text('रद्द करें'),
$('<label>').attr('id','DC-loading').text(' झलक लोड हो रही...').hide()
);
document.getElementById("DC-modal").addEventListener( "keydown", function ( key ) {
if( key.ctrlKey && ( key.keyCode == 10 || key.keyCode == 13 ) ) {
document.getElementById("DC-done").click();
}
else if ( key.keyCode == 27 ){
document.getElementById("DC-cancel").click();
}
});
$('#DC-cancel').click(function() {
$('#DC-modal').remove();
});
$('#DC-prev').click(function() {
$('#DC-loading').show();
var template = $("input[name=DC-radio]:checked").val();
var status = $('#DC-e').val();
var comment = $('#DC-com').val();
var request = {
action:"query",
titles: mw.config.get('wgPageName'),
rvsection: section,
prop: "revisions|info",
intoken: "edit",
rvprop: "content",
indexpageids: 1,
dataType: "xml",
format: "xml"
};
var bottom = dc_make_bottom( template );
$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
var contentSection = '\r\r' + $(response).find('rev').text();
var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
var title = contentSection.substring(2, contentSection.length - discussiontext.length);
var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}'+discussiontext+'\n'+bottom;
var sectiontitle = title.replace('==', '').replace('==', '').replace('\n', '').replace('/r','').trim();
var sectiontitle2 = sectiontitle.replace(/ /g, '_');
if (template === "subst:RMT"){
wikitext = wikitext.replace(/{\{नाम बदलें\/dated.*\|/g, '{{नाम बदलें/old |');
}
jQuery.ajax({
url:mw.util.wikiScript('api'),
dataType:'json',
type:'POST',
data:{
format:'json',
action:'parse',
pst:1,
text:wikitext,
title:mw.config.get('wgPageName'),
prop:'text'
}
}).done(function(r) {
if(!r.parse || !r.parse.text || !r.parse.text['*']){
alert('Error previewing.');
}
$('#DC-loading').hide();
$('#DC-prevt').html('<hr>Preview:<br>');
$('#DC-prevdiv').html(r.parse.text['*']+'<br />').css({'display':'block','background-color':'white'});
$('#DC-closeprev').show();
$('#DC-closeprev').click(function() {
$('#DC-prevt').empty();
$('#DC-prevdiv').empty().css({'display':'','background-color':'','border-color':'',"border-width":"", "border-style":""});
$('#DC-closeprev').hide();
});
});
});
});
$('#DC-done').click(function() {
var template = $("input[name=DC-radio]:checked").val();
var status = $('#DC-e').val();
var editsummary = $('#DC-es').val();
if (editsummary === "") {
editsummary = "चर्चा बंद की जा रही";
}
var comment = $('#DC-com').val();
$('#DC-done').remove();
$('#DC-prev').remove();
$('#DC-cancel').remove();
$('#DC-interface-content').empty();
$("#DC-interface-content").text('जानकारी हासिल की जा रही...');
var request = {
action:"query",
titles: mw.config.get('wgPageName'),
rvsection: section,
prop: "revisions|info",
intoken: "edit",
rvprop: "content",
indexpageids: 1,
dataType: "xml",
format: "xml"
};
$("#DC-interface-content").append('<b>पूर्ण!</b><br>चर्चा बंद की जा रही...');
var bottom = dc_make_bottom( template );
$.get(mw.config.get("wgScriptPath")+"/api.php", request, function(response){
var contentSection = '\r\r' + $(response).find('rev').text();
var discussiontext = contentSection.substring(contentSection.substring(3,contentSection.length).indexOf('\n')+3, contentSection.length);
var title = contentSection.substring(2, contentSection.length - discussiontext.length);
var wikitext = title + '\n{{'+template+'\n| status = '+status+'\n| result = '+comment+'\n}}\n\n'+discussiontext+'\n'+bottom;
var sectiontitle = title.replace(/=/g, '').replace('\n', '').replace('/r','').trim();
var sectiontitle2 = sectiontitle.replace(/ /g, '_');
if (template === "closed rfc top") {
wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '')
.replace(/(\r|\n)?<!--\s\[\[User:DoNotArchiveUntil\]\][^->]*-->{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, '');
} else if (template === "subst:RMT" ){
wikitext = wikitext.replace(/\n?{{नाम बदलें\/dated\|[^}]*?}}\n?\n?/i, '');
}
var request2 = {
action:"edit",
section: section,
title: mw.config.get('wgPageName'),
text: wikitext,
summary: '/* ' + sectiontitle + ' */ ' + editsummary + DiscussionCloser_ending,
token: mw.user.tokens.get("csrfToken")
};
var willClose = true;
if (alreadyClosed( contentSection )) {
willClose = confirm('यह चर्चा पहले ही बंद की जा चुकी हो सकती है। आगे बढ़ें?');
}
if (!willClose) {
$("#DC-interface-content").append('<b>सदस्य द्वारा निरस्त</b><br><b>कार्य संपन्न हुआ!</b>');
$('#DC-interface-footer').append(
$('<button>').attr('id', 'DC-close').text('Done')
);
$('#DC-close').click(function() {
$('#DC-modal').remove();
window.location.href = 'https://hi.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
window.location.reload();
});
}
else {
$.when(
$.post(mw.config.get("wgScriptPath")+"/api.php", request2, function(response2){
}).done(function() {
$("#DC-interface-content").append('<b>पूर्ण!</b><br><b>कार्य संपन्न हुआ!</b>');
$('#DC-interface-footer').append(
$('<button>').attr('id', 'DC-close').text('Done')
);
$('#DC-close').click(function() {
$('#DC-modal').remove();
window.location.href = 'https://hi.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;
window.location.reload();
});
}));
}
});
});
});
}
}
});
}
mw.loader.using(['mediawiki.util', 'mediawiki.api', 'mediawiki.Title'], function() {
mw.loader.load('//hi.wikipedia.org/w/index.php?title=User:SM7/DiscussionCloser.css&action=raw&ctype=text/css', 'text/css'); // Import stylesheet
dc_init();
});
//</nowiki>