User:Anerisys/source shortcut for MediaWiki 2019 and newer.js

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

// initialize var sourcelink = {}; var contribution_count = 0; var pagehistory = document.getElementById("pagehistory");

sourcelink.number_of_days = document.getElementById("pagehistory").getElementsByTagName("h4").length;

// localization var language = mw.config.values.wgContentLanguage; var l10n_base = { en: { 'source': 'source' },	de: { 'source': 'Quelltext' } }; function l10n(msg) { return l10n_base[language][msg]; }

if (sourcelink.number_of_days == 0) sourcelink.number_of_days++;

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

for ( contribution_count = 0; contribution_count < contribution_list.length; contribution_count++ ) { var contribution=contribution_list[contribution_count];

source_page_URL = contribution.querySelector(".mw-changeslist-date").getAttribute("href")+"&action=edit";

// add "source" 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("source")+'';

} }