xmlhttprequest_get_top_trader_gmgn.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // ==UserScript==
  2. // @name GMGN Token Traders Monitor
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Monitor GMGN token traders API and log response
  6. // @author Grok
  7. // @match https://gmgn.ai/sol/token/*
  8. // @grant none
  9. // ==/UserScript==
  10. function sleep(sleepdelay) {
  11. return new Promise((resolve, reject) => {
  12. setTimeout(() => {
  13. resolve(sleepdelay);
  14. }, sleepdelay);
  15. })
  16. }
  17. function timestampToString(timestamp) {
  18. if (!timestamp) return '';
  19. const date = new Date(timestamp * 1000);
  20. return date.toLocaleString('zh-CN', {
  21. year: 'numeric',
  22. month: '2-digit',
  23. day: '2-digit',
  24. hour: '2-digit',
  25. minute: '2-digit',
  26. second: '2-digit',
  27. hour12: false
  28. }).replace(/\//g, '-');
  29. }
  30. function clickButton_get_toptrader() {
  31. const originalXhrOpen = XMLHttpRequest.prototype.open;
  32. XMLHttpRequest.prototype.open = function (method, url) {
  33. if (url.includes('/vas/api/v1/token_traders/sol/Hdt68n4uzAZzy1C6YJjo5Qb1hj6QNwEzb44w7Lp5pump')) {
  34. console.log('Matched target API in XHR:', url);
  35. this.addEventListener('load', function () {
  36. try {
  37. const response = JSON.parse(this.responseText);
  38. if (response.code === 0 && response.data && response.data.list) {
  39. const processedData = response.data.list.map(item => ({
  40. address: item.address,
  41. start_holding_at: timestampToString(item.start_holding_at),
  42. end_holding_at: timestampToString(item.end_holding_at)
  43. }));
  44. console.log('Processed Data:', processedData);
  45. } else {
  46. console.log('No valid list data found in response');
  47. }
  48. } catch (err) {
  49. console.error('XHR JSON parse error:', err);
  50. console.log('XHR Raw Response:', this.responseText);
  51. }
  52. });
  53. }
  54. originalXhrOpen.apply(this, arguments);
  55. };
  56. const observer = new MutationObserver((mutations) => {
  57. console.log('DOM changed, mutations:', mutations.length);
  58. });
  59. observer.observe(document.body, { childList: true, subtree: true });
  60. console.log('Script initialized');
  61. }
  62. (async function () {
  63. console.log("enter load");
  64. await sleep(6000);
  65. console.log("create button");
  66. var mydivbox = document.createElement("div");
  67. var button_get_toptrader = document.createElement("button");//创建 获取 top trader 一个按钮
  68. button_get_toptrader.className = "tam-mybutton-gettran"
  69. button_get_toptrader.textContent = "top_sol"; //按钮内容
  70. button_get_toptrader.style.width = "90px"; //按钮宽度
  71. button_get_toptrader.style.height = "20px"; //按钮高度
  72. button_get_toptrader.style.align = "center"; //文本居中
  73. button_get_toptrader.style.color = "blue"; //按钮文字颜色
  74. button_get_toptrader.style.background = "#717171"; //按钮底色
  75. button_get_toptrader.style.border = "1px solid #717171"; //边框属性
  76. mydivbox.appendChild(button_get_toptrader);
  77. mydivbox.style.position = "fixed";
  78. mydivbox.style.top = "160px";
  79. mydivbox.style.right = "40px";
  80. document.body.appendChild(mydivbox);
  81. button_get_toptrader.addEventListener("click", clickButton_get_toptrader); //监听按钮点击事件
  82. })();