User:Anerisys/vector.js

/* User contributions edit and info shortcuts */

// initialize variables var contribution_day = 0; var contribution_count = 0; var contributions_on_page = 0;

// localization var language = mw.config.values.wgPageContentLanguage; var l10n_base = { en: { 'edit': 'edit', 'info': 'info' },	de: { 'edit': 'Bearbeiten', 'info': 'Informationen' } }; function l10n(msg) { return l10n_base[language][msg]; }

// main if (	mw.config.get("wgNamespaceNumber") == -1 // checks "Special" name space	&& mw.config.get("wgCanonicalSpecialPageName") == "Contributions" // checks if it is a contributions page	&& document.getElementsByClassName("mw-changeslist-links").length > 1 // contributions list not empty	&& ( ! document.getElementsByClassName("mw-changeslist-links")[1].getElementsByTagName("span")[2] ) // not already added ) {

var mw_contributions_list = document.getElementsByClassName("mw-contributions-list");

for ( contribution_day = 0; contribution_day < mw_contributions_list.length; contribution_day++ ) {

for ( contribution_count = 0; contribution_count < mw_contributions_list[contribution_day].getElementsByTagName("li").length; contribution_count++ ) {

var contribution = mw_contributions_list[contribution_day].getElementsByTagName("li")[contribution_count]; if (contribution.querySelector(".mw-changeslist-links") ) { edit_page_URL = mw.util.getUrl( contribution.querySelector(".mw-contributions-title").innerHTML, { "action": "edit" } ); info_page_URL = mw.util.getUrl( contribution.querySelector(".mw-contributions-title").innerHTML, { "action": "info" } );

// add "edit" shortcut contribution.querySelector(".mw-changeslist-links").appendChild(document.createElement("span")); contribution.querySelector(".mw-changeslist-links").lastElementChild.classList.add("mw-changeslist-edit"); contribution.querySelector(".mw-changeslist-links").lastElementChild.innerHTML=' '+l10n("edit")+'';

// add "info" shortcut contribution.querySelector(".mw-changeslist-links").appendChild(document.createElement("span")); contribution.querySelector(".mw-changeslist-links").lastElementChild.classList.add("mw-changeslist-info"); contribution.querySelector(".mw-changeslist-links").lastElementChild.innerHTML=' '+l10n("info")+'';

contributions_on_page+=1; }		}	}	console.log("Showing "+contributions_on_page+" contributions on "+contribution_day+" days."); } else { // check if already added if (document.getElementsByClassName("mw-changeslist-links")[1] ) { if (document.getElementsByClassName("mw-changeslist-links")[1].getElementsByTagName("span")[2] ) { console.warn("Contribution shortcuts: Edit links appear to have already been added."); }	}	// legacy mode if (document.querySelector(".mw-contributions-list") ) { if ( ! document.querySelector(".mw-contributions-list").getElementsByTagName("h4") ) { console.warn("Contribution shortcuts: legacy mode"); var contribution = document.querySelector(".mw-contributions-list").getElementsByTagName("li"); }	} }