Skip to content

Commit

Permalink
regex+
Browse files Browse the repository at this point in the history
  • Loading branch information
hamishzx committed Oct 24, 2024
1 parent 7bf616b commit dc497fa
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/twinkleclose.js
Original file line number Diff line number Diff line change
Expand Up @@ -815,9 +815,13 @@ Twinkle.close.callbacks = {

var params = pageobj.getCallbackParameters();
var text = pageobj.getPageText();

// HACK: match template w/ or w/o date param, and {{vfd|(reason)}} in one regex

if (/{{[rsaiftcmv]fd[^|}]*(?:\|[^|}]*)?\|(?:[^|}]*date[^|}]*=)?[^|}]*[^}]*}}/is.test(text)) {
text = text.replace(/({{[rsaiftcmv]fd[^|}]*(?:\|[^|}]*)?\|(?:[^|}]*date[^|}]*=)?)[^|}]*([^}]*}})/is, '$1' + params.date + '$2');
if (/{{[rsaiftcmv]fd\s*\|\s*[^|}]*}}/is.test(text) & !/{{[rsaiftcmv]fd\s*\|\s*date\s*=/is.test(text)) {
text = text.replace(/({{[rsaiftcmv]fd[^|}]*)\|([^|}]*}})/is, '$1|date=' + params.date + '|$2');
} else if (/{{[rsaiftcmv]fd[^|}]*(?:\|[^}]*)?\|(?:[^|}]*date[^|}]*=)?(?=\d{4})[^|}]*[^}]*}}/is.test(text)) {
text = text.replace(/({{[rsaiftcmv]fd[^|}]*(?:\|[^}]*)?\|(?:[^|}]*date[^|}]*=)?(?=\d{4}))[^|}]*([^}]*}})/is, '$1' + params.date + '$2');
} else {
Morebits.status.warn(conv({ hans: '重新标记', hant: '重新標記' }), conv({ hans: '找不到提删模板,重新插入', hant: '找不到提刪模板,重新插入' }));
// Insert tag after short description or any hatnotes
Expand Down

0 comments on commit dc497fa

Please sign in to comment.