User:GhostInTheMachine/FoldSections

Purpose
This script adds an icon in front of each section header.
 *  for a section that is expanded — fully displayed
 *  for a section that is collapsed — everything below the heading is hidden

Use
The icon acts as a toggle button — collapsing or "folding" the text of a displayed section or displaying the text of a currently collapsed section.

The icon is added to all headings from H2 down.

Prerequisites
The script probably only works on Vector. I have not tried it on other skins or on Evil Vector.

Installing
Add the following line to your common.js file.

Add the following line for elsewhere mw.loader.load( '/w/index.php?title=User:GhostInTheMachine/FoldSections.js&action=raw&ctype=text/javascript' ); // Backlink: User:GhostInTheMachine/FoldSections.js

Contributions list
In March 2022, added daily date headings into the user contributions page. Rather than have the code test for which skin was in use and only output them for the mobile skin, on the desktop skins the dates are just hidden.

This script adds CSS to cause the daily dates to be also displayed for desktop skins, so that it is possible to collapse individual days in the list.

Talk pages
The script no longer works on talk pages (and such pages as the Village Pump) due to the Discussion Tools changes. Talk pages no longer show the section headings in H2 tags as nature intended, but in a div tag which has a mw-heading2 class.

, I am working to alter this script to cope with the change.

Alternatives

 * User:BrandonXLF/CollapseSections — the original — puts icons in front of all section headings
 * User:BethNaught/hideSectionDesktop — puts links after the section headings — only H2 headings

June 2024
Damage due to a series of changes to the HTML created for headings.
 * see and more details in Heading HTML changes

Possible improvements
Replace the icons with characters
 * This might avoid any extra load dependency
 * This would allow them to be styled to a different colour
 * Maybe — ↑ and ↓
 * Have different jQuery filters for articles and the contributions page
 * Do not try to collapse the TOC in articles
 * Confirm that the fix for does not have other side-effects
 * Check changes from and probably