User:Zackmann08/scripts/GenerateTable.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:Zackmann08/scripts/GenerateTable.
//<nowiki>
jQuery(document).ready(function($) {
if(mw.config.get('wgPageName').toLowerCase().includes('sandbox') && mw.config.get('wgNamespaceNumber') != 0 && document.getElementsByName('wpTextbox1')[0]) {
mw.loader.using(['mediawiki.util']).done( function() {
var portletlink = mw.util.addPortletLink('p-tb','#','GenDepTable','t-gentdeptable');
$(portletlink).click(function(e) {
e.preventDefault();
generateDepTable();
});
});
}
// -------------------------------------------------------------------------------- //
function generateDepTable()
{
var mycontent = $('#wpTextbox1').textSelection('getContents');
// Copy the contents of the text window so we can modify it without problems
var original_text = mycontent;
const params_regex = /\{\{#invoke\:Check for deprecated parameters\|check([\s\S]*)\}\}<noinclude>/i;
var param_text = original_text.match(params_regex);
if (param_text == null){
alert('Match not found');
return;
}
param_text = original_text.match(params_regex)[1];
console.log(param_text);
param_text = param_text.replace(/\|\s*\_.*\n/g,'').replace(/^\n/,'');
var final_text = '== Pushpin map cleanup ==\n\nAs part of a larger refactor of [[Module:Location map]], I will be refactoring the way that this Infobox calls the location map code. The only noticeable change for most will be that the parameter names related to the pushpin maps will now all start with {{para|pushpin_...}}. This is part of a larger effort to make things consistent across Infoboxes. When this is done, ALL infoboxes using pushpin maps will use the same parameters. For more information about this, please see [[Module_talk:Location_map#Proposal_to_refactor_the_way_Template:Location_map_works_in_Infoboxes|this post]]. As part of this cleanup, I am also going to resolving any conflicting parameters that I can find and cleaning up parameter names that fail to conform to [[MOS:INFOBOXNAME]]. Note that this follows a long list of similar clean ups that I have done on countless other Infoboxes. The parameters I plan to replace are the following:\n\n{| class="wikitable"\n! Deprecate\n! Replace with\n'
const replace_regex = /\|\s([\w\s\(\)\-\']*)\s=\s(\w+)/g;
const replaces = param_text.matchAll(replace_regex);
var count = 0;
for (const replace of replaces) {
count = count + 1;
final_text = final_text + '|-\n| {{para|' + replace[1] + '}}\n| {{para|' + replace[2] + '}}\n'
}
if (param_text.split(/\n/).length -1 != count){
alert('One or more params, do not match replace_regex formula.');
}
final_text += '|}\n\nPlease chime in below with any questions, comments or concerns about this cleanup.'
$('#wpTextbox1').textSelection('setContents', final_text);
mw.notify('Success');
}
// -------------------------------------------------------------------------------- //
});
//</nowiki>