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>// Unindent discussions for accessibility// WARNING WARNING WARNING ----- DO NOT USE THIS SCRIPT// OBSOLETE AND BUGGY ----- DO NOT USE THIS SCRIPT// NOT DELETED ONLY BECAUSE I WANT TO REMEMBER SOME CODING IDEAS AND PITFALLS IN JAVASCRIPTfunctionunindent(){varalert_string="";vardiagnostic_string="";varindent_level=0;varindent_level_string="";varprev_indent_level_string="";varprepended_string="";varempty_prepended_string=" ";varDL_elements;varnum_DL_elements=0;varDT_elements;varnum_DT_elements=0;varDD_elements;vartemp_DD_element;varnum_DD_elements=0;varDD_element_index=0;varnum_unindented_DD_elements=0;varnum_higher_level_DD_elements=0;vartop_node;varchild_node;varparent_node;vartop_DD_node;vartop_DL_node;varprev_top_DL_node;vartemp_DD_text;varuntagged_text;varunspaced_text;varbyte_count=0;varnum_child_nodes=0;varnum_sub_DL_elements=0;varsibling_node;varsibling_node_list=newArray();// Colors to help sighted people after the unindentingvarnum_colors=0;varDD_background_colors=["white","yellow","greenyellow","gold","lightskyblue","orange","lawngreen","darkorange"];// Initializationnum_colors=DD_background_colors.length;top_node=document.getElementById('bodyContent');DD_elements=top_node.getElementsByTagName("DD");num_DD_elements=DD_elements.length;// First-pass loop colors the links and adds the level to the beginningdiagnostic_string="";num_unindented_DD_elements=0;num_higher_level_DD_elements=0;top_DL_node=null;prev_top_DL_node=null;prepended_string="";indent_level_string="";prev_indent_level_string="";for(DD_element_index=0;DD_element_index<num_DD_elements;DD_element_index++){temp_DD_element=DD_elements[DD_element_index];child_node=temp_DD_element.firstChild;if(child_node){if((child_node.nodeType==3)&&(child_node.data.match(/^\(Indent\s\d+\)/))){continue;}// add "(Indent #)" to beginning if it isn't there already}num_sub_DL_elements=temp_DD_element.getElementsByTagName("DL").length;// Skip empty DD elementsnum_child_nodes=temp_DD_element.childNodes.length;if(!num_child_nodes){continue;}// ignore empty DD elements//Alternative approach: skip all DD elements that have a sub DL element withintemp_DD_text=temp_DD_element.innerHTML;unspaced_text=temp_DD_text.replace(/\s/ig,"");// remove whitespacesuntagged_text=unspaced_text.replace(/<dl>.*<\/dl>/ig,"");// remove inner DL'suntagged_text=untagged_text.replace(/(<([^>]+)>)/ig,"");// remove other HTML tagsbyte_count=untagged_text.length;// count charactersif(byte_count<1){continue;}// Find the topmost DL element for this DD nodeindent_level=0;top_DL_node=null;top_DD_node=temp_DD_element;parent_node=temp_DD_element.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=="DL"){// Check whether the parent DL element has any DT elementsnum_DT_elements=parent_node.getElementsByTagName("DT").length;if(num_DT_elements>0){break;}// if so, stop unindenting...// ...else make this the new indent levelindent_level++;top_DL_node=parent_node;}// closes check for a parental DL elementif(parent_node.nodeName=="DD"){top_DD_node=parent_node;}parent_node=parent_node.parentNode;}// closes loop climbing up the document treeif(top_DL_node!=prev_top_DL_node){prev_indent_level_string="";}prev_top_DL_node=top_DL_node;if(indent_level>2){num_higher_level_DD_elements++;}if(indent_level>0){num_unindented_DD_elements++;temp_DD_element.style.cssText="background-color:"+DD_background_colors[indent_level%num_colors];indent_level_string="(Indent "+indent_level+") ";// indent_level_string = "(Indent " + indent_level + " " + num_sub_DL_elements + ") ";// if (num_sub_DL_elements > 0) { // indent_level_string += "[ " + num_sub_DL_elements + " " + byte_count + " " + untagged_text + " ] ";// }if(indent_level_string==prev_indent_level_string){prepended_string=empty_prepended_string;}else{prepended_string=indent_level_string;}prev_indent_level_string=indent_level_string;child_node=temp_DD_element.firstChild;if(child_node){if((child_node.nodeType!=3)||(!child_node.data.match(/^\(Indent\s\d+\)/))){temp_DD_element.insertBefore(document.createTextNode(prepended_string),child_node);}// add "(Indent #)" to beginning if it isn't there already}else{indent_level_string+="No text in this DD element.\n";temp_DD_element.appendChild(document.createTextNode(prepended_string));}temp_DD_element.normalize();sibling_node_list[DD_element_index]=null;if((top_DD_node)&&(top_DL_node)){sibling_node=top_DD_node.nextSibling;while((sibling_node)&&(sibling_node.nodeType!=1)){sibling_node=sibling_node.nextSibling;}}// closes check that both top_DD_node and top_DL_node are definedif(sibling_node_list[DD_element_index]){diagnostic_string+="DD element "+DD_element_index+" is indented to level "+indent_level+".\n";}else{diagnostic_string+="DD element "+DD_element_index+" is indented to level "+indent_level+". NULL SIBLING\n";}}// check for unindenting}// closes loop over the DD elements of the document// window.alert(diagnostic_string);// Prevents repeated applications of the script from changing the colorsif(num_higher_level_DD_elements==0){return;}// Second-pass loop changes the document tree structurediagnostic_string="";for(DD_element_index=0;DD_element_index<num_DD_elements;DD_element_index++){temp_DD_element=DD_elements[DD_element_index];indent_level=0;// Find the topmost DL element for this DD nodetop_DL_node=null;top_DD_node=null;parent_node=temp_DD_element.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=="DL"){// Check whether the parent DL element has any DT elementsnum_DT_elements=parent_node.getElementsByTagName("DT").length;if(num_DT_elements>0){break;}// if so, stop unindenting...// ...else make this the new indent levelindent_level++;top_DL_node=parent_node;}// closes check for a parental DL elementif(parent_node.nodeName=="DD"){top_DD_node=parent_node;}parent_node=parent_node.parentNode;}// closes loop climbing up the document treeif(indent_level>1){if((top_DD_node)&&(top_DL_node)){// top_DL_node.insertBefore(temp_DD_element, top_DD_element);sibling_node=sibling_node_list[DD_element_index];if(sibling_node){top_DL_node.insertBefore(temp_DD_element,sibling_code);}else{top_DL_node.appendChild(temp_DD_element);}}// check that both the top_DD and top_DL elements are defined}// check for unindenting}// closes loop over the DD elements of the document// window.alert(diagnostic_string);// Third-pass loop to uncreate empty discursive lists//Acknowledgmentalert_string="Unindented "+num_unindented_DD_elements+" paragraphs of "+num_DD_elements+" possible.";window.alert(alert_string);}// closes unindent() functionaddOnloadHook(function(){mw.util.addPortletLink('p-cactions','javascript:unindent()','unindent','ca-unindent','Unindent discussions','i','');});//</pre>