Content deleted Content added
punctuation variable not used; variable for correcting punctuation placement |
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) |
||
(17 intermediate revisions by the same user not shown) | |||
Line 1:
/* <nowiki>
Moves refs and citation needed tags after punctuation.
*/
// 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");
$("#editform").prepend('<div id="footnote-cleanup"><a href="javascript:cleanupFootnotes()">clean up footnotes</a></div>');▼
var cleanUpFootnotes = function
if ( textbox )▼
{
var
const oldContents = textbox.val();
var contents = oldContents;
Line 36:
{
escaped[i] = match;
var replacement = "%%" + i + "%%";
i += 1;
return replacement;
Line 42:
);
return text;
count += 1;
};
var fixPunctuationPlacement = function(text)
{
while ( puncRegex.test(text) )
▲ return text.replace(
text = text.replace(
▲ /((?:%%\d+%%)+)([\.\,\;\:\)]{1,3})/g,
/((?:%%\d+%%)+)([\.\,\;\:\"]{1,3})/g,
▲ function(match, capture1, capture2)
▲ var replacement = capture2 + capture1;
return text;
▲ replacements.push(replacement);
▲ return replacement;
▲ }
▲ );
};
Line 62 ⟶ 69:
contents = escape(
contents,
"<ref[^>]*>[^<]+<\\/ref>"
);
contents = escape(
contents,
"<ref[^\\/]+\\/>"
);
Line 68 ⟶ 79:
contents = escape(
contents,
"\\{\\{(?:[Cc]itation needed|[Cc]n|[Ff]act|[Cc]b|[Cc]tn|[Rr]ef\\?)\\|[^\}]+\\}\\}"
);
Line 78 ⟶ 89:
contents = escape(
contents,
"\\{\\{(?:sfn|efn|rfn)\\|(?:[^\\}]
);
Line 119 ⟶ 130:
$("#wpSummary").val(function(index, summary)
{
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 129 ⟶ 140:
if ( !isUnchanged && ( !afterSectionName || !afterSectionName[1].includes(addition) ) )
▲ {
return summary + addition;
return summary;
}
);
};
if ( !$("#wikitext-cleanup-button-wrapper").length )
$("#editform").prepend('<div id="wikitext-cleanup-button-wrapper"></div>');
$("#wikitext-cleanup-button-wrapper")
▲
$("#footnote-cleanup")
.click(cleanUpFootnotes);
}
|