User:Bosco/Unsigned helper.js: Difference between revisions
From Test Wiki
Content deleted Content added
makeUnsignedTemplate: refactor |
refactor top-level structure |
||
| Line 1: | Line 1: | ||
(function () { |
|||
var UnsignedHelper = { |
|||
months |
const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; |
||
function makeUnsignedTemplate(user, timestamp, template) { |
|||
const ts = new Date(timestamp); |
const ts = new Date(timestamp); |
||
let h = ts.getUTCHours(); |
let h = ts.getUTCHours(); |
||
| Line 12: | Line 12: | ||
const formattedTimestamp = `${h}:${m}, ${ts.getUTCDate()} ${UnsignedHelper.months[ts.getUTCMonth()]} ${ts.getUTCFullYear()} (UTC)`; |
const formattedTimestamp = `${h}:${m}, ${ts.getUTCDate()} ${UnsignedHelper.months[ts.getUTCMonth()]} ${ts.getUTCFullYear()} (UTC)`; |
||
return '\x7b\x7bsubst:' + template + '|' + user + '|' + formattedTimestamp + '\x7d\x7d'; |
return '\x7b\x7bsubst:' + template + '|' + user + '|' + formattedTimestamp + '\x7d\x7d'; |
||
} |
} |
||
function appendToEditSummary(newSummary) { |
|||
const editSummaryField = $("#wpSummary:first"); |
const editSummaryField = $("#wpSummary:first"); |
||
if (editSummaryField.length == 0) { |
if (editSummaryField.length == 0) { |
||
| Line 32: | Line 32: | ||
} |
} |
||
editSummaryField.val(newText); |
editSummaryField.val(newText); |
||
} |
} |
||
window.unsignedHelperAddUnsignedTemplate = function(evt) { |
|||
addUnsignedTemplate: function (evt) { |
|||
mw.loader.using(['mediawiki.util', 'jquery.ui'], function () { |
mw.loader.using(['mediawiki.util', 'jquery.ui'], function () { |
||
var f = document.getElementById('editform'); |
var f = document.getElementById('editform'); |
||
| Line 183: | Line 183: | ||
return false; |
return false; |
||
} |
} |
||
}; |
|||
if (!window.charinsertCustom) |
|||
window.charinsertCustom = {}; |
|||
window.charinsertCustom |
if (!window.charinsertCustom['Insert']) |
||
window.charinsertCustom['Insert'] = ''; |
|||
window.charinsertCustom['Insert'] = ''; |
window.charinsertCustom['Insert'] += ' \x7b\x7bunsigned\x7d\x7d\x10unsignedHelperAddUnsignedTemplate'; |
||
window.charinsertCustom[' |
if (!window.charinsertCustom['Wiki markup']) |
||
window.charinsertCustom['Wiki markup'] = ''; |
|||
window.charinsertCustom['Wiki markup'] = ''; |
window.charinsertCustom['Wiki markup'] += ' \x7b\x7bunsigned\x7d\x7d\x10unsignedHelperAddUnsignedTemplate'; |
||
| ⚫ | |||
window.charinsertCustom['Wiki markup'] += ' \x7b\x7bunsigned\x7d\x7d\x10UnsignedHelper.addUnsignedTemplate'; |
|||
window.updateEditTools(); |
|||
})(); |
|||
| ⚫ | |||