User:Evalprime/common.js

// makes RecentChanges into columns; finally, it's no longer hard to read // // if you want to use this - I don't officially support you using this // shoot a message on my talk page and I'll try to walk you through setting // this up

(function ($, mw) {   function runReadableRC($content) {        if (!$content.hasClass('mw-changeslist')) {            return;        }

$content.addClass('column-rc');

var rows = document.querySelectorAll('.mw-changeslist-line, ' + // normal edits                   '.mw-rcfilters-ui-highlights-enhanced-toplevel, ' + // grouped edits                    '.mw-rcfilters-ui-highlights-enhanced-nested'); // children in grouped edits

for (var i = 0; i < rows.length; i++) { var row = rows[i];

if (row.classList.contains('mw-rcfilters-ui-highlights-enhanced-nested')) { row.classList.add('column-rc-nested');

if (row.classList.contains('mw-changeslist-edit')) { cleanNestedEdit(row); }               else if (row.classList.contains('mw-changeslist-log')) { cleanNestedLog(row); }           }            else { if (row.classList.contains('mw-collapsible')) { continue; }

if (row.classList.contains('mw-rcfilters-ui-highlights-enhanced-toplevel')) { var parent = row.closest('.mw-collapsible');

if (parent.classList.contains('mw-changeslist-edit')) { cleanMultipleEdits(row); }                   else if (parent.classList.contains('mw-changeslist-log')) { cleanMultipleLogs(row); }               }                else { if (row.classList.contains('mw-changeslist-edit')) { cleanSingleEdit(row); }                   else if (row.classList.contains('mw-changeslist-log')) { cleanSingleLog(row); }               }            }        }    }

function insert(row, newNode, referenceNode) { return row.querySelector(referenceNode).parentNode.insertBefore(row.querySelector(newNode), row.querySelector(referenceNode)); }

function wrap(referenceNode, wrapperEl, wrapperClass) { var wrapper = document.createElement(wrapperEl);

referenceNode.parentNode.insertBefore(wrapper, referenceNode); wrapper.appendChild(referenceNode); wrapper.classList.add(wrapperClass); }

function cleanNestedLog(row) { wrap(row.querySelector('.mw-enhanced-rc-time'), 'td', 'column-rc-logname');

wrap(row.querySelector('.mw-changeslist-separator'), 'td', 'column-rc-logdots');

cleanUserLinks(row);

row.querySelector('td.mw-enhanced-rc-nested').className = 'column-rc-logentry';

insert(row, '.column-rc-logname', '.column-rc-logentry'); insert(row, '.column-rc-logdots', '.column-rc-logentry'); }

function cleanNestedEdit(row) { wrap(row.querySelector('.mw-enhanced-rc-time'), 'td', 'column-rc-pagename');

row.querySelector('.mw-changeslist-separator').remove; row.querySelector('.mw-changeslist-separator').remove;

$('.mw-userlink, .mw-usertoollinks, .comment, .mw-rollback-link, .mw-tag-markers, .history-deleted', row).wrapAll('');

cleanUserLinks(row);

if (row.querySelector('.mw-rollback-link')) { row.querySelector('.mw-rollback-link a').textContent = 'rollback'; }

row.querySelector('td.mw-enhanced-rc-nested').className = 'column-rc-diff';

insert(row, '.column-rc-userlinks', '.column-rc-diff'); insert(row, '.column-rc-pagename', '.column-rc-userlinks'); insert(row, '.column-rc-diff', '.column-rc-userlinks'); }

function cleanMultipleLogs(row) { wrap(row.querySelector('.mw-rc-unwatched'), 'td', 'column-rc-logname');

var users = row.querySelector('.changedby').childNodes;

users[0].textContent = users[0].textContent.slice(1); // [ users[users.length - 1].textContent = users[users.length - 1].textContent.slice(0, -1); // ]

wrap(row.querySelector('.mw-changeslist-separator'), 'td', 'column-rc-logdots');

row.querySelector('.mw-changeslist-line-inner').className = 'column-rc-logentry';

insert(row, '.column-rc-logname', '.column-rc-logentry'); insert(row, '.column-rc-logdots', '.column-rc-logentry');

row.querySelector('.column-rc-logentry').childNodes[0].remove; }

function cleanMultipleEdits(row) { wrap(row.querySelector('.mw-title'), 'td', 'column-rc-pagename');

if (row.querySelector('.mw-changeslist-groupdiff')) { row.querySelector('.mw-changeslist-groupdiff').textContent = 'diff'; }       else { row.querySelector('.mw-changeslist-links span:first-child').textContent = 'diff'; }

if (row.querySelector('.mw-changeslist-history')) { row.querySelector('.mw-changeslist-history').textContent = 'hist'; }       else { var newHist = row.querySelector('.mw-changeslist-line-inner').childNodes[4].nodeValue.replace('history', 'hist');

row.querySelector('.mw-changeslist-line-inner').childNodes[4].nodeValue = newHist; }

wrap(row.querySelector('.changedby'), 'td', 'column-rc-userlinks');

var users = row.querySelector('.changedby').childNodes;

users[0].textContent = users[0].textContent.slice(1); // [ users[users.length - 1].textContent = users[users.length - 1].textContent.slice(0, -1); // ]

row.querySelector('.mw-changeslist-line-inner').className = 'column-rc-diff';

insert(row, '.column-rc-userlinks', '.column-rc-diff'); insert(row, '.column-rc-pagename', '.column-rc-userlinks'); insert(row, '.column-rc-diff', '.column-rc-userlinks'); }

function cleanSingleLog(row) { wrap(row.querySelector('.mw-changeslist-line-inner-logLink'), 'td', 'column-rc-logname');

wrap(row.querySelector('.mw-changeslist-line-inner-separatorAfterLinks'), 'td', 'column-rc-logdots');

cleanUserLinks(row);

row.querySelector('.mw-changeslist-line-inner').className = 'column-rc-logentry';

insert(row, '.column-rc-logname', '.column-rc-logentry'); insert(row, '.column-rc-logdots', '.column-rc-logentry'); }

function cleanSingleEdit(row) { wrap(row.querySelector('.mw-title'), 'td', 'column-rc-pagename');

if (row.querySelector('.mw-rollback-link')) { row.querySelector('.mw-rollback-link a').textContent = 'rollback'; }

$('.mw-userlink, .mw-usertoollinks, .comment, .mw-rollback-link, .mw-tag-markers, .history-deleted', row).wrapAll('');

cleanUserLinks(row);

row.querySelector('.mw-changeslist-line-inner').className = 'column-rc-diff';

insert(row, '.column-rc-userlinks', '.column-rc-diff'); insert(row, '.column-rc-pagename', '.column-rc-userlinks'); insert(row, '.column-rc-diff', '.column-rc-userlinks'); }

function cleanUserLinks(row) { if (row.querySelector('.history-deleted')) { return; }       if (row.querySelector('.mw-usertoollinks-contribs')) { row.querySelector('.mw-usertoollinks-contribs').textContent = 'c'; }

if (row.querySelector('.mw-usertoollinks-block')) { row.querySelector('.mw-usertoollinks-block').textContent = 'b'; }   }

function init { mw.hook('structuredChangeFilters.ui.initialized').add(function {            runReadableRC($('.mw-changeslist'));            mw.hook('wikipage.content').add(runReadableRC);        }); }

$(init); })(jQuery, mediaWiki);

// add additional portlet links

$( function {	var conf = mw.config.get([ 'wgPageName', 'wgNamespaceNumber', 'wgArticlePath' ]);   if (conf.wgNamespaceNumber === -1) {    	return    }

mw.util.addPortletLink(		'p-cactions',		conf.wgArticlePath.replace('$1', encodeURIComponent(conf.wgPageName) + '?diff=cur'),		'Last',		'ca-diff',		'Show most recent diff'	);

mw.util.addPortletLink(		'p-cactions',		conf.wgArticlePath.replace('$1', 'Special:PrefixIndex/' + encodeURIComponent(conf.wgPageName) + '/'),		'Subpages',		'ca-subpages',		'List this page\'s subpages'	); });