Greasy Fork镜像 支持简体中文。

Roblox Friend Requests Counter

Count total friend requests on Roblox

  1. // ==UserScript==
  2. // @name Roblox Friend Requests Counter
  3. // @namespace https://mopsfl.de
  4. // @version 1.2
  5. // @description Count total friend requests on Roblox
  6. // @author mopsfl
  7. // @match *://*.roblox.com/*
  8. // @grant GM_setValue
  9. // @grant GM_getValue
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (async function() {
  14. 'use strict';
  15.  
  16. function waitForElm(selector) {
  17. return new Promise(resolve => {
  18. if (document.querySelector(selector)) {
  19. return resolve(document.querySelector(selector));
  20. }
  21.  
  22. const observer = new MutationObserver(mutations => {
  23. if (document.querySelector(selector)) {
  24. observer.disconnect();
  25. resolve(document.querySelector(selector));
  26. }
  27. });
  28.  
  29. observer.observe(document.body, {
  30. childList: true,
  31. subtree: true
  32. });
  33. });
  34. }
  35.  
  36. async function fetchFriendRequests(cursor = "") {
  37. const url = `https://friends.roblox.com/v1/my/friends/requests?sortOrder=Desc&limit=100${cursor ? `&cursor=${cursor}` : ""}`;
  38.  
  39. const response = await fetch(url, {
  40. method: "GET",
  41. credentials: "include",
  42. });
  43.  
  44. if (!response.ok) {
  45. throw new Error(`HTTP error! Status: ${response.status}`);
  46. }
  47.  
  48. return response.json();
  49. }
  50.  
  51. async function main() {
  52. const cachedData = GM_getValue("friendRequestCount", null);
  53. const now = new Date().getTime();
  54.  
  55. if (cachedData && now - cachedData.t < 5 * 60 * 1000) {
  56. console.log(`Using cached value: ${cachedData.v}`);
  57. waitForElm("#nav-friends > div.dynamic-width-item.align-right > span").then(el => {
  58. el.innerText = cachedData.v;
  59. });
  60.  
  61. waitForElm("#friends-web-app > div > div.rbx-tabs-horizontal.rbx-scrollable-tabs-horizontal > div > div > div.friends-content.section > div > div > h2").then(el => {
  62. el.innerText = `Requests (${cachedData.v})`;
  63. });
  64. return;
  65. } else {
  66. waitForElm("#nav-friends > div.dynamic-width-item.align-right > span").then(el => {
  67. el.innerText = cachedData.v;
  68. });
  69.  
  70. waitForElm("#friends-web-app > div > div.rbx-tabs-horizontal.rbx-scrollable-tabs-horizontal > div > div > div.friends-content.section > div > div > h2").then(el => {
  71. el.innerText = `Requests (${cachedData.v})`;
  72. });
  73. }
  74.  
  75. console.log("Fetching all friend requests! This may take a few seconds...")
  76.  
  77. let length = 0;
  78. let cursor = "";
  79.  
  80. try {
  81. do {
  82. const response = await fetchFriendRequests(cursor);
  83. length += response.data.length;
  84. cursor = response.nextPageCursor;
  85. } while (cursor);
  86.  
  87. GM_setValue("friendRequestCount", { v: length, t: now });
  88.  
  89. waitForElm("#nav-friends > div.dynamic-width-item.align-right > span").then(el => {
  90. el.innerText = length;
  91. });
  92.  
  93. waitForElm("#friends-web-app > div > div.rbx-tabs-horizontal.rbx-scrollable-tabs-horizontal > div > div > div.friends-content.section > div > div > h2").then(el => {
  94. el.innerText = `Requests (${length})`;
  95. });
  96.  
  97. console.log(`Total friend requests: ${length}`);
  98. } catch (error) {
  99. console.error("Error fetching friend requests:", error);
  100. }
  101. }
  102.  
  103. main();
  104. })();

QingJ © 2025

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