MediaWiki

Gadget-editButton.js

From Dogcraft Wiki

Revision as of 00:59, 6 September 2024 by Domino (talk | contribs) (Added Read support in edit mode)

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");
	wikiEdit.setAttribute("class", "button");
	
	if (action === 'edit')
		wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName'))
	else {
		if (namespace === 14 || namespace === 3004 || namespace == 2 || namespace == 0)
			wikiEdit.setAttribute("href", "/wiki/index.php?title=" + mw.config.get('wgPageName') + "&veaction=edit")
		else
			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);
})
This page was last modified on 6 September 2024, at 00:59. (2 months ago)
Background Takeshi by Edo