User:SD0001/BDCS.js
Appearance
From Wikipedia, the free encyclopedia
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
This code will be executed when previewing this page.
This user script seems to have a documentation page at User:SD0001/BDCS.
/** * Script for the Birthday Committee * Rip-off from Twinkle's Welcome module ([[MediaWiki:Gadget-friendlywelcome.js]]) */ // <nowiki> $.when( mw.loader.using('ext.gadget.morebits'), $.ready ).then(function(){ if(!mw.config.get('wgRelevantUserName')){ return; } varWish={}; window.Wish=Wish; Wish.advert=' ([[User:SD0001/BDCS|BDCS]])'; varli=mw.util.addPortletLink('p-cactions','#','BDC wish','p-wish','Wish user'); li.addEventListener('click',function(){ Wish.callback(mw.config.get('wgRelevantUserName')); }); Wish.callback=function(uid){ if(uid===mw.config.get('wgUserName')&&!confirm('Are you really sure you want to wish yourself?...')){ return; } Morebits.wiki.api.setApiUserAgent('[[w:User:SD0001/BDCS.js]]'); varWindow=newMorebits.simpleWindow(600,420); Window.setTitle('Wish user'); Window.addFooterLink('Birthday Committee','WP:BDC'); varform=newMorebits.quickForm(Wish.callback.evaluate); form.append({ type:'select', name:'type', label:'Type of wish: ', event:Wish.populateWishList, list:[ {type:'option',value:'birthday',label:'Happy Birthday',selected:true}, {type:'option',value:'firsteditday',label:'Happy First Edit Day'}, {type:'option',value:'anniv',label:'Happy Adminship Anniversary'} ].concat( window.BDCS_CustomTemplates&&window.BDCS_CustomTemplates.length? [{type:'option',value:'custom',label:'Custom templates'}]:[] ) }); form.append({ type:'div', id:'wishWorkArea' }); form.append({ type:'input', name:'heading', label:'Section heading: ', value:'Happy Birthday!' }); varpreviewlink=document.createElement('a'); $(previewlink).click(function(){ Wish.callbacks.preview(result);// |result| is defined below }); previewlink.style.cursor='pointer'; previewlink.textContent='Preview'; form.append({type:'div',id:'wishpreview',label:[previewlink]}); form.append({type:'div',id:'wish-previewbox',style:'display: none'}); form.append({type:'submit'}); varresult=form.render(); Window.setContent(result); Window.display(); result.previewer=newMorebits.wiki.preview($('#wish-previewbox').last()[0]); // initialize the wish list varevt=document.createEvent('Event'); evt.initEvent('change',true,true); result.type.dispatchEvent(evt); }; Wish.populateWishList=function(e){ vartype=e.target.value; varform=e.target.form; varcontainer=newMorebits.quickForm.element({type:'fragment'}); varappendTemplates=function(list){ container.append({ type:'radio', name:'template', list:list.map(function(obj){ return{ value:obj, label:'{{'+obj+'}}' } }) }); }; switch(type){ case'birthday': form.heading.value='Happy Birthday!'; appendTemplates([ 'Happy Birthday', 'Happy Birthday 2', 'Happy Birthday 3', 'Happy Birthday 4', 'Happy Birthday 5', 'Happy Birthday 6', 'Happy Birthday 7', 'Happy Birthday 8', 'Happy Birthday 9', 'Happy Birthday 10', 'Happy Birthday 11', 'Happy Birthday 12', 'Happy Birthday 13' ]); break; case'firsteditday': form.heading.value='Happy First Edit Day!'; appendTemplates([ 'First Edit Day', 'First Edit Day 2', 'First Edit Day 3', 'First Edit Day 4', ]); break; case'anniv': form.heading.value='Happy Adminship Anniversary!'; appendTemplates([ 'Happy Adminship', 'Happy Adminship 2', 'Happy Adminship 3', 'Happy Adminship 4', 'Happy Adminship 5', 'Happy Adminship 6', 'Happy Adminship 7', 'Happy Bureaucratship', 'Happy Bureaucratship 2', 'Happy Bureaucratship 3', ]); break; case'custom': form.heading.value=''; appendTemplates(window.BDCS_CustomTemplates); break; default: container.append({type:'div',label:'Wish.populateWishList: something went wrong'}); break; } varrendered=container.render(); $('#wishWorkArea').empty().append(rendered); varfirstRadio=form.template[0]||form.template; firstRadio.checked=true; }; Wish.getTemplateWikitext=function(template,heading){ return'=='+heading+'==\n{{subst:'+template+'}}'; }; Wish.callbacks={ preview:function(form){ form.previewer.beginRender(Wish.getTemplateWikitext(form.getChecked('template'),form.heading.value),'User talk:'+mw.config.get('wgRelevantUserName')); }, main:function(pageobj){ varparams=pageobj.getCallbackParameters(); vartext=pageobj.getPageText(); varwishText=Wish.getTemplateWikitext(params.value,params.heading); text+='\n'+wishText; summaryText=(params.heading?('/* '+params.heading+' */ '):'')+'new section'; pageobj.setPageText(text); pageobj.setEditSummary(summaryText+Wish.advert); pageobj.setCreateOption('nocreate'); pageobj.save(); } }; Wish.callback.evaluate=functionwishEvaluate(e){ varform=e.target; varparams={ value:form.getChecked('template'), heading:form.heading.value }; Morebits.simpleWindow.setButtonsEnabled(false); Morebits.status.init(form); varuserTalkPage=mw.config.get('wgFormattedNamespaces')[3]+':'+mw.config.get('wgRelevantUserName'); Morebits.wiki.actionCompleted.redirect=userTalkPage; Morebits.wiki.actionCompleted.notice='Wishing complete, reloading talk page in a few seconds'; varwikipedia_page=newMorebits.wiki.page(userTalkPage,'User talk page modification'); wikipedia_page.setFollowRedirect(true); wikipedia_page.setCallbackParameters(params); wikipedia_page.load(Wish.callbacks.main); }; }); // </nowiki>