MediaWiki

Gadget-editButton.js

From Dogcraft Wiki

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (โŒ˜-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (โŒ˜-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
$( function () {
	var namespace = mw.config.get('wgNamespaceNumber');
	var action = mw.config.get('wgAction');
	
	var wikiEdit = document.createElement("a");
	wikiEdit.setAttribute("id", "wikiEdit");
	if (action === 'edit') {
		wikiEdit.setAttribute("class", "button editButton-view");
		wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName'))
	} else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0) {
			wikiEdit.setAttribute("class", "button editButton-edit");
			wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit")
		} else {
			wikiEdit.setAttribute("class", "button editButton-editSource");
			wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&action=edit")
		}
	}
		
	var wikiEditButton = document.createElement("button");
	wikiEdit.appendChild(wikiEditButton);
	
	var wikiEditButtonIcon = document.createElement("i");
	if (action === "edit") 
		wikiEditButtonIcon.setAttribute("class", "fas fa-file");
	else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
			wikiEditButtonIcon.setAttribute("class", "fas fa-pencil");
		else 
			wikiEditButtonIcon.setAttribute("class", "fas fa-code");
	}
	wikiEditButton.appendChild(wikiEditButtonIcon);
	
	var wikiEditButtonLabel = document.createElement("span");
	if (action === "edit")
		wikiEditButtonLabel.innerText = " Read";
	else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
			wikiEditButtonLabel.innerText = " Edit";
		else 
			wikiEditButtonLabel.innerText = " Edit source";
	}
	wikiEditButton.appendChild(wikiEditButtonLabel);
	
	document.getElementById("wikiActions").before(wikiEdit);
})
Background Dragon Slayer - Retriever by Ironboundred