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.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
//<pre>// This script counts and lists AfD !votes. Tip o' the hat to Graham87.//// To use this script, add "importScript('User:Proteins/summarizeAfD.js');" to your monobook.js subpage // under your user page, as you can see at User:Proteins/monobook.jsfunctionsummarizeAfD(){varalert_string="";varreported_string="";vardiagnostic_string="";varindented;vartop_node;varparent_node;varlist_items;vartemp_list_item;varnum_list_items=0;varlist_item_index=0;varnum_unindented_list_items=0;varboldface_elements;varboldface_text="";varfirst_boldface_element;varnum_boldface_elements=0;varboldface_element_index=0;varnum_votes=0;varnum_notes=0;varnum_comments=0;varnum_keep_votes=0;varnum_merge_votes=0;varnum_delete_votes=0;varnum_redirect_votes=0;varnum_refactor_votes=0;varnum_transwiki_votes=0;varnum_ambiguous_votes=0;varnum_error_messages=0;varnote_index=0;varcomment_index=0;varkeep_vote_index=0;varmerge_vote_index=0;vardelete_vote_index=0;varredirect_vote_index=0;varrefactor_vote_index=0;vartranswiki_vote_index=0;varambiguous_vote_index=0;varerror_message_index=0;varnote_summary="";varcomment_summary="";varkeep_vote_summary="";varmerge_vote_summary="";vardelete_vote_summary="";varredirect_vote_summary="";varrefactor_vote_summary="";vartranswiki_vote_summary="";varambiguous_vote_summary="";varerror_message_summary="";varnotes=newArray();varcomments=newArray();varkeep_votes=newArray();varmerge_votes=newArray();vardelete_votes=newArray();varredirect_votes=newArray();varrefactor_votes=newArray();vartranswiki_votes=newArray();varambiguous_votes=newArray();varerror_messages=newArray();varuser_name="";varalias_name="";varuser_talk_name="";varalias_talk_name="";varlist_item_links;vartemp_list_item_link;varnum_list_item_links=0;varlist_item_link_index=0;varlist_item_link_text="";varpossible_user_name=true;varnum_enclosing_list_tags=0;// Get the top nodetop_node=document.getElementById('bodyContent');if(!top_node){window.alert("No bodyContent node in this document.");return;}// Get the list itemslist_items=top_node.getElementsByTagName("LI");if(!list_items){window.alert("This article has no list items.");return;}num_list_items=list_items.length;// Initializationsnum_notes=0;num_comments=0;num_keep_votes=0;num_merge_votes=0;num_delete_votes=0;num_redirect_votes=0;num_refactor_votes=0;num_transwiki_votes=0;num_ambiguous_votes=0;notes[0]="NONE";comments[0]="NONE";keep_votes[0]="NONE";merge_votes[0]="NONE";delete_votes[0]="NONE";redirect_votes[0]="NONE";refactor_votes[0]="NONE";transwiki_votes[0]="NONE";ambiguous_votes[0]="NONE";// Loop over the list itemsnum_unindented_list_items=0;for(list_item_index=1;list_item_index<=num_list_items;list_item_index++){temp_list_item=list_items[list_item_index-1];if(!temp_list_item){window.alert("List item "+list_item_index+" doesn't exist.");continue;}// shouldn't happen, but...// find the enclosing ordered or unordered listfound_parent_list=false;parent_node=temp_list_item.parentNode;while((parent_node)&&(parent_node!=top_node)){if(parent_node.nodeType!=1){parent_node=parent_node.parentNode;continue;}// examine only Element nodesif((parent_node.nodeName=="UL")||(parent_node.nodeName=="OL")){found_parent_list=true;break;}// closes check for a parental list elementparent_node=parent_node.parentNode;}// closes loop climbing up the document treeif(found_parent_list==false){diagnostic_string="List item "+list_item_index+" doesn't have an enclosing list:\n\n";diagnostic_string+=temp_list_item.innerHTML.replace(/(<([^>]+)>)/ig,"")+"\n";window.alert(diagnostic_string);continue;}// check that the list item is not indentedindented=false;parent_node=parent_node.parentNode;while((parent_node)&&(parent_node!=top_node)){if(parent_node.nodeType!=1){parent_node=parent_node.parentNode;continue;}// examine only Element nodesif((parent_node.nodeName=="DD")||(parent_node.nodeName=="DL")||(parent_node.nodeName=="UL")||(parent_node.nodeName=="OL")||(parent_node.nodeName=="LI")){indented=true;break;}// closes check for a parental list elementparent_node=parent_node.parentNode;}// closes loop climbing up the document treeif(indented==true){// window.alert("List item " + list_item_index + " is indented."); continue;}num_unindented_list_items++;// get the first bold-faced item within this list itemboldface_elements=temp_list_item.getElementsByTagName("B");if(!boldface_elements){diagnostic_string="List item "+list_item_index+" has no boldface elements:\n\n";diagnostic_string+=temp_list_item.innerHTML.replace(/(<([^>]+)>)/ig,"")+"\n";window.alert(diagnostic_string);continue;}num_boldface_elements=boldface_elements.length;if(num_boldface_elements==0){// window.alert("List item " + list_item_index + " has no first boldface element.\n");continue;}elseif(num_boldface_elements==1){// window.alert("List item " + list_item_index + " has one boldface element.\n");}else{// window.alert("List item " + list_item_index + " has " + num_boldface_elements + " boldface elements.\n");}first_boldface_element=null;for(boldface_element_index=0;boldface_element_index<num_boldface_elements;boldface_element_index++){first_boldface_element=boldface_elements[boldface_element_index];parent_node=parent_node.parentNode;while((parent_node)&&(parent_node!=temp_list_item)){if(parent_node.nodeName=="S"){first_boldface_element=null;break;}parent_node=parent_node.parentNode;}if(first_boldface_element){break;}}// closes loop identifying the first valid boldface element of this list itemif(!first_boldface_element){window.alert("List item "+list_item_index+" has no first boldface element.\n");continue;}// Find the user name list_item_links=temp_list_item.getElementsByTagName("A");if(!list_item_links){diagnostic_string="List item "+list_item_index+" has no links:\n\n";diagnostic_string+=temp_list_item.innerHTML.replace(/(<([^>]+)>)/ig,"")+"\n";window.alert(diagnostic_string);continue;}num_list_item_links=list_item_links.length;if(num_list_item_links==0){diagnostic_string="List item "+list_item_index+" has no links:\n\n";diagnostic_string+=temp_list_item.innerHTML.replace(/(<([^>]+)>)/ig,"")+"\n";window.alert(diagnostic_string);continue;}user_name="";user_talk_name="";for(list_item_link_index=num_list_item_links;list_item_link_index>0;list_item_link_index--){temp_list_item_link=list_item_links[list_item_link_index-1];if(!temp_list_item_link){window.alert("The "+list_item_link_index+" link in the "+list_item_index+"list item doesn't exist.\n");continue;}possible_user_name=true;num_enclosing_list_tags=0;parent_node=temp_list_item_link.parentNode;while((parent_node)&&(parent_node!=top_node)){if(parent_node.nodeType!=1){parent_node=parent_node.parentNode;continue;}// examine only Element nodesif(parent_node.nodeName=="S"){possible_user_name=false;break;}if(parent_node.nodeName=="UL"){possible_user_name=false;break;}if(parent_node.nodeName=="OL"){possible_user_name=false;break;}if(parent_node.nodeName=="DL"){possible_user_name=false;break;}if(parent_node.nodeName=="DD"){possible_user_name=false;break;}if(parent_node.nodeName=="LI"){num_enclosing_list_tags++;if(num_enclosing_list_tags>1){possible_user_name=false;break;}}// closes check for a parental list elementif(parent_node==temp_list_item){break;}parent_node=parent_node.parentNode;}// closes loop climbing up the document treeif(possible_user_name==false){continue;}if(num_enclosing_list_tags!=1){continue;}if(parent_node!=temp_list_item){continue;}list_item_link_text=temp_list_item_link.title;list_item_link_text=list_item_link_text.replace(/(<([^>]+)>)/ig,"");// remove HTML tagsif((list_item_link_text.match(/^User:/))&&(!list_item_link_text.match(/\//))){user_name=list_item_link_text.replace(/^User:/,"");user_name=user_name.replace(/\s+\(page does not exist\)$/,"");user_name=user_name.replace(/ /ig," ");// convert non-breaking spaces to spacesuser_name=user_name.replace(/ /ig," ");// convert non-breaking spaces to spacesuser_name=user_name.replace(/\s+/ig," ");// convert all whitespace to a single spacealias_name=temp_list_item_link.innerHTML;alias_name=alias_name.replace(/(<([^>]+)>)/ig,"");// remove HTML tagsalias_name=alias_name.replace(/ /ig," ");// convert non-breaking spaces to spacesalias_name=alias_name.replace(/ /ig," ");// convert non-breaking spaces to spacesalias_name=alias_name.replace(/\s+/ig," ");// convert all whitespace to a single spaceif(alias_name.replace(/\s/g,"").toLowerCase()!=user_name.replace(/\s/g,"").toLowerCase()){user_name+=" ("+alias_name+")";}break;}if((list_item_link_text.match(/^User\stalk:/))&&(!list_item_link_text.match(/\//))){user_talk_name=list_item_link_text.replace(/^User\stalk:/,"");user_talk_name=user_talk_name.replace(/\s+\(page does not exist\)$/,"");user_talk_name=user_talk_name.replace(/ /ig," ");// non-breaking spaces to spacesuser_talk_name=user_talk_name.replace(/ /ig," ");// non-breaking spaces to spacesuser_talk_name=user_talk_name.replace(/\s+/ig," ");// all whitespace to a single spacealias_talk_name=temp_list_item_link.innerHTML;alias_talk_name=alias_talk_name.replace(/(<([^>]+)>)/ig,"");// remove HTML tagsalias_talk_name=alias_talk_name.replace(/ /ig," ");// non-breaking spaces to spacesalias_talk_name=alias_talk_name.replace(/ /ig," ");// non-breaking spaces to spacesalias_talk_name=alias_talk_name.replace(/\s+/ig," ");// all whitespace to a single spaceif(alias_talk_name.replace(/\s/g,"").toLowerCase()!=user_talk_name.replace(/\s/g,"").toLowerCase()){user_talk_name+=" ("+alias_talk_name+")";}}}// closes loop over the list-item links if(!user_name){if(!user_talk_name){diagnostic_string="List item "+list_item_index+" has no user name.\n\n";diagnostic_string+=temp_list_item.innerHTML.replace(/(<([^>]+)>)/ig,"")+"\n";window.alert(diagnostic_string);continue;}else{user_name=user_talk_name;}}num_boldface_elements=boldface_elements.length;if(num_boldface_elements==0){// window.alert("List item " + list_item_index + " has no first boldface element.\n");continue;}elseif(num_boldface_elements==1){// window.alert("List item " + list_item_index + " has one boldface element.\n");}else{// window.alert("List item " + list_item_index + " has " + num_boldface_elements + " boldface elements.\n");}// Analyze the votesboldface_text=first_boldface_element.innerHTML;if(!boldface_text){window.alert("List item "+list_item_index+" has no boldface text.\n");}boldface_text=boldface_text.replace(/(<([^>]+)>)/ig,"");// remove HTML tags// window.alert("List item " + list_item_index + " has boldface text: " + boldface_text + "\n"); if(boldface_text.match(/delet/ig)){num_delete_votes++;reported_string=num_delete_votes+". "+boldface_text+" — "+user_name+"\n";// window.alert(reported_string);delete_votes[num_delete_votes-1]=reported_string;}elseif(boldface_text.match(/remov/ig)){num_delete_votes++;reported_string=num_delete_votes+". "+boldface_text+" — "+user_name+"\n";delete_votes[num_delete_votes-1]=reported_string;}elseif(boldface_text.match(/keep/ig)){num_keep_votes++;reported_string=num_keep_votes+". "+boldface_text+" — "+user_name+"\n";keep_votes[num_keep_votes-1]=reported_string;}elseif(boldface_text.match(/merg/ig)){num_merge_votes++;reported_string=num_merge_votes+". "+boldface_text+" — "+user_name+"\n";merge_votes[num_merge_votes-1]=reported_string;}elseif(boldface_text.match(/redirect/ig)){num_redirect_votes++;reported_string=num_redirect_votes+". "+boldface_text+" — "+user_name+"\n";redirect_votes[num_redirect_votes-1]=reported_string;}elseif(boldface_text.match(/transwiki/ig)){num_transwiki_votes++;reported_string=num_transwiki_votes+". "+boldface_text+" — "+user_name+"\n";transwiki_votes[num_transwiki_votes-1]=reported_string;}elseif(boldface_text.match(/refactor/ig)){num_refactor_votes++;reported_string=num_refactor_votes+". "+boldface_text+" — "+user_name+"\n";refactor_votes[num_refactor_votes-1]=reported_string;}elseif(boldface_text.match(/comment/ig)){num_comments++;reported_string=num_comments+". "+boldface_text+" — "+user_name+"\n";comments[num_comments-1]=reported_string;}elseif(boldface_text.match(/note/ig)){num_notes++;reported_string=num_notes+". "+boldface_text+" — "+user_name+"\n";notes[num_notes-1]=reported_string;}else{num_ambiguous_votes++;reported_string=num_ambiguous_votes+". "+boldface_text+" — "+user_name+"\n";ambiguous_votes[num_ambiguous_votes-1]=reported_string;}}// closes loop over list itemsnum_votes=num_keep_votes+num_delete_votes+num_merge_votes+num_redirect_votes+num_transwiki_votes+num_refactor_votes+num_ambiguous_votes;// Print acknowledgmentalert_string="";// alert_string ="This article has " + num_unindented_list_items + " unindented list items of " + num_list_items + " possible.\n\n"if(num_votes==1){alert_string+="One !vote was counted:\n";}else{alert_string+=num_votes+" !votes were counted:\n";}if(num_delete_votes==1){alert_string+="\t one Delete !vote\n";delete_vote_summary="There was one Delete !vote:\n\n";}elseif(num_delete_votes){alert_string+="\t "+num_delete_votes+" Delete !votes\n";delete_vote_summary="There were "+num_delete_votes+" Delete !votes:\n\n";}if(num_keep_votes==1){alert_string+="\t one Keep !vote\n";keep_vote_summary="There was one Keep !vote:\n\n";}elseif(num_keep_votes){alert_string+="\t "+num_keep_votes+" Keep !votes\n";keep_vote_summary="There were "+num_keep_votes+" Keep !votes:\n\n";}if(num_merge_votes==1){alert_string+="\t one Merge !vote\n";merge_vote_summary="There was one Merge !vote:\n\n";}elseif(num_merge_votes){alert_string+="\t "+num_merge_votes+" Merge !votes\n";merge_vote_summary="There were "+num_merge_votes+" Merge !votes:\n\n";}if(num_redirect_votes==1){alert_string+="\t one Redirect !vote\n";redirect_vote_summary="There was one Redirect !vote:\n\n";}elseif(num_redirect_votes){alert_string+="\t "+num_redirect_votes+" Redirect !votes\n";redirect_vote_summary="There were "+num_redirect_votes+" Redirect !votes:\n\n";}if(num_transwiki_votes==1){alert_string+="\t one Transwiki !vote\n";transwiki_vote_summary="There was one Transwiki !vote:\n\n";}elseif(num_transwiki_votes){alert_string+="\t "+num_transwiki_votes+" Transwiki !votes\n";transwiki_vote_summary="There were "+num_transwiki_votes+" Transwiki !votes:\n\n";}if(num_refactor_votes==1){alert_string+="\t one Refactor !vote\n";refactor_vote_summary="There was one Refactor !vote:\n\n";}elseif(num_refactor_votes){alert_string+="\t "+num_refactor_votes+" Refactor !votes\n";refactor_vote_summary="There were "+num_refactor_votes+" Refactor !votes:\n\n";}if(num_ambiguous_votes==1){alert_string+="\t one ambiguous !vote\n";ambiguous_vote_summary="There was one ambiguous !vote:\n\n";}elseif(num_ambiguous_votes){alert_string+="\t "+num_ambiguous_votes+" ambiguous !votes\n";ambiguous_vote_summary="There were "+num_ambiguous_votes+" ambiguous !votes:\n\n";}if((num_notes+num_comments)==1){alert_string+="\nIn addition, there was:\n";}elseif(num_notes+num_comments){alert_string+="\nIn addition, there were:\n";}if(num_notes==1){alert_string+="\t one Note\n";note_summary="There was one Note:\n\n";}elseif(num_notes){alert_string+="\t "+num_notes+" Notes\n";note_summary="There were "+num_notes+" Notes:\n\n";}if(num_comments==1){alert_string+="\t one Comment\n";comment_summary="There was one Comment:\n\n";}elseif(num_comments){alert_string+="\t "+num_comments+" Comments\n";comment_summary="There were "+num_comments+" comments:\n\n";}window.alert(alert_string);// Report more details on each type of !voteif(num_delete_votes>0){alert_string=delete_vote_summary;for(delete_vote_index=0;delete_vote_index<num_delete_votes;delete_vote_index++){if((delete_vote_index%40==0)&&(delete_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=delete_votes[delete_vote_index];}window.alert(alert_string);}if(num_keep_votes>0){alert_string=keep_vote_summary;for(keep_vote_index=0;keep_vote_index<num_keep_votes;keep_vote_index++){if((keep_vote_index%40==0)&&(keep_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=keep_votes[keep_vote_index];}window.alert(alert_string);}if(num_merge_votes>0){alert_string=merge_vote_summary;for(merge_vote_index=0;merge_vote_index<num_merge_votes;merge_vote_index++){if((merge_vote_index%40==0)&&(merge_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=merge_votes[merge_vote_index];}window.alert(alert_string);}if(num_redirect_votes>0){alert_string=redirect_vote_summary;for(redirect_vote_index=0;redirect_vote_index<num_redirect_votes;redirect_vote_index++){if((redirect_vote_index%40==0)&&(redirect_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=redirect_votes[redirect_vote_index];}window.alert(alert_string);}if(num_transwiki_votes>0){alert_string=transwiki_vote_summary;for(transwiki_vote_index=0;transwiki_vote_index<num_transwiki_votes;transwiki_vote_index++){if((transwiki_vote_index%40==0)&&(transwiki_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=transwiki_votes[transwiki_vote_index];}window.alert(alert_string);}if(num_refactor_votes>0){alert_string=refactor_vote_summary;for(refactor_vote_index=0;refactor_vote_index<num_refactor_votes;refactor_vote_index++){if((refactor_vote_index%40==0)&&(refactor_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=refactor_votes[refactor_vote_index];}window.alert(alert_string);}if(num_ambiguous_votes>0){alert_string=ambiguous_vote_summary;for(ambiguous_vote_index=0;ambiguous_vote_index<num_ambiguous_votes;ambiguous_vote_index++){if((ambiguous_vote_index%40==0)&&(ambiguous_vote_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=ambiguous_votes[ambiguous_vote_index];}window.alert(alert_string);}if(num_comments>0){alert_string=comment_summary;for(comment_index=0;comment_index<num_comments;comment_index++){if((comment_index%40==0)&&(comment_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=comments[comment_index];}window.alert(alert_string);}if(num_notes>0){alert_string=note_summary;for(note_index=0;note_index<num_notes;note_index++){if((note_index%40==0)&&(note_index>1)){alert_string+="\nContinued on next screen...";window.alert(alert_string);alert_string="Continued from previous screen...\n\n";}alert_string+=notes[note_index];}window.alert(alert_string);}}// closes function summarizeAfD() addOnloadHook(function(){mw.util.addPortletLink('p-cactions','javascript:summarizeAfD()','AfD','ca-afd','Summarize AfD votes','a','');});//</pre>