jcunews

AutoCollapseWikipediaPlotSection.user.js

May 9th, 2021
672
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Auto Collapse Wikipedia "Plot" Section
  3. // @namespace    https://greasyfork.org/en/users/85671-jcunews
  4. // @version      1.0.1
  5. // @license      AGPLv3
  6. // @author       jcunews
  7. // @description  https://www.reddit.com/r/userscripts/comments/n72ppa/request_collapse_the_plot_paragraph_by_default_on/
  8. // @match        https://*.wikipedia.org/wiki/*
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. ((a, b, c, d, l) => {
  13.   if (a = document.querySelector("#Plot.mw-headline")) {
  14.     b = a.nextElementSibling ? a : a.parentNode;
  15.     b.insertAdjacentHTML("beforeend", '<a href="javascript:void(0)" style="margin-left:2em;font-size:10pt;font-weight:normal">[Expand]</a>');
  16.     b.lastChild.onclick = function() {
  17.       l.forEach(e => {
  18.         e.style.display = e.dataset.display;
  19.       });
  20.       this.remove();
  21.     };
  22.     d = (c = Array.from(document.querySelectorAll(".mw-headline,.navbox"))).indexOf(a);
  23.     if (d >= 0) {
  24.       if (!(c = c[d + 1]).nextElementSibling) c = c.parentNode;
  25.     } else c = null;
  26.     l = [];
  27.     while ((b = b.nextElementSibling) && (b !== c)) {
  28.       l.push(b);
  29.       b.dataset.display = b.style.display;
  30.       b.style.display = "none";
  31.     }
  32.   }
  33. })();
  34.  
RAW Paste Data