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>// Check whether alt text is specified for all images on a page//// To use this script, add "importScript('User:Proteins/checkALTtext.js');" to your monobook.js subpage // under your user page, as you can see at User:Proteins/monobook.jsfunctioncheckAltText(){varalt_text="";varalert_string="";varerror_string="";vartemp_image;varparent_node;vargrandparent_node;varnum_pixels=0;varimage_index=0;varnum_raw_images=0;varnum_icon_images=0;varnum_icon_images_missing_alt_text=0;varnum_nonicon_images=0;varnum_nonicon_images_missing_alt_text=0;varicon_percentage=0.0;varnonicon_percentage=0.0;// Loop over the imagesnum_icon_images=0;num_icon_images_missing_alt_text=0;num_nonicon_images=0;num_nonicon_images_missing_alt_text=0;num_raw_images=document.images.length;alert_string="This document has "+num_raw_images+" images.\n\n";// window.alert(alert_string);for(image_index=0;image_index<num_raw_images;image_index++){alt_text="";temp_image=document.imagesimage_index];if(!temp_image){continue;}alt_text=temp_image.alt;num_pixels=temp_image.width*temp_image.height;if(temp_image.src.match(/Replace_this_image_male\.svg/)){continue;}if(temp_image.src.match(/Replace_this_image_female\.svg/)){continue;}if(num_pixels>5000){num_nonicon_images++;if(!alt_text){num_nonicon_images_missing_alt_text++;temp_image.src="";}continue;}num_icon_images++;if(!alt_text){num_icon_images_missing_alt_text++;temp_image.src="";}}// closes loop over the imagesicon_percentage=0.0;nonicon_percentage=0.0;if(num_nonicon_images>0){nonicon_percentage=(100.0*num_nonicon_images_missing_alt_text)/num_nonicon_images;nonicon_percentage=Math.round(nonicon_percentage);alert_string+=num_nonicon_images_missing_alt_text+" of "+num_nonicon_images+" normal images ";if(num_nonicon_images_missing_alt_text==1){alert_string+="is";}else{alert_string+="are";}alert_string+=" missing alt text ("+nonicon_percentage+"%).\n\n";}if(num_icon_images>0){icon_percentage=(100.0*num_icon_images_missing_alt_text)/num_icon_images;icon_percentage=Math.round(icon_percentage);alert_string+=num_icon_images_missing_alt_text+" of "+num_icon_images+" small images ";if(num_icon_images_missing_alt_text==1){alert_string+="is";}else{alert_string+="are";}alert_string+=" missing alt text ("+icon_percentage+"%).\n";alert_string+="Small images are defined as those having fewer than 5000 pixels.\n\n";}window.alert(alert_string);}// closes function checkAltText() $(function(){mw.util.addPortletLink('p-cactions','javascript:checkAltText()','alt','ca-alttext','Check images for alt text','','');});//</pre>