Scorable follower count [neocities.org]

See approximate "scorable follower count", which is the count that's used in site top

当前为 2024-04-19 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Scorable follower count [neocities.org]
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0.0
  5. // @description See approximate "scorable follower count", which is the count that's used in site top
  6. // @author https://neocities.org/site/dimden
  7. // @match https://neocities.org/site/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=neocities.org
  9. // @grant none
  10. // @run-at document-end
  11. // @license MIT
  12. // ==/UserScript==
  13.  
  14. (async () => {
  15. let style = document.createElement('style');
  16. style.innerHTML = `.col.col-50.profile-info { width: 64% !important }`;
  17. document.head.append(style);
  18.  
  19. let site = location.pathname.split('/').slice(-1)[0];
  20. async function getFollowings() {
  21. const followerPage = await fetch(`https://neocities.org/site/${site}/follows`).then(res => res.text());
  22. try {
  23. const parser = new DOMParser();
  24. const doc = parser.parseFromString(followerPage, "text/html");
  25. return Array.from(doc.querySelectorAll('.username > a')).map(u => u.innerText.replace(/\n/g, '').trim()).filter(u => !u.includes('/'));
  26. } catch(e) {
  27. console.error('error getting follows', e);
  28. console.log(followerPage);
  29. }
  30. return [];
  31. }
  32. let followings = (await getFollowings()).length;
  33. let followers = parseInt(document.getElementsByClassName('stats')[0].children[1].children[0].innerText.replace(/,/g, ''));
  34. let stats = document.getElementsByClassName('stats')[0];
  35. let div = document.createElement('div');
  36. div.className = 'stat';
  37. div.innerHTML = `
  38. <strong>${followers - followings}</strong>
  39. <span>Score</span>
  40. `;
  41. document.getElementsByClassName('stats')[0].children[1].after(div);
  42.  
  43. })();