User:Anerisys/vector.js

/* source links – adds "source" link – (cur|prev|source) */ /* backwards compatible to MediaWiki ~2019 */

// initialize var sourcelink = {}; var contribution_count = 0; var history_element = {};

if (document.getElementById("pagehistory") ) history_element = document.getElementById("pagehistory"); if (document.getElementsByClassName("mw-contributions-list") ) history_element = document.getElementsByClassName("mw-contributions-list"); if (history_element.length > 1) history_element = history_element[0].parentElement;

sourcelink.number_of_days = history_element.getElementsByTagName("h4").length; if (sourcelink.number_of_days == 0) sourcelink.number_of_days++; // backwards compatibility

// localization var 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) { shortcut_url=parent_element.querySelector("."+parent_class).getAttribute("href")+"&action="+action;

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

// main for (day_count=0; day_count < sourcelink.number_of_days; day_count++ ) { if ( sourcelink.number_of_days > 1 ) { var contribution_list = history_element.getElementsByTagName("ul")[day_count].getElementsByTagName("li"); } else { var contribution_list = history_element.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.querySelector(".mw-changeslist-links"),"mw-contributions-date" ); } else { // add "edit" and "info" shortcuts addHistoryShortcut("edit","edit","mw-changeslist-edit",contribution.querySelector(".mw-changeslist-links"),"mw-contributions-title" ); addHistoryShortcut("info","info","mw-changeslist-edit",contribution.querySelector(".mw-changeslist-links"),"mw-contributions-title" ); }	} }