User:Lost Labyrinth/autowelcome.js

From Uncyclopedia, the content-free encyclopedia
Jump to navigation Jump to search

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

  • Internet Explorer: hold down the Ctrl key and click the Refresh or Reload button, or press Ctrl+F5.
  • Firefox: hold down the Shift key while clicking Reload; alternatively press Ctrl+F5 or Ctrl-Shift-R.
  • Opera, Konqueror and Safari users can just click the Reload button.
  • Chrome: press Ctrl+F5 or Shift+F5
/* global mw */
/* jshint scripturl:true */
/*
//<nowiki>
==Automatic welcome script ==
Installing this script as described on the talk page will give you a dropdown menu
for all pages in the User talk: namespace, that say 'Welcome'.
It adds the substituted welcome template and your signature to the talk page for you then saves the edit. Simple.


Code by [[User:Lost Labyrinth]], most of which was shamelessly stolen/butchered from [https://www.mediawiki.org/wiki/MediaWiki:Gadget-userMessages.js]

There's meant to be a toolbox function here and the bold "Welcome" text is kind of distracting and there's probably some leftover redundant code from the original script. We can probably work on that later but for now, it functions as it should.
*/
// <source lang="javascript">

// Configuration

// Should the edits be saved automatically?
if(window.template_autosave !== true){ window.template_autosave = true; }
 
// Template Name
var uTemplate = [
	'Welcome',
	'Welcome-anon',
	'IPjoin',
	'Oh Dear',
]; /* if you want to use a custom welcome message, my advice would be to make a copy of this into your own personal JS and switch whatever template with your personal one */
 
// Text to be shown in Toolbox
var uText = [
	"Welcome",
	"Welcome (IP)",
	"Welcome (IP alt)",
	"Oh Dear",
];

// Mouseover help text for Toolbox
var uHelp = [
	"Welcome a new user",
	"Welcome an IP, encourage them to make an account",
	"Welcome an IP in a different way",
	"Welcome a new user (Oh Dear template)",
];

// Add the template
function template_mark(talkpage_fakeaction) {
	var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
	document.location = editlk + '&fakeaction=' + talkpage_fakeaction;
}
 
// Add template to user talk page
function template_addTemplate(template) {
	var txt = '{{safesubst:' + template + '}}';
	document.editform.wpTextbox1.value = document.editform.wpTextbox1.value + '\n' + txt + '\n~~\~~';
	//  the edit summary for when you mark the image. You can change it if you want.
	document.editform.wpSummary.value = 'Welcome to Uncyclopedia!';
	if (template_autosave) document.editform.wpSave.click();
}

function makeVectorFancySection()  {
	//wrap this in a try. this might be somewhat delicate at the moment.
	var pNotify = document.createElement('div');
	pNotify.id = 'p-Notify';
	pNotify.className = 'vectorMenu';
	pNotify.innerHTML = ' <h3><span>Welcome</span><a href="#"></a></h3> <div class="menu"> <ul> </ul> </div>';
	var rightNav = document.getElementById('right-navigation');
	var pViews = document.getElementById('p-views');
	pViewsCont = document.createElement('div');
	pViewsCont.id = 'p-views-continued';
	pViewsCont.className = 'vectorTabs';
	var pViewsUL = document.createElement('ul');
	pViewsCont.appendChild(pViewsUL);
	var pivot = (document.getElementById('ca-history') ? document.getElementById('ca-history') : document.getElementById('ca-addsection'));
	pivot = (pivot ? pivot : document.getElementById('ca-edit'));
	pViewsUL.appendChild(pivot);
	rightNav.insertBefore(pNotify, pViews.nextSibling);
	rightNav.insertBefore(pViewsCont, pNotify.nextSibling); 
}
 
// Add the menu, or add the template to the edit page
function template_onload() {
    try {
    if (mw.config.get('skin') === 'vector') {
        if (window.useFancyVectorDropdown || window.useFancyVectorDropdown === undefined) {
            try {
                makeVectorFancySection();
                useFancyVectorDropdown = 'done'; //this is for debug. can remove
            }
            catch (e) {
                document.getElementById('panel').innerHTML += '<div id="p-Notify" class="portal"><h3 lang="en" xml:lang="en">Welcome</h3><div class="body">\n <ul> </ul> </div> </div>';
            }
        }
        else {
            document.getElementById('panel').innerHTML += '<div id="p-Notify" class="portal"><h3 lang="en" xml:lang="en">Welcome</h3><div class="body">\n <ul> </ul> </div> </div>';
       }
    } else if (mw.config.get('skin') === 'monobook') {
        document.getElementById('column-one').innerHTML += '<div id="p-Notify" class="portlet"> <h3 lang="en" xml:lang="en">Welcome</h3> <div class="pBody">	<ul></ul></div>	</div>';
    }
    } catch (e) {} //ignore errors and just use tb if they happen.
    var portlet = (document.getElementById('p-Notify') ? 'p-Notify' : 'p-tb');
 
    for( var i = 0; i < uText.length; i++ ) {
	    var node = mw.util.addPortletLink(portlet, '', uText[i], 'mark-warn', uHelp[i], null, null);
	    $( node ).click( { template_idx: i }, function(e) {
	    	e.preventDefault();
	    	template_mark( e.data.template_idx );	
	    } );
    }

	// On the edit page, check the fackaction param, to see if we need to add a template 
	var action_idx = -1;
	try {
		action_idx = parseInt (mw.util.getParamValue('fakeaction'), 10);
	} catch (some_error) {
		action_idx = -1;    
	}
	if ( uTemplate[ action_idx ] !== undefined ) {
		//may i take this moment to mention, this script is very very confusing
		if ( mw.config.get( 'wgNamespaceNumber' ) !== 3 ) { 
			alert("The user welcome script has been disabled in this namespace for security reasons.");
			throw new Error("Security error: wrong namespace for user welcome gadget.");
		}
		template_addTemplate( uTemplate[ action_idx ] );
	}
}
 
// NS_USERTALK
if (
	mw.config.get('wgNamespaceNumber') === 3
	&& mw.config.get( 'wgPageContentModel' ) === 'wikitext'
) {
	// Load dependencies and wait for page to be ready
	$.when( mw.loader.using( [ 'mediawiki.util' ] ), $.ready )
		.done( template_onload );
}
// </syntaxhighlight>
//</nowiki>