PTT-顯示推文樓層

顯示 PTT 的推文樓層數

  1. // ==UserScript==
  2. // @name PTT-顯示推文樓層
  3. // @namespace https://github.com/jlhg/userscript
  4. // @license MIT
  5. // @version 0.2.1
  6. // @description 顯示 PTT 的推文樓層數
  7. // @author jlhg
  8. // @homepage https://github.com/jlhg/userscript
  9. // @supportURL https://github.com/jlhg/userscript/issues
  10. // @match https://www.ptt.cc/bbs/*
  11. // @grant none
  12. // ==/UserScript==
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. function createPushLevel(level) {
  18. const el = document.createElement('div');
  19. el.className = 'push-level';
  20. el.style.cssText = 'display: inline-block;' +
  21. 'min-width: 50px;' +
  22. 'margin-left: -62px;' +
  23. 'padding-right: 12px;' +
  24. 'text-align: right;' +
  25. 'color: #808080;';
  26. el.textContent = level;
  27. return el;
  28. }
  29.  
  30. const pushElements = document.querySelectorAll('.push');
  31.  
  32. let pushCount = 0;
  33. for (const pushElement of pushElements) {
  34. pushElement.prepend(createPushLevel(++pushCount));
  35. }
  36.  
  37. const observer = new MutationObserver(mutations => {
  38. for (const mutation of mutations) {
  39. for (const node of mutation.addedNodes) {
  40. for (const child of node.childNodes) {
  41. if (child.className == 'push') {
  42. child.prepend(createPushLevel(++pushCount));
  43. }
  44. }
  45. }
  46. }
  47. });
  48.  
  49. let mainContent = document.querySelector('#main-content');
  50. observer.observe(mainContent, { childList: true, subtree: true });
  51. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址