Automatically adds a Table of Contents block under the right-hand History sidebar of all entities on Kanka. You can customize its appearance using campaign CSS, but keep in mind that it is only visible on browsers where this script is installed. It should match the appearance of other sidebar blocks out of the box.
When clicking a link to a collapsed post (or a heading within), the post will automatically expand so you are scrolled to the correct position and can start reading right away. This also applies to Timeline events and their parent era.
Preferences
You can control the settings below by editing the /* Preferences */
section near the top of the script. Note that you will need to reimplement these changes each time you update the script.
Sticky table of contents
By default, the table of contents block is "sticky", meaning it will stay on-screen when you scroll down a long page. You can turn this off by changing the following property:
const stickyTOC = true;
→ const stickyTOC = false;
Back to top
The script can also add links to scroll back to the table of contents after every heading (excluding entry/post box headings), but this is turned off by default since it isn’t useful with a sticky ToC. To activate this feature, locate the following line and add the desired text inside the quotation marks:
const addTopLink = "";
→ e.g. const addTopLink = "toc";
Class exclusions
You can add any custom HTML classes to the script’s ignore list if you have content that you would rather not include, for example an infobox template that contains several headings not useful for content navigation. Simply add each one, within quotes, to the list that starts with const classExclusions = ["calendar", "modal", "box-entity-attributes", ...
.
Note: This script will not conflict with Kanka’s own tables of contents ({table-of-contents}
). You can use it to supplement the "native" tables of contents, and create back-to-top links if enabled.
If my scripts are making your life easier, please consider tipping via Ko-fi (no account needed):
