User:Bongolium500/Gadgets/MediaWiki:Gadget-talk page button.js

/* This JavaScript was put together by User:Bongolium500. It relies heavily upon code from w:c:javascript:DOM functions TO DO: Move the button to be between the edit button and 3 dots menu Add an icon to the button Simplify the code (the function at the top is only used once for example, although adding the above may mean it is used more) function adom(el, atts) { var elem = document.createElement(el); for (attname in atts) { if (attname === 'textContent' || attname === 'textc') { var textnode = document.createTextNode(atts[attname]); elem.appendChild(textnode); }		else if (attname === 'className' || attname === 'classn') { elem.setAttribute('class', atts[attname]); }		else { elem.setAttribute(attname, atts[attname]); }	}	if (arguments[2] == null) { return elem; }	else { var nexttoappend = elem; for (var i=2; i < arguments.length; i++) { // > var argtemp = arguments[i]; if (typeof argtemp === 'string') { argtemp = document.getElementById(argtemp); }			argtemp.appendChild(nexttoappend); nexttoappend = argtemp; }

return nexttoappend; } }

//Setup variables var header = document.getElementsByClassName("page-header__actions")[0]; namespace = mw.html.escape(mw.config.get("wgCanonicalNamespace"))+"_"; namespaceNum = mw.config.get("wgNamespaceNumber"); pagename = mw.html.escape(mw.config.get("wgTitle"));

if (namespaceNum !== -1 && namespaceNum%2 === 0) { //check that the namespace would have a valid talk page adom('a', {href: "http://tardis.fandom.com/wiki/"+namespace+"Talk:"+pagename, title: "Go to the talk page", classn: "wds-button wds-is-text page-header__action-button has-label talk-button", id: "ca-talk", textc: "Talk"}, header); //add the emelent to the page }