User:Alex 21/script-categorypagelinks.js

$(document.getElementsByClassName("mw-category-generated")).ready(function() {
	// Categories only
	if (mw.config.get("wgNamespaceNumber") !== 14) return;
	
	// Make sure it's only run once
	var mw_category_alllinks = document.getElementsByClassName("categorypagelinks");
	if (mw_category_alllinks.length !== 0) return;
	
	// Variables
	var baseLink = "https://en.wikipedia.org/wiki/";
	var i, anchor_span, anchor_edit, anchor_talk, anchor_hist, mw_category_anchor, mw_category_article, documentFragment;
	
	// All anchors within the main category class
	var mw_category = document.getElementsByClassName("mw-category-generated");
	var mw_category_allanchors = mw_category[0] ? mw_category[0].getElementsByTagName("a") : [];
	
	// Add specific class as a failsafe so the script only runs once, and only on these anchors and not the ones generated later
	for (i = 0; i < mw_category_allanchors.length; i++) {
		mw_category_anchor = mw_category_allanchors[i];
		mw_category_anchor.className = mw_category_anchor.className+" categorypagelinks";
	}
	
	mw_category_alllinks = document.getElementsByClassName("categorypagelinks");

	for (i = 0; i < mw_category_alllinks.length; i++) {
		// Get anchor and href attribute
		mw_category_anchor = mw_category_alllinks[i];
		mw_category_article = mw_category_anchor.href.substr(baseLink.length);
		
		if (mw_category_article.indexOf("Wikipedia:FAQ") != -1) continue;
		
		// Create edit, talk and history links
		anchor_edit = document.createElement("a");
		anchor_talk = document.createElement("a");
		anchor_hist = document.createElement("a");
		anchor_edit.innerHTML = "edit";
		anchor_talk.innerHTML = "talk";
		anchor_hist.innerHTML = "history";
		anchor_edit.className = "external text";
		anchor_hist.className = "external text";
		
		anchor_edit.href = "https://en.wikipedia.org/w/index.php?title="+mw_category_article+"&action=edit";
		anchor_talk.href = "https://en.wikipedia.org/wiki/Talk:"+mw_category_article;
		anchor_hist.href = "https://en.wikipedia.org/w/index.php?title="+mw_category_article+"&action=history";
		
		// Span to house the edit, talk and history links 
		anchor_span = document.createElement("span");
		anchor_span.className = "plainlinks lx";
		
		// Lay out links as such: ( edit | talk | history )
		anchor_span.appendChild(document.createTextNode(" ("));
		anchor_span.appendChild(anchor_edit);
		anchor_span.appendChild(document.createTextNode(" | "));
		anchor_span.appendChild(anchor_talk);
		anchor_span.appendChild(document.createTextNode(" | "));
		anchor_span.appendChild(anchor_hist);
		anchor_span.appendChild(document.createTextNode(")"));
		
		// Add span and links
		documentFragment = document.createDocumentFragment();
		documentFragment.appendChild(anchor_span);
		mw_category_anchor.parentNode.appendChild(documentFragment);
	}
});

Content Disclaimer

Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.

  1. The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
  2. There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
  3. It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
  4. Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
  5. Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.