User:Mattk4355/PatrolRCTable.js

mw.loader.using([   'mediawiki.api',    'mediawiki.util' ]).then(function {    if (mw.config.get('wgNamespaceNumber') !== -1 /* Special: namespace */|| mw.config.get('wgTitle') !== 'PatrolRC') {        return;    }    var intro = 'Table of unpatrolled edits on the ' + mw.config.get('wgSiteName') + '.';

document.title = 'Recent Changes Patrol'; $('.page-header__title').text('Recent Changes Patrol'); var api = new mw.Api; function updateTable { api.get({           action: 'query',            list: 'recentchanges',            //rcnamespace: '0|10|6|828|2',             // https://www.mediawiki.org/wiki/Manual:Namespace#Built-in_namespaces            // https://community.fandom.com/wiki/Help:Namespace            // 0 - Main            // 10 - Template            // 828 - Module            // 6 - File            // 2 - User            rcprop: 'title|user|sizes|parsedcomment|timestamp|ids',            rclimit: '500',            rcshow: '!patrolled'        }).done(function(data) {            var changes = data.query.recentchanges;            var list = document.createElement('table');			list.setAttribute('class', 'wikitable');			list.setAttribute('style', 'width:100%; text-align: center; word-break: break-word;');			var tr_top = list.insertRow;			var th_title = document.createElement('th');			th_title.textContent = 'Title & Timestamp (PT)'; var th_user = document.createElement('th'); th_user.setAttribute('style', 'width: 200px;'); th_user.textContent = 'User'; var th_change = document.createElement('th'); th_change.setAttribute('style', 'width: 100px;'); th_change.textContent = 'Change'; var th_summary = document.createElement('th'); th_summary.setAttribute('style', 'width: 50%;'); th_summary.textContent = 'Summary'; tr_top.append(th_title, th_user, th_change, th_summary); $.each(changes, function(i, v) {				var tr_pageChange = list.insertRow;				var td_title = tr_pageChange.insertCell;				var td_user = tr_pageChange.insertCell;				var td_change = tr_pageChange.insertCell;				var td_summary = tr_pageChange.insertCell;				// Title				var page_title = mw.html.escape(v.title);				var a_title = document.createElement('a');				a_title.setAttribute('href', mw.util.getUrl(v.title));				a_title.innerHTML = page_title;				if (page_title.includes('File:') && ((v.newlen - v.oldlen) === 0)) { // Only add (diff) to files if they have nonzero changes, (0 size change generally means a new version was uploaded).					td_title.append(a_title, document.createElement('br'), new Date(v.timestamp).toLocaleString('en-US', {timeZone: 'America/Los_Angeles', hour12: false}).slice(11));				}				else {					var a_diff = document.createElement('a');									a_diff.setAttribute('style', 'color: grey; font-weight: bold; font-style: italic;'); a_diff.setAttribute('href', mw.util.getUrl('Special:Diff/' + v.revid)); a_diff.textContent = '(diff)'; td_title.append(a_title, ' ', a_diff, document.createElement('br'), new Date(v.timestamp).toLocaleString('en-US', {timeZone: 'America/Los_Angeles', hour12: false}).slice(11)); }				// User var a_user = document.createElement('a'); a_user.setAttribute('href', mw.util.getUrl('User:' + v.user)); a_user.textContent = mw.html.escape(v.user); td_user.append(a_user); // Page size change var diff = document.createElement('strong'); if ((v.newlen - v.oldlen) > 0) { diff.setAttribute('class', 'mw-plusminus-pos'); diff.innerText = '+ ' + Math.abs(v.newlen - v.oldlen); }				else if ((v.newlen - v.oldlen) === 0) { diff.setAttribute('style', 'color: grey;'); diff.innerText = ' 0 '; }				else { diff.setAttribute('class', 'mw-plusminus-neg'); diff.innerText = '- ' + Math.abs(v.newlen - v.oldlen); }               td_change.append(diff); // Summary td_summary.innerHTML = v.parsedcomment; });			tr_end = list.insertRow;			var th_end = document.createElement('th');			th_end.setAttribute('colspan', '4');			th_end.innerText = 'Last refreshed: ' + new Date.toString.slice(16, -15) + ')'; tr_end.append(th_end); $('#mw-content-text').html(list); $('#mw-content-text').prepend(intro); });   }    updateTable;    setInterval(updateTable, 180000); });