User:Sav/welcome.js

From Test Wiki
Jump to navigation Jump to search

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.
/* TO USE: ADD LINES LIKE BELOW

const WELCOME_TEMPLATE = "<full page name of your welcome template>";
mw.loader.load('/w/index.php?title=User:Sav/welcome.js&action=raw&ctype=text/javascript');

FOR EXAMPLE:

const WELCOME_TEMPLATE = "User:Sav/Welcome";
mw.loader.load('/w/index.php?title=User:Sav/welcome.js&action=raw&ctype=text/javascript');

*/

const tag = "welcomingnice"; // Change this to change the query used to detect if you're welcoming

if (mw.config.get('wgNamespaceNumber') == 3) {
	let actions = document.querySelector('.content-actions');
	let ul = actions.getElementsByClassName('dropdown')[0];
	
	let li = document.createElement('li');
	ul.insertBefore(li, document.getElementById('ca-history'));
	
	const params = new URLSearchParams(window.location.search);
	
	li.innerHTML = '<li id="ca-welcome" class="selected"><a href="/w/index.php?title=' + (params.has("title") ? params.get("title") : window.location.pathname.replaceAll("/wiki/", "")) + '&action=edit&section=new&' + tag + '=true" title="Welcome this user!">Welcome User</a></li>';
	
	if (params.has(tag)) {
		$("#wpSummary").textSelection('setContents', 'Welcome!');
		$("#wpTextbox1").textSelection('setContents', '{{' + WELCOME_TEMPLATE + '}}~~' + '~~\n');
	}
}
console.log("Loaded Wiki Welcome");