Jump to content

User:Polygnotus/Scripts/SectionLinks

From Wikipedia, the free encyclopedia

This script adds icons to each section header that, when clicked, copy a link or a permalink to the clipboard.

SectionLinks
DescriptionAdds icons to each section header that, when clicked, copy a link or a permalink to the clipboard.
AuthorsDVRTed and Polygnotus
UpdatedAugust 14, 2026
    (1 day ago)
SourceUser:Polygnotus/Scripts/SectionLinks.js

Installation

[edit]

First install User:Enterprisey/script-installer, then come back to this page and click the giant blue "Install" button in the infobox on the right.

Or install it manually by adding the below code to your Special:MyPage/common.js file:

{{subst:iusc|User:Polygnotus/Scripts/SectionLinks.js}}

Usage

[edit]

Click on the icon to the left for a permalink to that section. Click on the icon to the right for a link to that section.

Functionality

[edit]
  • Adds icons that allow you to copy a link or a permalink.
  • When viewing a diff it will give you a link to that diff.

Customization

[edit]

By default, the script adds a button to all h1, h2, h3, and h4 headers. You can override this by setting SECTIONLINKS_CUSTOM_HEADER_SELECTOR to a jQuery selector in your common.js, before the code loading the script.

The code that loads the script looks like this:

importScript('User:Polygnotus/Scripts/SectionLinks.js'); // Backlink: [[User:Polygnotus/Scripts/SectionLinks.js]]

Examples:

Only h2 and h3:

var SECTIONLINKS_CUSTOM_HEADER_SELECTOR = ".mw-heading :is(h2,h3)[id]";

Only h2:

var SECTIONLINKS_CUSTOM_HEADER_SELECTOR = ".mw-heading h2[id]";

All levels up to h5:

var SECTIONLINKS_CUSTOM_HEADER_SELECTOR = ".mw-heading :is(h1,h2,h3,h4,h5)[id]";

The selector must target elements that have an id attribute, otherwise the script has no anchor to link to. Do not remove the [id] part from the selector.