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

Content deleted Content added
declare function only if necessary; fiddle with variable scope
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)
 
(One intermediate revision by the same user not shown)
Line 4:
*/
 
const 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);
 
Line 153 ⟶ 146:
);
};
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);
}