Jump to content

User:Deryck Chan/closerfd.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <nowiki>
// There are instructions on [[User:Deryck Chan/closerfd]]!
// closerfd.js - written by [[User:Deryck Chan]], modelled upon
// [[User:King of Hearts/closerfd.js]] by [[User:King of Hearts]]
// [[Wikipedia:WikiProject User scripts/Scripts/CloseAFD.js]] by [[User:Johnleemk]]
// and [[User:Lifebaka/closedrv.js]] by [[User:Lifebaka]]

function autorfd_result()
{
	var f = document.editform, t = f.wpTextbox1;
	var wikitext_split = t.value.split("====");
	t.value = "====" + wikitext_split[1] + "====" + "\n{{sub" + "st:rfdt|    }}    ~~" + "~~" + wikitext_split[2] + "\n{{sub" + "st:rfdb}}";
	f.wpSummary.value += " closing as ";
}

function autorfd_relist()
{
	var f = document.editform, t = f.wpTextbox1;
	var wikitext_split = t.value.split("====");
	t.value = "====" + wikitext_split[1] + "====\n{{sub" + "st:Rfdr|" + wikitext_split[1] + "}}\n";
	f.wpSummary.value += " relisting";
}

function autorfd_scrub()
{
	var f = document.editform, t = f.wpTextbox1;
	var wikitext_split = t.value.split("<!-- End of RFD message. Don't edit anything above here, but feel free to edit below here. -->|content=\n");
	if (wikitext_split.length == 2) wikitext_edited = wikitext_split[1];
	t.value = wikitext_edited.replace("\n<!-- Don't add anything after this line. -->\n}}", "");
} //This approach scrubs everything above the RfD template but preserves content (e.g. draft disambigs) below the RfD template


function autorfd_result_test()
{
	var f = document.editform, t = f.wpTextbox1;
	var wikitext_split = t.value.split("====");
	t.value = "====" + wikitext_split[1] + "====" + "\n{{sub" + "st:rfd top/sandbox|    }}    ~~" + "~~" + wikitext_split[2] + "\n{{sub" + "st:rfd bottom/sandbox}}";
	f.wpSummary.value += " closing as     with new template, comments welcome on [[WT:RFD]]";
}

// Create portlet links
if ((document.title.indexOf("Editing Wikipedia:Redirects for discussion/Log/") != -1) && (document.title.indexOf("(section)") != -1))
{
	var portletLinkResult = mw.util.addPortletLink( 'p-cactions', '#',
		'Close RfD', 'ca-rfd-result',	'Click here to insert RfD closure templates'
	);
	// Bind click handler
	$( portletLinkResult ).click( function ( e ) {
		e.preventDefault();
		autorfd_result();
	});
	
	var portletLinkTest = mw.util.addPortletLink( 'p-cactions', '#',
		'Relist RfD', 'ca-relist',	'Copy discussion content first, then click here to insert RfD relisting template'
	);
	// Bind click handler
	$( portletLinkTest ).click( function ( e ) {
		e.preventDefault();
		autorfd_relist();
	});
}

if ((document.title.indexOf("Editing ") != -1) && (document.editform.wpSummary.value.split("Wikipedia:Redirects for discussion").length > 1))
{
	var portletLinkScrub = mw.util.addPortletLink( 'p-cactions', '#',
		'Scrub RfD', 'ca-rfd-result',	'Click here to remove RfD nomination templates and restore a redirect'
	);
	// Bind click handler
	$( portletLinkScrub ).click( function ( e ) {
		e.preventDefault();
		autorfd_scrub();
	});
}
// </nowiki>