Headlapse

Hide topic head with spoiler on all pages except first

当前为 2017-12-23 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Headlapse
  3. // @name:ru Шапкозакрывательство
  4. // @description Hide topic head with spoiler on all pages except first
  5. // @description:ru Каждой шапке по шапке! /Свернуть шапки тем под спойлер на всех страницах темы, кроме первой/
  6. // @version 0.0.5
  7. // @date 23.12.2017
  8. // @author Halibut
  9. // @namespace https://greasyfork.org/en/users/145947-halibut
  10. // @homepageURL https://greasyfork.org/en/scripts/36645-headlapse
  11. // @supportURL https://forum.ru-board.com/topic.cgi?forum=2&topic=56723&glp
  12. // @license HUG-WARE
  13. // @include http*://forum.ru-board.com/topic.cgi?forum=*&topic=*
  14. // @exclude /^https?:\/\/forum\.ru-board\.com\/topic\.cgi\?forum=\d+&topic=\d+(#\d+|#lt|&start=0)?$/
  15. // @noframes
  16. // @run-at document-start
  17. // @grant none
  18. // ==/UserScript==
  19.  
  20. /******************************************************************************
  21. * "THE HUG-WARE LICENSE" (Revision 2): As long as you retain this notice you *
  22. * can do whatever you want with this stuff. If we meet some day, and you *
  23. * think this stuff is worth it, you can give me/us a hug. *
  24. ******************************************************************************/
  25.  
  26. window.addEventListener('DOMContentLoaded', function headlapse() {
  27. "use strict";
  28. this.removeEventListener('DOMContentLoaded', headlapse);
  29. const tpcHead = document.getElementsByClassName('tb')[0]
  30. if (!tpcHead || tpcHead && !tpcHead.querySelector('a.tpc[href$="&postno=1"]')) return;
  31. tpcHead.hidden = true;
  32. const dummyNode = tpcHead.parentNode.insertBefore(document.createElement('div'), tpcHead),
  33. show = '\u25BA Показать шапку темы',
  34. hide = '\u25BC Скрыть шапку темы';
  35. dummyNode.outerHTML = '<table width="95%" cellspacing="1" cellpadding="3" bgcolor="#999999" align="center" border="0"><tbody><tr><td valign="middle" bgcolor="#dddddd" align="left"></td></tr></tbody></table>';
  36. const spoilerHead = tpcHead.previousElementSibling,
  37. spTitle = spoilerHead.getElementsByTagName('td')[0];
  38. spoilerHead.style.cssText = '-moz-user-select: none !important;-webkit-user-select: none !important; -ms-user-select: none !important; user-select: none !important; cursor: pointer !important';
  39. spTitle.textContent = show;
  40. spoilerHead.onclick = e => {
  41. if (e.button != 0) return;
  42. e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation();
  43. tpcHead.hidden = !tpcHead.hidden;
  44. spTitle.textContent = tpcHead.hidden ? show : hide;
  45. }
  46. });