Content deleted Content added
f |
|||
Line 1:
/*▼
//
▲ Nominations Viewer
//
//
//
//
const NominationsViewer = window.NominationsViewer || {};▼
▲ Description: Compact nominations for [[WP:FAC]], [[WP:FAR]], [[WP:FLC]],
▲ [[WP:FLRC]], [[WP:FPC]], and [[WP:PR]].
▲ Documentation: [[Wikipedia:Nominations Viewer]]
▲ ===
▲ Begin settings
▲ ---
▲ Default:
▲ NominationsViewer =
▲ {
▲ 'enabledPages': ['Wikipedia:Featured article candidates', ...],
▲ 'nominationData': ['images', 'age', 'nominators', 'participants', 'votes'],
▲ }
*/▼
▲const NominationsViewer =
▲if (NominationsViewer.enabledPages == null) {
NominationsViewer.enabledPages = {
// 'User:Gary/Sandbox': 'nominations'
Line 38 ⟶ 35:
}
if (!NominationsViewer.nominationData
NominationsViewer.nominationData = [
'images',
Line 47 ⟶ 44:
];
}
▲/*
▲/**
▲*/
▲ */
class NominationsViewerClass {
/**
* Add empty nomination data holders for a nomination.
* @param {string} pageName Name of the nomination page.
* @param {jQuery} $parentNode Parent node containing the entire nomination.
* @param {Array} ids The ID names to create.
* @returns {jQuery} The new node we added.
*/
static addNominationData(pageName, $parentNode, ids) {
Line 71:
}
static
const data = { allH3Length: $headings.length };
Line 123:
// Age
'NominationsViewerClass.firstRevisionCallback',
`action=query&prop=revisions&rvdir=newer&rvlimit=1&titles=${pageName}`,
Line 129:
}
static addNewNomData(pageName, data, id, abbrTitle, isFirstData) {
data,▼
if (!data) {
return
}
Line 150 ⟶ 144:
$newChild.append($abbr);
}
/**
* Create the data that appears next to the nomination's listing.
* @param {string} pageName Page name of the nomination page.
* @returns {jQuery} The new node we added.
*/
static createData(pageName) {
Line 208 ⟶ 204:
/**
* Replace a nomination with a new and improved one.
* @param {jQuery} $h3 The h3 heading of the nomination.▼
* @param {
▲ * @param {jQuery} options.$h3 The h3 heading of the nomination.
* @param {number} options.index The index of the nomination among the others.
* @returns {undefined}
*/
static createNomination({ $h3, index }) {
Line 217 ⟶ 216:
// Skip it.
if (!$editLink.length) {
return
}
Line 251 ⟶ 250:
// Ask the API to add data to our placeholders
}
Line 290 ⟶ 289:
// it isn't an H2 or H3, and it doesn't have the class "printfooter"
while (
nomNextSibling
['H2', 'H3'].indexOf(nomNextSibling.nodeName) === -1 &&
!(
Line 318 ⟶ 317:
// Check if enabled on this page
Object.keys(NominationsViewer.enabledPages).forEach((page) => {
if (pageName === page.replace(/\s/g, '_')) {
currentPageIsEnabled = true;
} else if (pageName.
currentPageIsASubpage = true;
}
Line 328 ⟶ 325:
if (
!currentPageIsEnabled
window.mw.config.get('wgAction') !== 'view' ||
window.location.href.indexOf('&oldid=') !== -1 ||
) {
return false;
Line 341 ⟶ 338:
const $parentNode = $('.mw-content-ltr');
const $h3s = $parentNode.find('h3');
this.
//
$h3s.each((index, element) =>
this.createNomination({
Line 370 ⟶ 367:
}
/
▲ */
static collapseTable(event) {
event.preventDefault();
Line 433 ⟶ 428:
let action = actionParam;
if (!action
action = 'expand';
}
Line 449 ⟶ 444:
let action = actionParam;
if (!action
action = '';
}
Line 468 ⟶ 463:
if (action === 'collapse') {
return toggleHideNom($node, $nomButton);
}
return toggleShowNom($node, $nomButton);
// These have to be separate from the above because they have a lower▼
// priority.▼
} else if ($node.is(':visible')) {▼
return toggleHideNom($node, $nomButton);
}
return toggleShowNom($node, $nomButton);
}
Line 487 ⟶ 488:
}
/
static allRevisionsCallback(obj) {
const vars = this.formatJSON(obj);
Line 502 ⟶ 501:
vars.revisions.forEach((revision) => {
if (!revision.user) {
return;
Line 525 ⟶ 523:
if (a[1] < b[1]) {
return 1;
}
return -1;
}
return 0;
});
Line 533 ⟶ 534:
const usersArray2 = usersArray.map((user) => `${user[0]}: ${user[1]}`);
return this.
vars.pageName,
`${moreThan + userCount} ${this.pluralize('participant', userCount)}`,
Line 577 ⟶ 578:
});
this.
vars.pageName,
`${matches.length} ${this.pluralize('image', matches.length)}`,
Line 598 ⟶ 599:
);
// eslint-disable-next-line max-depth
if ($.isEmptyObject(listOfNominators)) {
listOfNominators = this.findNominators(content, /:<small>''.*/);
Line 623 ⟶ 625:
/* eslint-disable indent */
this.
vars.pageName,
allNominators.length > 0
Line 734 ⟶ 736:
const toolTip = supports + opposes;
return this.
}
Line 747 ⟶ 744:
/**
* The callback after getting the first revision of a page.
* @param {Object} obj The response object from the Wikipedia API.
* @returns {undefined} Generated nomination data.
*/
static firstRevisionCallback(obj) {
Line 753 ⟶ 752:
if (!vars) {
return
}
Line 814 ⟶ 813:
}
vars.pageName,
timeAgo,
Line 821 ⟶ 820:
);
}
}
▲ /*
▲ Callback helpers
static capitalize(string) {
return string.charAt(0).toUpperCase() + string.slice(1);
Line 908 ⟶ 903:
const pageType = NominationsViewer.enabledPages[pageName];
if (type
if (type === pageType) {
return true;
|