User:DannyS712/DiscussionCloser.js

//

//Credits to Equazcion, Evad37, and Abelmoschus Esculentus

//Date: 6 Mar 2019

//Forked from [[User:Abelmoschus Esculentus/DiscussionCloser.js]

//Maintained by DannyS712

var DiscussionCloser_config = {

name: '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 "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 = "{{" + 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') == 'Wikipedia:Administrators\'_noticeboard/Edit_warring') ||

(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 = /§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('

| ' + 'Close' + '
');

$(this).parent(sectionLevel).find('a.closeLink').click(function(){

$('body').prepend('

'+

'

'+

'

'+

'


'+

'

'+

'


'+

'

'+

'

'+

'

');

$("#DC-interface-header, #DC-interface-content, #DC-interface-footer").empty();

$("#DC-interface-header").text("Discussion Closer");

$("#DC-interface-content").append(

$('

').append(

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio1','value':'atop','checked':'true','onchange':'dc_radio(1)'}),

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio2','value':'atopg','onchange':'dc_radio(1)'}),

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio3','value':'atopy','onchange':'dc_radio(1)'}),

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio4','value':'atopr','onchange':'dc_radio(1)'}),

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio5','value':'closed rfc top','onchange':'dc_radio(2)'}),

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio6','value':'hat','onchange':'dc_radio(2)'}),

$('

$('').attr({'type':'radio', 'name':'DC-radio','id':'DC-radio7','value':'subst:RMT','onchange':'dc_radio(2)'}),

$('

),

$('

').append(

$('

$('').attr({'type':'text','name':'DC-e','id':'DC-e'})

),

$('

').append(

$('

$('