User:Erutuon/scripts/footnoteCleanup.js: Difference between revisions

Content deleted Content added
oops
set event handler below definition of event handler (JavaScript hoisting of variable declarations is bizarre and the previous code might be wrong, but I don't know)
 
(4 intermediate revisions by the same user not shown)
Line 1:
/* <nowiki>
 
Moves refs and citation needed tags after punctuation.
 
*/
 
varconst namespaceNumber = mw.config.values.get("wgNamespaceNumber");
 
// Add a link just above the edit box, if you're in the main or Draft namespace.
if ( namespaceNumber === 0 || namespaceNumber === 118 )
{
mw.loader.load("//en.wiktionary.org/w/index.php?title=User:Erutuon/styles/wikitext-cleanup.css&action=raw&ctype=text/css", "text/css");
if ( !$("#wikitext-cleanup-button-wrapper").length )
$("#editform").prepend('<div id="wikitext-cleanup-button-wrapper"></div>');
$("#wikitext-cleanup-button-wrapper")
.append(`<div id="footnote-cleanup" class="wikitext-cleanup-button">clean up footnotes</div>`)
$("#footnote-cleanup")
.click(cleanUpFootnotes);
}
 
function var cleanUpFootnotes = function ()
{
var textbox = $("#wpTextbox1");
if ( textbox )
{
var oldContentstextbox = textbox.val$("#wpTextbox1");
if ( !textbox )
return;
const oldContents = textbox.val();
var contents = oldContents;
Line 43 ⟶ 36:
{
escaped[i] = match;
var replacement = "%%" + i + "%%";
i += 1;
return replacement;
Line 139 ⟶ 132:
var addition = "made sure refs are after punctuation with [[User:Erutuon/footnoteCleanup.js|JavaScript]]; see [[WP:REFPUNC]]";
const afterSectionName = summary.match(/^(?:\/\*[^\*]+\*\/)?\s*(.+)/);
if ( afterSectionName && afterSectionName[1].length > 1 )
Line 152 ⟶ 145:
}
);
};
if ( !$("#wikitext-cleanup-button-wrapper").length )
$("#editform").prepend('<div id="wikitext-cleanup-button-wrapper"></div>');
$("#wikitext-cleanup-button-wrapper")
.append(`<div id="footnote-cleanup" class="wikitext-cleanup-button">clean up footnotes</div>`);
$("#footnote-cleanup")
.click(cleanUpFootnotes);
}