pawoo.net 顯示轉嘟與最愛

把隱藏的轉嘟與最愛顯示出來

  1. // ==UserScript==
  2. // @name pawoo.net 顯示轉嘟與最愛
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description 把隱藏的轉嘟與最愛顯示出來
  6. // @author BeenYan
  7. // @match https://pawoo.net/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=pawoo.net
  9. // @license GPL
  10. // @run-at document-start
  11. // @grant GM_addElement
  12. // ==/UserScript==
  13.  
  14. /**
  15. * DATA struct {
  16. * id: string, // 搜索文章識別符號
  17. * favourites_count: number, // 最愛人數
  18. * reblogs_count: number, // 轉嘟人數
  19. * }
  20. */
  21.  
  22. const delay = ms => new Promise(res => setTimeout(res, ms));
  23. const DATA = new Map();
  24.  
  25. class DataInfo {
  26. constructor(reblogs, favourites) {
  27. this.reblogs_count = reblogs;
  28. this.favourites_count = favourites;
  29. }
  30. }
  31.  
  32. function number_dom(parent, num) {
  33. parent.classList.add('icon-button--with-counter');
  34. GM_addElement(parent, 'span', {
  35. class: 'icon-button__counter',
  36. textContent: num
  37. });
  38. }
  39.  
  40. async function get_action_bar(id) {
  41. const ACTION_BAR = document.querySelectorAll(`div[data-id="${id}"] .status__action-bar__button`);
  42. if (ACTION_BAR.length === 0) {
  43. await delay(1000);
  44. return get_action_bar(id);
  45. }
  46.  
  47. return ACTION_BAR;
  48. }
  49.  
  50. async function save(dataList) {
  51. /**
  52. * 0 => 回覆
  53. * 1 => 轉嘟
  54. * 2 => 最愛
  55. */
  56. for (const data of dataList) {
  57. const target = data.reblog?? data;
  58. DATA.set(target.id, new DataInfo(target.reblogs_count, target.favourites_count))
  59. }
  60.  
  61. console.log(DATA);
  62. }
  63.  
  64. (function(open) {
  65. unsafeWindow.XMLHttpRequest.prototype.open = function() {
  66. this.addEventListener('load', function() {
  67. if (this.responseURL.startsWith('https://pawoo.net/api/v1/timelines/') !== true) {
  68. return;
  69. }
  70.  
  71. const DATA_LIST = JSON.parse(this.response);
  72. save(DATA_LIST);
  73. }, false);
  74. open.apply(this, arguments);
  75. };
  76.  
  77. window.onload = () => {
  78. console.log('loading');
  79.  
  80. const ItemList = document.querySelector('.item-list');
  81. const observer = new MutationObserver((mutations) => {
  82. const TargetList = mutations
  83. .filter(m => m.attributeName === 'class' && m.target.classList.length === 3 && [...m.target.classList]
  84. .some(c => c === 'focusable'))
  85. .map(m => m.target);
  86. if (!TargetList.length) return;
  87. for (const Target of TargetList) {
  88. const ID = Target.querySelector('[data-id].status').getAttribute('data-id');
  89. const ButtonList = Target.querySelectorAll('.status__action-bar__button');
  90. const Info = DATA.get(ID);
  91. if (Info === undefined) {
  92. console.info('Info not found');
  93. return;
  94. }
  95.  
  96. number_dom(ButtonList[1], Info.reblogs_count);
  97. number_dom(ButtonList[2], Info.favourites_count);
  98. }
  99. });
  100.  
  101. observer.observe(ItemList, {
  102. attributes: true,
  103. subtree: true,
  104. });
  105. }
  106. })(unsafeWindow.XMLHttpRequest.prototype.open);
  107.  
  108. window.addEventListener('keydown', (event) => {
  109. const KEY = event.key;
  110. if (KEY !== "F5") {
  111. return;
  112. }
  113.  
  114. location.reload(true);
  115. event.preventDefault();
  116. })

QingJ © 2025

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