MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
No edit summary |
No edit summary |
||
Line 3: | Line 3: | ||
function createArtistString(link, artists, featured) { |
function createArtistString(link, artists, featured) { |
||
featured = (featured === undefined) ? [] : featured; |
featured = (featured === undefined) ? [] : featured; |
||
linkStart = (link === true) ? '[[' : ''; |
var linkStart = (link === true) ? '[[' : ''; |
||
linkEnd = (link === true) ? ']]' : ''; |
var linkEnd = (link === true) ? ']]' : ''; |
||
var artistStr = ''; |
var artistStr = ''; |
||
Line 22: | Line 22: | ||
return artistStr; |
return artistStr; |
||
} |
|||
var pageHTML = $(".mw-parser-output").html(); |
|||
/** CONTEST RESULTS **/ |
|||
var resultsRegex = /{{#ContestResults:([1-9](?:[0-9]{1,})?)\|(SF[1-3]|GF)}}/gm; |
|||
let m; |
|||
while ((m = resultsRegex.exec(pageHTML)) !== null) { |
|||
if (m.index === resultsRegex.lastIndex) { |
|||
resultsRegex.lastIndex++; |
|||
} |
|||
m.forEach((match, groupIndex) => { |
|||
console.log(`Found match, group ${groupIndex}: ${match}`); |
|||
}); |
|||
} |
} |
Revision as of 15:26, 30 December 2019
/* Any JavaScript here will be loaded for all users on every page load. */
function createArtistString(link, artists, featured) {
featured = (featured === undefined) ? [] : featured;
var linkStart = (link === true) ? '[[' : '';
var linkEnd = (link === true) ? ']]' : '';
var artistStr = '';
if (artists.length == 1) {
artistStr += linkStart+artists[0]+linkEnd;
} else if (artists.length == 2) {
artistStr += linkStart+artists.join(linkEnd+' & '+linkStart)+linkEnd;
} else {
var last_artist = artists.pop();
artistStr += linkStart+artists.join(linkEnd+', '+linkStart)+linkEnd+' & '+linkStart+last_artist+linkEnd;
}
if (featured.length > 0) {
artistStr += " feat. "+createArtistString(link, featured);
}
return artistStr;
}
var pageHTML = $(".mw-parser-output").html();
/** CONTEST RESULTS **/
var resultsRegex = /{{#ContestResults:([1-9](?:[0-9]{1,})?)\|(SF[1-3]|GF)}}/gm;
let m;
while ((m = resultsRegex.exec(pageHTML)) !== null) {
if (m.index === resultsRegex.lastIndex) {
resultsRegex.lastIndex++;
}
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}