User:Anerisys/vector.js

/* user contribution links – adds "edit" and "info" links: (diff|hist|edit|info) */ /* page history links – adds "source" link: (cur|prev|source) */ /* backwards compatible to MediaWiki ~2019 */

// initialize var history_links = {}; var history_container = {}; var contribution_count = 0; var day_count = 0;

// determine history_container, the parent element of all history entries on the page if (document.getElementById("pagehistory") ) { // is page history console.debug("page history detected"); history_container = document.getElementById("pagehistory"); }	else { // user contributions console.debug("user contributions detected"); history_container = document.getElementsByClassName("mw-contributions-list")[0].parentElement; }

history_links.number_of_days = history_container.getElementsByTagName("h4").length; if (history_links.number_of_days == 0) history_links.number_of_days=1; // backwards compatibility

// localization var language = "en"; // fallback if (typeof mw != "undefined") language = mw.config.values.wgUserLanguage; var l10n_base = { en: { 'source': 'source', 'edit': 'edit', 'info': 'info' },	de: { 'source': 'Quelltext', 'edit': 'Bearbeiten', 'info': 'Informationen' } }; function l10n(msg) { return l10n_base[language][msg]; }

// functions function addHistoryShortcut(action,label,class_name,parent_element,parent_class_name) { shortcut_URL=parent_element.querySelector("."+parent_class_name).getAttribute("href")+"&action="+action;

parent_element.querySelector(".mw-changeslist-links").appendChild(document.createElement("span")); parent_element.querySelector(".mw-changeslist-links").lastElementChild.classList.add(class_name); parent_element.querySelector(".mw-changeslist-links").lastElementChild.innerHTML=' '+l10n(label)+''; }

// main for (day_count=0; day_count < history_links.number_of_days; day_count++ ) { if ( history_links.number_of_days > 1 ) { var contribution_list = history_container.getElementsByTagName("ul")[day_count].getElementsByTagName("li"); } else { var contribution_list = history_container.getElementsByTagName("li"); }

for ( contribution_count = 0; contribution_count < contribution_list.length; contribution_count++ ) { var contribution=contribution_list[contribution_count]; if (document.getElementById("pagehistory") ) { // add "source" shortcut addHistoryShortcut("edit","source","mw-changeslist-source",contribution,"mw-changeslist-date" ); } else { // add "edit" and "info" shortcuts addHistoryShortcut("edit","edit","mw-changeslist-edit",contribution,"mw-contributions-title" ); addHistoryShortcut("info","info","mw-changeslist-info",contribution,"mw-contributions-title" ); }	} }