Content deleted Content added
f |
Improve vote-matching |
||
Line 102:
}
/**
* Call the Wikipedia API with params then run a function on the return data.
*
* @param {Object} params The params to pass to the Wikipedia API.
* @param {Function} callback The function to run with the return data.
* @returns {undefined}
*/
function addNomData(params, callback) {
$.getJSON(mw.util.wikiScript('api'), {
Line 111 ⟶ 118:
}
/**
* Add all data to a nomination.
*
* @param {string} pageName The page name.
* @returns {undefined}
*/
function addAllNomData(pageName) {
// Participants, age. Get all the edits for this nomination.
Line 139 ⟶ 152:
}
/**
* Add data to a nomination.
*
* @param {Object} options Options
* @param {string} options.pageName The page name to which to add this data.
* @param {string} options.data The data to add.
* @param {string} options.id The ID of the field to add to.
* @param {string} options.hoverText Data that appears on hover.
* @returns {undefined}
*/
function addNewNomData({ pageName, data, id, hoverText }) {
if (!data) {
Line 164 ⟶ 186:
'<span>(<span>'
);
const matchArchiveNumber = pageName.match(/(
const conditions = matchArchiveNumber && matchArchiveNumber[1] > 1;
Line 212 ⟶ 234:
* Replace a nomination with a new and improved one.
*
* @param {Object} options Options
* @param {jQuery} options.$h3 The h3 heading of the nomination.
* @param {number} options.index The index of the nomination among the
Line 224 ⟶ 246:
// There are no edit links.
if (
return;
}
Line 241 ⟶ 263:
// to the review page directly. So, skip this nomination.
if (
!$filteredEditLinks.eq(0).attr('href') ||
!$filteredEditLinks
Line 338 ⟶ 360:
// Move the node, if it isn't a text node
if (nomNextSibling.nodeType !== 3) {
// eslint-disable-next-line unicorn/prefer-node-append
hiddenNode.appendChild(nomNextSibling);
}
Line 412 ⟶ 435:
function collapseTable(event) {
event.preventDefault();
const tableIndex = event.data.index;
const collapseCaption = 'hide';
Line 418 ⟶ 442:
const $button = $(`#collapseButton${tableIndex}`);
const $table = $(`#collapsibleTable${tableIndex}`);
if ($table.length === 0 || $button.length === 0) {
return false;
}
const $rows = $table.find('> tbody > tr');
Line 476 ⟶ 502:
const { allH3Length } = event.data;
new Array(allH3Length).fill().forEach((value, index) => {
});
}
Line 704 ⟶ 728:
}
/**
* Generate the patterns used to find vote text.
*
* @returns {Object} The patterns.
*/
function getVoteTextAndPatterns() {
// Look for text that is enclosed within bold text, or level-4 headings.
const wrapPattern = "('''|====)";
// The amount of characters allowed between the vote text, and the wrapping
// patterns.
const voteBuffer = 25;
let openPattern = `${wrapPattern}${textPattern}`;
let closePattern = `${textPattern}${wrapPattern}`;
let
let opposeText = 'oppose';
if
supportText = 'keep';
opposeText = 'delist';
} else if (nomType('pictures')) {
}
return {
supportText,
supportPattern: new RegExp(
`${openPattern}${supportText}${closePattern}`,
'gi'
)
opposeText,
opposePattern: new RegExp(
`${openPattern}${opposeText}${closePattern}`,
'gi'
)
};
}
Line 769 ⟶ 781:
}
/**
* Add votes data to a nomination.
*
* @param {string} content The nomination's content.
* @param {string} pageName The page name.
* @returns {undefined}
*/
function addVotes(content, pageName) {
if (!dataIsEnabled('votes') || nomType('peer reviews')) {
Line 844 ⟶ 863:
}
/**
* Check if the data field is enabled.
*
* @param {string} dataName The name of the data field to look up.
* @returns {boolean} The data field is enabled, so we want to use it.
*/
function dataIsEnabled(dataName) {
return NominationsViewer.nominationData.some((data) => dataName === data);
Line 925 ⟶ 950:
}
/**
* Check if the nomination type of the current nomination is the type
* specified. If no type is specified, then return the type of the current
* nomination. Possible types are: `nominations`, `peer reviews`, `pictures`,
* and `reviews`, as specified in `NominationsViewer.enabledPages`.
*
* @param {string} [type] The type to compare the current nomination with.
* @returns {boolean|string} The current nomination matches the type
* specified, or the type of the current nomination.
*/
function nomType(type = null) {
const pageName = mw.config.get('wgPageName').replace(/_/g, ' ');
const pageType = NominationsViewer.enabledPages[pageName];
|