User:ZI Jony/Gadget-DiscussionCloser.js/sandbox.js

// var DiscussionCloser_config = { name: '', version: '', debug: false }; var DiscussionCloser_ending = ' ' + DiscussionCloser_config.name + ' ' + DiscussionCloser_config.version + ''; /* সহায়তা কার্যাবলী */ function dc_make_bottom(template){ var bottom; switch (template) { case "atop": case "atopr": case "atopy": case "atopg": case "subst:RMT": bottom = "abot"; break; case "hat": bottom = "hab"; break; default: bottom = "closed rfc bottom"; break; }	bottom = ""; return bottom; } function alreadyClosed ( content ){ content = content.toLowerCase; if (content.includes('{{atop') ||		content.includes('{{hat') ||		content.includes('{{abot') ||		content.includes('{{archive') ||		content.includes('{{rfctop') ||		content.includes('{{rfc bottom') ||		content.includes('{{archive bottom') ||		content.includes('{{hidden archive bottom') ||		content.includes('')	) 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') == 'Wikipedia:In_the_news/Candidates')) &&			(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 = /&section=(.*)/;		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(' | ' + 'বন্ধ করুন' + ' ');				$(this).parent(sectionLevel).find('a.closeLink').click(function{ $('body').prepend(' '+						' '+						' '+						' '+						' '+						' '+						' '+						' '+						' '); $("#DC-interface-header, #DC-interface-content, #DC-interface-footer").empty; $("#DC-interface-header").text("আলোচনা বন্ধকারী"); $("#DC-interface-content").append(						$(' ').append( $(' ').attr({'id':'DC-label'}).text('পছন্দ:'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio1','value':'atop','checked':'true','onchange':'dc_radio(1)'}), $(' ').text('শ্রেণী (নীল)'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio2','value':'atopg','onchange':'dc_radio(1)'}), $(' ').text('শ্রেণী (সবুজ)'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio3','value':'atopy','onchange':'dc_radio(1)'}), $(' ').text('শ্রেণী (হলুদ)'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio4','value':'atopr','onchange':'dc_radio(1)'}), $(' ').text('শ্রেণী (লাল)'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'closed rfc top','onchange':'dc_radio(2)'}), $(' ').text('মন্তব্য'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio6','value':'hat','onchange':'dc_radio(2)'}), $(' ').text('লুকানো সংগ্রহশালা'), $(' ').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio7','value':'subst:RMT','onchange':'dc_radio(2)'}), $(' ').text('স্থানান্তর') ),						$(' ').append( $(' ').text('অবস্থা (বাধ্যতামূলক নয়): '), $(' ').attr({'type':'text','name':'DC-e','id':'DC-e'}) ),						$(' ').append( $(' ').text('আলোচনা বন্ধ করা হচ্ছে:'), $(' ').css({'resize':'none'}).attr({'name':'DC-com','id':'DC-com','rows':'17','cols':'30'}) ),						$(' ').append( $(' ').text('সম্পাদনা সারাংশ ("আলোচনা বন্ধ করা হয়েছে" যদি খালি থাকে): '), $(' ').attr({'type':'text','name':'DC-es','id':'DC-es'}) ),						$(' ').attr('id','DC-prevt'),						$(' ').attr('id','DC-prevdiv'),						$(' ').attr('id', 'DC-closeprev').text('প্রদর্শন বন্ধ করুন').hide					); $("#DC-interface-footer").append(						$(' ').attr({'name':'DC-done', 'id':'DC-done'}).text('আলোচনা বন্ধ করুন'),						$(' ').attr({'name':'DC-prev', 'id':'DC-prev'}).text('প্রদর্শন'),						$(' ').attr('id', 'DC-cancel').text('বাতিল'),						$(' ').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 === "closed rfc top") { wikitext = wikitext.replace(/(\r|\n)?{{rfc[^\}]*}}/g, '') .replace(/(\r|\n)?{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, ''); } else if (template === "subst:RMT"){ wikitext = wikitext.replace(/{{requested move\/dated\|[^}]*?}}\n?/i, '{{subst:RMpmc}}\n{{subst:requested move/end}}'); }							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(' প্রদর্শন: ');								$('#DC-prevdiv').html(r.parse.text['*']+' ').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 = "Closing discussion";						}						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('সম্পন্ন! আলোচনা বন্ধ করা হচ্ছে...');						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(2,contentSection.length).indexOf('\n')+3, contentSection.length);			                var title = contentSection.substring(0, 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)?{{[^C]+ClueBot\sIII\/DoNotArchiveUntil\|\d*}}/g, ''); } else if (template === "subst:RMT" ){ wikitext = wikitext.replace(/\n?{{requested move\/dated\|[^}]*?}}\n?\n?/i, '{{subst:RMpmc}}\n{{subst:requested move/end}}'); }							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('ব্যবহারকারী দ্বারা বাতিল সমাপ্ত!'); $('#DC-interface-footer').append(									$(' ').attr('id', 'DC-close').text('সম্পন্ন')								); $('#DC-close').click(function {									$('#DC-modal').remove;									window.location.href = 'https://en.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('সম্পন্ন! সমাপ্ত!'); $('#DC-interface-footer').append(										$(' ').attr('id', 'DC-close').text('সম্পন্ন')									); $('#DC-close').click(function {										$('#DC-modal').remove;										window.location.href = 'https://en.wikipedia.org/wiki/'+mw.config.get('wgPageName')+'#'+sectiontitle2;										window.location.reload;									}); }));							}						});					});				});			}		}	}); } mw.loader.using(['ext.gadget.Twinkle', 'mediawiki.util', 'mediawiki.api', 'mediawiki.Title'], function {	mw.loader.load('//en.wikipedia.org/w/index.php?title=User:ZI_Jony/Gadget-DiscussionCloser.css&action=raw&ctype=text/css', 'text/css'); // Import stylesheet	dc_init; }); //