User:Gauri Wur Sem/vector.js

mw.loader.load('//en.wikipedia.org/w/index.php?title=User%3ADr_pda%2Fprosesize.js&action=raw&ctype=text/javascript'); // User:Dr_pda/prosesize.js importScript('User:TheDJ/sharebox.js'); importScript('Wikipedia:AutoEd/complete.js'); importScript("User:GregU/dashes.js"); importScript('User:Ohconfucius/script/MOSNUM dates.js'); //User:Ohconfucius/script/MOSNUM dates.js importScript('User:Ohconfucius/script/Common Terms.js'); //User:Ohconfucius/script/Common Terms.js importScript('User:Ohconfucius/script/formatgeneral.js'); //User:Ohconfucius/script/formatgeneral.js function formatCitations(vertical) { var txt = document.editform.wpTextbox1; // Fill an array with one entry per each recognized citation template var originalTemplates = txt.value.match(/\{\{[Cc]it(ation|e [a-z ]+) *\n? *\|[^}]+\}\}/g); // Duplicate the array, for editing. We need to keep the original strings for the replacement step var tweakedTemplates = originalTemplates.slice; for(var i = 0; i < originalTemplates.length; i++) { if(vertical) { // Fill an array with one entry per each parameter for this citation template var originalParams = originalTemplates[i].match(/ *\n? *\| *\n? *[a-z1-9]+ *= */g); // Create array to be filled with the cleaned-up parameters. // We need to keep the original strings for the replacement step. var tweakedParams = []; var maxWidth = 0; for(var j = 0; j < originalParams.length; j++){ // Get rid of the delimiters and spaces, keep only the parameter string tweakedParams[j] = originalParams[j].match(/[a-z1-9]+/)[0]; // Calculate the length of the longest parameter maxWidth = (tweakedParams[j].length>maxWidth) ? tweakedParams[j].length : maxWidth; }           maxWidth++; // We need an extra one because Array(n).join(' ') will produce a string with n-1 chars // Generate the aligned versions of the parameters (with padding before the equal signs) for(var k = 0; k < originalParams.length; k++) { var numSpaces = maxWidth - tweakedParams[k].length; var alignedParam = "\n | " + tweakedParams[k] + new Array(numSpaces).join(" ") + " = "; // Replace the original parameters with the tweakes ones tweakedTemplates[i] = tweakedTemplates[i].replace (originalParams[k], alignedParam); }           // Also align the }} tweakedTemplates[i] = tweakedTemplates[i].replace(/ *\n? *\}\}/g,"\n }}"); // Replace the original templates with the tweaked versions txt.value = txt.value.replace(originalTemplates[i], tweakedTemplates[i]); } else { // Remove newlines tweakedTemplates[i] = tweakedTemplates[i].replace(/\n/g, ""); // Normalize spaces around the pipes and equal signs tweakedTemplates[i] = tweakedTemplates[i].replace(/ *\| *([a-z1-9]+) *= */g," |$1 = "); // Remove potencial extra spaces before template ends tweakedTemplates[i] = tweakedTemplates[i].replace(/ *\}\}$/," }}"); txt.value = txt.value.replace(originalTemplates[i], tweakedTemplates[i]); }   }    // Update the edit summary var sum = document.editform.wpSummary; var summary = vertical ? "Convert citation templates to vertical format, for readability" : "Harmonize whitespace in citation templates" ; summary += " (using Regex citation formatter)"; if (sum.value.indexOf(summary) == -1) { if (sum.value.match(/[^\*\/\s][^\/\s]?\s*$/)) { sum.value += " | "; }       sum.value += summary; }   if(!vertical) { document.editform.wpMinoredit.checked = true; } } $(function {    if(document.forms.editform) {        mw.util.addPortletLink('p-cactions', 'javascript:formatCitations(false)', ' – ', 'ca-formatcitations', 'Format citations: add whitespace', '-', );        mw.util.addPortletLink('p-cactions', 'javascript:formatCitations(true)', ' – +', 'ca-formatcitations-vertical', 'Formats citations vertically', '-', );    } }); importScript('User:Shubinator/DYKcheck.js'); //DYKcheck tool