User:DVRTed/sandbox/declutterUserTalk.js
Appearance
< User:DVRTed | sandbox
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.
This code will be executed when previewing this page.
Documentation for this user script can be added at User:DVRTed/sandbox/declutterUserTalk.
/* declutter user talk pages.
adds a button at the top of user talk pages that, when clicked,
gets rid of all the clutter, retaining only the ACTUAL talk sections and the table of contents;
also fixes the talk messages getting hidden behind "about this page" on mobile view.
*/
/* global mw, $ */
mw.loader.using("mediawiki.ui.button").then(() => {
if (mw.config.get("wgNamespaceNumber") !== 3) return;
const main_wrapper = $("#mw-content-text .mw-parser-output");
function declutter_talk_page() {
const toc = main_wrapper.find("#toc").detach();
const first_section = main_wrapper
.find("div.ext-discussiontools-init-section.mw-heading")
.first();
if (!first_section.length) return;
const talk_messages = first_section.add(first_section.nextAll()).detach();
main_wrapper.empty().append(toc, talk_messages);
}
const button = $("<button>")
.addClass("mw-ui-button mw-ui-progressive")
.text("Declutter this talk page")
.on("click", declutter_talk_page);
main_wrapper.prepend(button);
});