跳转到内容

User:Tommyang/Script/friendlywelcome.min.js

维基百科,自由的百科全书
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
if(typeof(FriendlyConfig)=='undefined'){FriendlyConfig={};}
if(typeof(FriendlyConfig.summaryAd)=='undefined'){FriendlyConfig.summaryAd=" using [[WP:FRIENDLY|Friendly]]";}
if(typeof(FriendlyConfig.topWelcomes)=='undefined'){FriendlyConfig.topWelcomes=true;}
if(typeof(FriendlyConfig.watchWelcomes)=='undefined'){FriendlyConfig.watchWelcomes=false;}
if(typeof(FriendlyConfig.insertHeadings)=='undefined'){FriendlyConfig.insertHeadings=false;}
if(typeof(FriendlyConfig.welcomeHeading)=='undefined'){FriendlyConfig.welcomeHeading="== Welcome ==";}
if(typeof(FriendlyConfig.insertUsername)=='undefined'){FriendlyConfig.insertUsername=false;}
if(typeof(FriendlyConfig.insertSignature)=='undefined'){FriendlyConfig.insertSignature=true;}
if(typeof(FriendlyConfig.markWelcomesAsMinor)=='undefined'){FriendlyConfig.markWelcomesAsMinor=true;}
if(typeof(FriendlyConfig.quickWelcomeMode)=='undefined'){FriendlyConfig.quickWelcomeMode="auto";}
if(typeof(FriendlyConfig.quickWelcomeTemplate)=='undefined'){FriendlyConfig.quickWelcomeTemplate="Welcome";}
if(typeof(FriendlyConfig.maskTemplateInSummary)=='undefined'){FriendlyConfig.maskTemplateInSummary=false;}
friendlywelcome={auto:function(){if(QueryString.get('action')!='edit'){return;}
return friendlywelcome.welcome();},semiauto:function(){friendlywelcome.callback(wgTitle.split('/')[0].replace(/\"/,"\\\""));},normal:function(){if(QueryString.exists('diff')){var oXPath='//div[@id="mw-diff-otitle2"]/span[@class="mw-usertoollinks"]/a[1][@class="new"]';var nXPath='//div[@id="mw-diff-ntitle2"]/span[@class="mw-usertoollinks"]/a[1][@class="new"]';var oList=document.evaluate(oXPath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);var nList=document.evaluate(nXPath,document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null);if(oList.snapshotLength>0||nList.snapshotLength>0){var spanTag=function(color,content){var span=document.createElement('span');span.style.color=color;span.appendChild(document.createTextNode(content));return span;}
var welcomeNode=document.createElement('strong');var welcomeLink=document.createElement('a');welcomeLink.appendChild(spanTag('Black','['));welcomeLink.appendChild(spanTag('Goldenrod','welcome'));welcomeLink.appendChild(spanTag('Black',']'));welcomeNode.appendChild(welcomeLink);if(oList.snapshotLength>0){var oTalkNode=oList.snapshotItem(0);var oHref=document.evaluate('@href',oTalkNode,null,XPathResult.STRING_TYPE,null).stringValue;var oWelcomeNode=welcomeNode.cloneNode(true);oWelcomeNode.firstChild.setAttribute('href',oHref+'&'+QueryString.create({'friendlywelcome':'norm'})+'&'+QueryString.create({'vanarticle':wgPageName.replace(/_/g,' ')}));oTalkNode.parentNode.parentNode.appendChild(document.createTextNode(' '));oTalkNode.parentNode.parentNode.appendChild(oWelcomeNode);}
if(nList.snapshotLength>0){var nTalkNode=nList.snapshotItem(0);var nHref=document.evaluate('@href',nTalkNode,null,XPathResult.STRING_TYPE,null).stringValue;var nWelcomeNode=welcomeNode.cloneNode(true);nWelcomeNode.firstChild.setAttribute('href',nHref+'&'+QueryString.create({'friendlywelcome':'norm'})+'&'+QueryString.create({'vanarticle':wgPageName.replace(/_/g,' ')}));nTalkNode.parentNode.parentNode.appendChild(document.createTextNode(' '));nTalkNode.parentNode.parentNode.appendChild(nWelcomeNode);}}}
if(wgNamespaceNumber==3){var username=wgTitle.split('/')[0].replace(/\"/,"\\\"");twAddPortletLink("javascript:friendlywelcome.callback(\""+username+"\")",wgULS("欢迎","歡迎"),"friendly-welcome",wgULS("欢迎新用户","歡迎新用戶"),"");}}}
friendlywelcome.welcome=function welcomeUser(){Status.init(document.getElementById('bodyContent'));var params={value:FriendlyConfig.quickWelcomeTemplate,article:QueryString.exists('vanarticle')?QueryString.get('vanarticle'):'',mode:'auto'};var query={'title':wgPageName,'action':'submit'};Wikipedia.actionCompleted.redirect=wgPageName;Wikipedia.actionCompleted.notice="Welcoming complete, reloading talk page in some seconds";var wikipedia_wiki=new Wikipedia.wiki('User talk page modification',query,friendlywelcome.callbacks.main);wikipedia_wiki.params=params;wikipedia_wiki.get();}
friendlywelcome.callback=function friendlywelcomeCallback(uid){var Window=new SimpleWindow(600,400);Window.setTitle("选择欢迎模板");var form=new QuickForm(friendlywelcome.callback.evaluate,'change');form.append({type:'input',name:'article',label:'相关条目',value:(QueryString.exists('vanarticle')?QueryString.get('vanarticle'):''),event:function(event){event.stopPropagation();}});form.append({type:'header',label:'简单模板'});form.append({type:'radio',name:'simple',list:friendlywelcome.standardList});if(typeof(FriendlyConfig.customWelcomeList)=='object'){form.append({type:'header',label:'自定义模板'});form.append({type:'radio',name:'custom',list:FriendlyConfig.customWelcomeList});}
form.append({type:'header',label:'问题模板'});form.append({type:'radio',name:'problem',list:friendlywelcome.problemList});form.append({type:'header',label:'匿名用户模板'});form.append({type:'radio',name:'anonymous',list:friendlywelcome.anonymousList});form.append({type:'header',label:'专题模板'});form.append({type:'radio',name:'project',list:friendlywelcome.projectList});form.append({type:'header',label:'地区模板'});form.append({type:'radio',name:'region',list:friendlywelcome.regionList});var result=form.render();Window.setContent(result);Window.display();}
friendlywelcome.standardList=[{label:'{{User:Tommyang/Welcome}}: Tommyang的欢迎模板',value:'User:Tommyang/Welcome'},{label:'{{Welcome}}: 标准欢迎模板',value:'Welcome'},{label:'{{Welcome plain}}: 纯文本欢迎模板',value:'Welcome plain'}]
friendlywelcome.problemList=[{label:'{{Firstarticle}}: 用户的第一篇条目不符合方针',value:'Firstarticle'},{label:'{{Welcomevandal}}: 用户的初始动作像是破坏',value:'Welcomevandal'},{label:'{{Welcomeipvandal}}: 匿名用户的初始动作像是破坏',value:'Welcomeipvandal'}]
friendlywelcome.anonymousList=[{label:'{{Welcome-anon}}: 匿名用户',value:'Welcome-anon'}]
friendlywelcome.projectList=[{label:'{{WelcomeACG}}: ACG',value:'WelcomeACG'},{label:'{{WelcomeBIO}}: 生物学',value:'WelcomeBIO'},{label:'{{WelcomeCHEM}}: 化学',value:'WelcomeCHEM'},{label:'{{WelcomeCVG}}: 电子游戏',value:'WelcomeCVG'},{label:'{{WelcomeFootball}}: 足球',value:'WelcomeFootball'},{label:'{{WelcomeMED}}: 医药',value:'WelcomeMED'},{label:'{{Welcomefl}}: 电影',value:'Welcomefl'},{label:'{{Welcomepl}}: 心理学',value:'Welcomepl'}]
friendlywelcome.regionList=[{label:'{{WelcomeTW}}: 台湾',value:'WelcomeTW'},{label:'{{Welcomegd}}: 广东',value:'Welcomegd'},{label:'{{Welcomegx}}: 广西',value:'Welcomegx'},{label:'{{Welcomehk}}: 香港',value:'Welcomehk'},{label:'{{WelcomePRC}}: 中华人民共和国',value:'WelcomePRC'},{label:'{{Welcomeshanxi}}: 山西',value:'Welcomeshanxi'},{label:'{{Welcomexa}}: 西安',value:'Welcomexa'},{label:'{{Welcomesx}}: 陝西',value:'Welcomesx'}]
friendlywelcome.headingHash={'Welcome':true,'Welcome plain':true,'Firstarticle':true,'Welcomevandal':false,'Welcomeipvandal':false,'Welcome-anon':true,'WelcomeACG':true,'WelcomeBIO':true,'WelcomeCHEM':true,'WelcomeCVG':true,'WelcomeFootball':true,'WelcomeMED':true,'Welcomefl':true,'Welcomepl':true,'WelcomeTW':true,'Welcomegd':true,'Welcomegx':true,'Welcomehk':true,'Welcomeshanxi':true,'Welcomexa':true,'Welcomesx':true}
friendlywelcome.signatureHash={'Welcome':true,'Welcome plain':true,'Firstarticle':true,'Welcomevandal':true,'Welcomeipvandal':true,'Welcome-anon':true,'WelcomeACG':true,'WelcomeBIO':true,'WelcomeCHEM':true,'WelcomeCVG':true,'WelcomeFootball':true,'WelcomeMED':true,'Welcomefl':true,'Welcomepl':true,'WelcomeTW':true,'Welcomegd':true,'Welcomegx':true,'Welcomehk':true,'Welcomeshanxi':true,'Welcomexa':true,'Welcomesx':true}
friendlywelcome.artHash={'Welcome':false,'Welcome plain':false,'Firstarticle':true,'Welcomevandal':true,'Welcomeipvandal':true,'Welcome-anon':false,'WelcomeACG':false,'WelcomeBIO':false,'WelcomeCHEM':false,'WelcomeCVG':false,'WelcomeFootball':false,'WelcomeMED':false,'Welcomefl':false,'Welcomepl':false,'WelcomeTW':false,'Welcomegd':false,'Welcomegx':false,'Welcomehk':false,'Welcomeshanxi':false,'Welcomexa':false,'Welcomesx':false}
friendlywelcome.vandalHash={'Welcome':false,'Welcome plain':false,'Firstarticle':true,'Welcomevandal':true,'Welcomeipvandal':true,'Welcome-anon':false,'WelcomeACG':false,'WelcomeBIO':false,'WelcomeCHEM':false,'WelcomeCVG':false,'WelcomeFootball':false,'WelcomeMED':false,'Welcomefl':false,'Welcomepl':false,'WelcomeTW':false,'Welcomegd':false,'Welcomegx':false,'Welcomehk':false,'Welcomeshanxi':false,'Welcomexa':false,'Welcomesx':false}
friendlywelcome.callbacks={main:function(self){var form=self.responseXML.getElementById('editform');if(form.wpTextbox1.value!='\n'&&self.params.mode=='auto'){Status.info('警告','用户讨论页不为空,取消操作');Wikipedia.actionCompleted.event();return;}
var text='';Status.info('信息','将会添加欢迎模板到用户讨论页'
+(FriendlyConfig.topWelcomes?'顶部':'底部'));if(!FriendlyConfig.topWelcomes){text+=form.wpTextbox1.value+'\n';}
Status.info('信息','将会替换引用{{'+self.params.value+'}}模板');text+='\{\{subst:'+self.params.value;if(friendlywelcome.artHash[self.params.value]){if(FriendlyConfig.insertUsername&&self.params.value.substring(2,0)!='W-'){Status.info('信息','将添加您的用户名到模板');text+='|'+wgUserName;}
if(self.params.article!=''){Status.info('信息','将添加条目名到模板');text+='|art='+self.params.article;}}else if(friendlywelcome.vandalHash[self.params.value]){if(self.params.article!=''){Status.info('信息','将添加被破坏条目名到模板');}
text+='|'+self.params.article;if(FriendlyConfig.insertUsername){Status.info('信息','将添加您的用户名到模板');text+='|'+wgUserName;}}else if(FriendlyConfig.insertUsername){Status.info('信息','将添加您的用户名到模板');text+='|'+wgUserName;}
text+='\}\}';if(!friendlywelcome.signatureHash[self.params.value]&&FriendlyConfig.insertSignature){Status.info('信息','将添加签名');text+=' \n\~\~\~\~';}
if(FriendlyConfig.topWelcomes){text+='\n\n'+form.wpTextbox1.value;}
var postData={'wpMinoredit':FriendlyConfig.markWelcomesAsMinor?1:undefined,'wpWatchthis':form.wpWatchthis.checked?1:(FriendlyConfig.watchWelcomes?1:undefined),'wpStarttime':form.wpStarttime.value,'wpEdittime':form.wpEdittime.value,'wpAutoSummary':form.wpAutoSummary.value,'wpEditToken':form.wpEditToken.value,'wpSummary':'添加'+(FriendlyConfig.maskTemplateInSummary?'欢迎':('\{\{[[Template:'+self.params.value+'|'+self.params.value+']]\}\}'))
+'模板到用户讨论页'+FriendlyConfig.summaryAd,'wpTextbox1':text};self.post(postData);}}
friendlywelcome.callback.evaluate=function friendlywelcomeCallbackEvaluate(e){if(e.target.name=='article'){return;}
var params={value:e.target.value,article:e.target.form.article.value,mode:'manual'};Status.init(e.target.form);var query={'title':wgPageName,'action':'submit'};Wikipedia.actionCompleted.redirect=wgPageName;Wikipedia.actionCompleted.notice="完成";var wikipedia_wiki=new Wikipedia.wiki('用户讨论页修改',query,friendlywelcome.callbacks.main);wikipedia_wiki.params=params;wikipedia_wiki.get();}
$(function(){if(QueryString.exists('friendlywelcome')){if(QueryString.get('friendlywelcome'=='auto')){friendlywelcome.auto();}else{friendlywelcome.semiauto();}}else{friendlywelcome.normal();}});