Jump to content

User:Joeytje50/JWB/feed.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/** <nowiki>This script generates a list of most recent edits for each of the relevant pages for JWB.
 * This is used to check most recent changes, and whether the git repo needs updating.
 * The git repo is located at https://github.com/Joeytje50/JWB.
 * If you want to use this script as well (idk why but okay), you can install it using:

{{subst:lusc|User:Joeytje50/JWB.js/load.js}}

 * This script is not a subpage of JWB.js because it doesn't affect the actual JWB script itself.
 * </nowiki>
 */
 
if (mw.config.get('wgPageName') === 'User:Joeytje50/JWB') {
	window.JWB = {
		imports: {i18n: {}},
		messages: {},
	};
	$(function() {
		var feed = $('#JWB-feed');
		function getJWBFeed() {
			feed.closest('table').show();
			feed.html('<table class="wikitable"><caption style="cursor:pointer;">JWB recent changes</caption><tr><th>Title</th><th>User</th><th>Date</th><th>Summary</th></tr></table>');
			var table = feed.find('table.wikitable')
							.append('<tr><th colspan="10"><a href="https://github.com/Joeytje50/JWB" target="_blank">Github repo</a></th></tr>');
			var api = new mw.Api();
			api.get({
				action: 'query',
				prop: 'revisions',
				format: 'json',
				titles: ['User:Joeytje50/JWB',
					'User:Joeytje50/JWB/Changelog',
					'User:Joeytje50/JWB.js',
					'User:Joeytje50/JWB.css',
					'User:Joeytje50/JWB.js/load.js',
					'User:Joeytje50/JWB.js/i18n.js',
					'User:Joeytje50/JWB.js/worker.js',
					'User:Joeytje50/RETF.js',
					'User:Joeytje50/RETF'],
				rvprop: ['timestamp', 'user', 'parsedcomment', 'ids']
			}).done(function(data) {
				var pages = data.query.pages;
				for (var id in pages) {
					var rev = pages[id].revisions[0];
					var row = $('<tr></tr>').appendTo(table);
					row.append('<td><a href="/wiki/'+pages[id].title+'?action=raw">'+pages[id].title+'</a></td>')
					   .append('<td><a href="/wiki/User:'+rev.user+'">'+rev.user+'</a></td>')
					   .append('<td><a href="/w/index.php?diff='+rev.revid+'">'+(new Date(rev.timestamp)).toLocaleDateString("en-US", { year: 'numeric', month: 'long', day: 'numeric' })+'</a></td>')
					   .append('<td>'+rev.parsedcomment+'</td>');
				}
			});
		}
		getJWBFeed();
		table.find('caption').attr('title', 'Refresh').click(getJWBFeed);
	});
	$.getScript('//en.wikipedia.org/w/index.php?title=User:Joeytje50/JWB.js/i18n.js&action=raw&ctype=text/javascript', function() {
		var langs = [];
		var codes = [];
		for (let lang in JWB.imports.i18n) {
			langs.push(JWB.imports.i18n[lang]);
			codes.push(lang);
		}
		$.when.apply($, langs.map(url => $.getScript(url))).done(function() {
			// loaded all i18n files. Check which messages are missing.
			var feed = $('#JWB-feed');
			var langtbl = $('<table class="wikitable"><tr><th>Code</th><th colspan="2">Missing messages</th></tr></table>');
			var missing = {};
			for (var c of codes) {
				missing[c] = [];
				for (var msg in JWB.messages.en) {
					if (JWB.messages[c][msg] === undefined) {
						missing[c].push(msg);
					}
				}
				if (missing[c].length === 0) continue;
				langtbl.append('<tr><td rowspan="'+missing[c].length+'"><code><a href="/wiki/User:Joeytje50/JWB.js/i18n-'+c+'.js">'+c+'</a></code></td>' + missing[c].reduce((acc, cur) => {
					if (acc.length) { // don't open a new <tr> if this is the first missing message.
						acc += '<tr>';
					}
					return acc + '<td><code>' + cur + '</code></td><td>' + JWB.messages.en[cur] + '</td></tr>';
				}, '')); // initialValue = '' to start off with an empty string.
			}
			feed.append(langtbl);
		});
	});
}