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.
// Automatically collapse talk page sections from bots// License: CC0functionsetup(){// If we're not reading a talk page, do nothingif(!(mw.config.get('wgAction')==='view'&&mw.config.get('wgIsArticle')&&!location.search.split('oldid=')[1]// Old revision&&mw.config.get('wgNamespaceNumber')%2==1)){// talk namespaces have odd numbersreturn;}mw.loader.using("jquery.makeCollapsible",function(){varuserMappings={};$(".mw-heading2").each(function(){extractUsers(this,userMappings);});checkBotStatus(userMappings);});}functionextractUsers(header,userMappings){vartalkNodes=$(header).nextUntil(".mw-heading2");varlastSignature=$(talkNodes).find("a[href^='/wiki/User:']").last();if(lastSignature.length){varusername=lastSignature.text();// Map each user with their sectionsif(!(usernameinuserMappings)){userMappings[username]=[header];}else{userMappings[username].push(header);}}}functioncheckBotStatus(userMappings){varuserList=Object.keys(userMappings);// API docs: https://www.mediawiki.org/wiki/API:Users$.ajax({url:"https://en.wikipedia.org/w/api.php",data:{action:"query",list:"users",format:"json",ususers:userList.join("|"),usprop:"groups"},success:function(response){varbotList=[];varresponseList=response.query.users;for(varrofresponseList){if(r.groups&&r.groups.includes("bot")){botList.push(r.name);}}filterUsers(userMappings,botList);}});}// Look for the bots in our mappings// More convoluted than necessary because API returns usernames in its// own case, while we use them as keysfunctionfilterUsers(userMappings,botList){varheaders=[];for(varbotofbotList){for(varuserinuserMappings){if(bot.toLowerCase()==user.toLowerCase()){headers=headers.concat(userMappings[user]);}}}for(varhofheaders){collapseSection(h);}}// In-house method: https://www.mediawiki.org/wiki/Manual:Collapsible_elementsfunctioncollapseSection(header){varsiblings=$(header).nextUntil(".mw-heading2, .collapseBots");$(siblings).wrapAll("<div class='mw-collapsible-content'></div>");// Recompute since we just wrapped all the siblingssiblings=$(header).next(".mw-collapsible-content");varsection=$().add(header).add(siblings);$(section).wrapAll("<div class='collapseBots mw-collapsed'></div>");$(section).parent().makeCollapsible();}setup();