arcalive hotdeal post counter

count hot deal post and display post description

  1. // ==UserScript==
  2. // @name arcalive hotdeal post counter
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-03-16
  5. // @description count hot deal post and display post description
  6. // @author BOI
  7. // @match http://arca.live/b/hotdeal*
  8. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. const getUserLink = () => {
  14. document.querySelector('div.member-info')?.children[0].children[0].getAttribute('href');
  15. };
  16.  
  17. const getUserInfo = async (url) => {
  18. let cnt = 0;
  19. const res = await fetch(url);
  20. const html = await res.text();
  21. const doc = new DOMParser().parseFromString(html, "text/html");
  22. const recent = doc.querySelectorAll('div.user-recent');
  23.  
  24. for (let i = 0; i < 15; i++) {
  25. cnt += recent[i].children[0].children[0]?.getAttribute('href') == '/b/hotdeal';
  26. }
  27.  
  28. const info = document.querySelector('div.article-info.article-info-section');
  29. info.innerHTML = `<span class="head">최근 핫딜 게시물 수</span><span class="body">${cnt}</span><span class="sep"></span>` + info.innerHTML;
  30. };
  31.  
  32. (function() {
  33. 'use strict';
  34. const userLink = getUserLink();
  35.  
  36. if (userLink && window.location.href.indexOf('/b/hotdeal') != -1) {
  37. getUserInfo(userLink);
  38. }
  39. })();