User:Bosco/Unsigned helper.js: Difference between revisions
From Test Wiki
Content deleted Content added
add code comments |
reportNormalSearcherResultToUser: show more information about the found revision to the user of the script: timestamp, author (user who made the edit), byte change |
||
| Line 340: | Line 340: | ||
setProgressCallback(progressCallback) { |
setProgressCallback(progressCallback) { |
||
this.#progressCallback = progressCallback; |
this.#progressCallback = progressCallback; |
||
} |
|||
getContentLoader() { |
|||
return this.#contentLoader; |
|||
} |
} |
||
| Line 611: | Line 615: | ||
} |
} |
||
function formatTimestamp(timestamp) { |
|||
| ⚫ | |||
// return new Date(timestamp).toLocaleString(); |
|||
return timestamp; |
|||
} |
|||
function revisionByteSize(fullRevision) { |
|||
if (fullRevision == null) { |
|||
return null; |
|||
} |
|||
return new Blob([fullRevision.slots.main.content]).size; |
|||
} |
|||
function formatSizeChange(afterSize, beforeSize) { |
|||
const change = afterSize - beforeSize; |
|||
const title = `${afterSize} bytes after change of this size`; |
|||
const titleAttribute = `title="${title}"`; |
|||
let style = ''; |
|||
let changeText = "" + change; |
|||
if (change > 0) { |
|||
changeText = "+" + change; |
|||
style = 'color: var(--color-content-added,#006400);'; |
|||
} |
|||
if (change < 0) { |
|||
// use proper minus sign ([[Plus and minus signs#Minus sign]]) |
|||
changeText = "−" + Math.abs(change); |
|||
style = 'color: var(--color-content-removed,#8b0000);'; |
|||
} |
|||
if (Math.abs(change) > 500) { |
|||
// [[Help:Watchlist#How to read a watchlist (or recent changes)]] |
|||
style = style + "font-weight:bold;"; |
|||
} |
|||
changeText = `(${changeText})`; |
|||
return $('<span>').text(changeText).attr('style', style).attr('title', title); |
|||
} |
|||
| ⚫ | |||
const fullRevision = searcherResult.fullRevision; |
const fullRevision = searcherResult.fullRevision; |
||
const user = fullRevision.user; |
|||
const revid = fullRevision.revid; |
const revid = fullRevision.revid; |
||
const comment = fullRevision.parsedcomment; |
const comment = fullRevision.parsedcomment; |
||
const afterSize = revisionByteSize(fullRevision); |
|||
const beforeSize = revisionByteSize(await searcher.getContentLoader().loadContent(searcherResult.index + 1)); |
|||
reportSearcherResultToUser(searcherResult, "Do you want to use this?", useCb, keepLookingCb, cancelCb, () => { |
reportSearcherResultToUser(searcherResult, "Do you want to use this?", useCb, keepLookingCb, cancelCb, () => { |
||
return $('<div>').append( |
return $('<div>').append( |
||
| Line 622: | Line 664: | ||
target: '_blank' |
target: '_blank' |
||
}).text(`[[Special:Diff/${revid}]] (index=${searcherResult.index})`), |
}).text(`[[Special:Diff/${revid}]] (index=${searcherResult.index})`), |
||
$('<br/>'), '• ', formatTimestamp(fullRevision.timestamp), |
|||
".", |
|||
$('<br/>'), |
$('<br/>'), "• by ", $('<a>').prop({ |
||
href: '/wiki/Special:Contributions/' + user.replaceAll(' ', '_'), |
|||
"Comment: ", |
|||
target: '_blank' |
|||
}).text(`User:${user}`), |
|||
$('<br/>'), "• ", formatSizeChange(afterSize, beforeSize), |
|||
$('<br/>'), "• edit summary: ", $('<i>').html(comment) |
|||
); |
); |
||
}); |
}); |
||
| Line 669: | Line 714: | ||
searchFromIndex(0); |
searchFromIndex(0); |
||
} |
} |
||
window.unsignedHelperAddUnsignedTemplate = function(event) { |
window.unsignedHelperAddUnsignedTemplate = function(event) { |
||
event.preventDefault(); |
event.preventDefault(); |
||