tamper_get_top_sol_gmgn_nowuse.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. // ==UserScript==
  2. // @name GMGN-Get-Top
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-10-19
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://gmgn.ai/sol/token/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=gmgn.ai
  9. // @grant none
  10. // ==/UserScript==
  11. function funcDownload(content, filename) {
  12. console.log('begin download');
  13. // 创建隐藏的可下载链接
  14. let eleLink = document.createElement('a');
  15. eleLink.download = filename;
  16. eleLink.style.display = 'none';
  17. // 字符内容转变成blob地址
  18. let blob = new Blob([content]);
  19. eleLink.href = URL.createObjectURL(blob);
  20. // 触发点击
  21. document.body.appendChild(eleLink);
  22. eleLink.click();
  23. // 然后移除
  24. document.body.removeChild(eleLink);
  25. }
  26. function sleep(sleepdelay) {
  27. return new Promise((resolve, reject) => {
  28. setTimeout(() => {
  29. resolve(sleepdelay);
  30. }, sleepdelay);
  31. })
  32. }
  33. var number_chars_obj = {
  34. "k": 3,
  35. "m": 6,
  36. "b": 9,
  37. "t": 12,
  38. "p": 15
  39. };
  40. var number_chars_arr = ["k", "m", "b", "t", "p"];
  41. function get_float_number(str_number) {
  42. let float_number = parseFloat(str_number);
  43. for (let number_char of number_chars_arr) {
  44. if (str_number.indexOf(number_char) != -1) {
  45. float_number = parseFloat(str_number) * 10 ** number_chars_obj[number_char];
  46. }
  47. }
  48. return float_number;
  49. }
  50. function getCurrentTime() {
  51. const zeroFill = (i) => {
  52. if (i >= 0 && i <= 9) {
  53. return "0" + i;
  54. } else {
  55. return '' + i;
  56. }
  57. }
  58. let date = new Date();//当前时间
  59. let year = date.getFullYear();
  60. let month = zeroFill(date.getMonth() + 1);//月
  61. let day = zeroFill(date.getDate());//日
  62. let hour = zeroFill(date.getHours());//时
  63. let minute = zeroFill(date.getMinutes());//分
  64. let second = zeroFill(date.getSeconds());//秒
  65. //当前时间
  66. var curTime = month + day + '_' + hour + minute ;
  67. return curTime;
  68. }
  69. function get_thead_arr_toptrader() {
  70. // let titlearr = _thead.innerText.trim().split(/\r?\n/);
  71. let titlearr = ['Maker', 'SOL', 'Buy_sol', 'Buy_token_M', 'Sell_sol', 'Sell_token_M', 'Pnl_sol', 'Pnl_per', 'buy_cout', 'sell_cout'];
  72. return titlearr;
  73. }
  74. async function get_tbody_data_toptrader() {
  75. let div_has_tran_table = document.querySelector("div.chakra-tabs__tab-panels.css-2zi8qu");
  76. let tbody = div_has_tran_table.querySelector("div.ag-body.ag-layout-normal div.ag-center-cols-viewport div.ag-center-cols-container");
  77. let arr_tbody_trs;
  78. arr_tbody_trs = Array.from(tbody.children);
  79. let last_tr = arr_tbody_trs[arr_tbody_trs.length - 1];
  80. let last_row_id = parseInt(last_tr.getAttribute('row-id'));
  81. if (arr_res_data_toptrader.length - 1 >= last_row_id + 1) {
  82. // 这批已经全部获取了
  83. return false;
  84. }
  85. for (let i = 0; i < arr_tbody_trs.length; i++) {
  86. let cur_row_id = parseInt(arr_tbody_trs[i].getAttribute('row-id'));
  87. if (arr_res_data_toptrader.length - 1 >= cur_row_id + 1) {
  88. continue;
  89. }
  90. let arr_tds;
  91. arr_tds = Array.from(arr_tbody_trs[i].children);
  92. let tdtexts = [];
  93. for (let i = 0; i < arr_tds.length; i++) {
  94. if (i == 0) {
  95. // trader
  96. let a_element = arr_tds[i].querySelector("a");
  97. let str_trader = a_element.href.split('/').pop();
  98. tdtexts.push(str_trader);
  99. }
  100. else if (i == 1) {
  101. //sol balance
  102. let str_balance = arr_tds[i].innerText.trim().replace(/[,]/g, "").trim();
  103. str_balance = str_balance.replace(/\s+/g, "");
  104. str_balance = str_balance.toLowerCase();
  105. let float_balance;
  106. float_balance = get_float_number(str_balance);
  107. // for (let number_char of number_chars_arr) {
  108. // if (str_balance.indexOf(number_char) != -1) {
  109. // float_balance = parseFloat(str_balance) * 10 ** number_chars_obj[number_char];
  110. // }
  111. // }
  112. tdtexts.push(float_balance);
  113. } else if (i == 2) {
  114. continue;
  115. }
  116. else if (i == 3) {
  117. // bought
  118. let arr_sol_amount = arr_tds[i].children[0].children;
  119. if (arr_sol_amount.length == 1) {
  120. // 为 --
  121. tdtexts.push(0);
  122. tdtexts.push(0);
  123. continue;
  124. }
  125. let str_sol = "0";
  126. let float_sol;
  127. str_sol = arr_sol_amount[0].innerText.trim().toLowerCase();
  128. str_sol = str_sol.replace(/[sol$,%\+><]/g, "").trim();
  129. // if (str_sol == "--") {
  130. // str_sol = "0";
  131. // }
  132. let str_token_amount = "0";
  133. let float_token_amount;
  134. str_token_amount = arr_sol_amount[1].innerText.trim().toLowerCase();
  135. // if (str_token_amount == "--") {
  136. // str_token_amount = "0";
  137. // }
  138. float_sol = get_float_number(str_sol);
  139. // for (let number_char of number_chars_arr) {
  140. // if (str_sol.indexOf(number_char) != -1) {
  141. // float_sol = parseFloat(str_sol) * 10 ** number_chars_obj[number_char];
  142. // }
  143. // }
  144. tdtexts.push(float_sol);
  145. float_token_amount = get_float_number(str_token_amount);
  146. // for (let number_char of number_chars_arr) {
  147. // if (str_token_amount.indexOf(number_char) != -1) {
  148. // float_token_amount = parseFloat(str_token_amount) * 10 ** number_chars_obj[number_char];
  149. // }
  150. // }
  151. tdtexts.push(float_token_amount/1e6);
  152. } else if (i == 4) {
  153. // sold
  154. let arr_sol_amount = arr_tds[i].children[0].children;
  155. if (arr_sol_amount.length == 1) {
  156. tdtexts.push(0);
  157. tdtexts.push(0);
  158. continue;
  159. }
  160. let str_sol = "0";
  161. let float_sol;
  162. str_sol = arr_sol_amount[0].innerText.trim().toLowerCase();
  163. str_sol = str_sol.replace(/[sol$,%\+><]/g, "").trim();
  164. // if (str_sol == "--") {
  165. // str_sol = "0";
  166. // }
  167. let str_token_amount = "0";
  168. let float_token_amount;
  169. str_token_amount = arr_sol_amount[1].innerText.trim().toLowerCase();
  170. // if (str_token_amount == "--") {
  171. // str_token_amount = "0";
  172. // }
  173. float_sol = get_float_number(str_sol);
  174. tdtexts.push(float_sol);
  175. float_token_amount = get_float_number(str_token_amount);
  176. tdtexts.push(float_token_amount/1e6);
  177. } else if (i == 5) {
  178. // pnl
  179. let str_sol = "0";
  180. let str_percent = "0";
  181. let float_sol = 0;
  182. let float_percent = 0;
  183. let arr_sol_percent = arr_tds[i].children[0].children;
  184. str_sol = arr_sol_percent[0].innerText.trim().toLowerCase();
  185. str_sol = str_sol.replace(/[sol$,%\+><]/g, "").trim();
  186. str_percent = arr_sol_percent[1].innerText.trim().toLowerCase();
  187. str_percent = str_percent.replace(/[sol$,%\+><]/g, "").trim();
  188. if (str_sol == "--") {
  189. str_sol = "0";
  190. }
  191. if (str_percent == "--") {
  192. str_percent = "999999";
  193. }
  194. float_sol = parseFloat(str_sol);
  195. float_percent = parseFloat(str_percent);
  196. for (let number_char of number_chars_arr) {
  197. if (str_sol.indexOf(number_char) != -1) {
  198. float_sol = parseFloat(str_sol) * 10 ** number_chars_obj[number_char];
  199. }
  200. if (str_percent.indexOf(number_char) != -1) {
  201. float_percent = parseFloat(str_percent) * 10 ** number_chars_obj[number_char];
  202. }
  203. }
  204. tdtexts.push(float_sol);
  205. tdtexts.push(float_percent);
  206. } else if (i == 6) {
  207. // Realized
  208. continue;
  209. }
  210. else if (i == 7) {
  211. // UnRealized
  212. continue
  213. } else if (i == 8) {
  214. //Holding Duration
  215. continue
  216. }
  217. else if (i == 9) {
  218. // Avg Cost/Sold
  219. continue
  220. } else if (i == 10) {
  221. // TXs
  222. let arr_buy_sell_cout = arr_tds[i].children[0].children;
  223. let str_buy_cout = "0";
  224. str_buy_cout = arr_buy_sell_cout[0].innerText.trim().toLowerCase();
  225. str_buy_cout = str_buy_cout.replace(/[sol$,%\+><]/g, "").trim();
  226. let str_sell_cout = "0";
  227. str_sell_cout = arr_buy_sell_cout[1].innerText.trim().toLowerCase();
  228. str_sell_cout = str_sell_cout.replace(/[sol$,%\+><]/g, "").trim();
  229. let float_buy_cout = get_float_number(str_buy_cout);
  230. tdtexts.push(float_buy_cout);
  231. let float_sell_cout = get_float_number(str_sell_cout);
  232. tdtexts.push(float_sell_cout);
  233. continue
  234. } else if (i == 11) {
  235. // Last Active
  236. continue
  237. }
  238. }
  239. arr_res_data_toptrader.push(tdtexts);
  240. }
  241. return true
  242. }
  243. function save_resdata_toptrader() {
  244. console.log("enter save_resdata_toptrader");
  245. arr_res_data_toptrader.forEach((val, index, arr) => { arr[index] = val.join() + "\n" });
  246. let urlpathname = window.location.pathname.slice(1).split('/');
  247. urlpathname = urlpathname.pop()
  248. funcDownload(arr_res_data_toptrader.join(""), urlpathname + "_top_gmgn_sol" + "_" + getCurrentTime() + ".csv");
  249. arr_res_data_toptrader = [];
  250. }
  251. function autoScroll_toptrader() {
  252. console.log("enter autoScroll_toptrader");
  253. let interval;
  254. let scroll_times = 15;
  255. let div_has_tran_table = document.querySelector("div.chakra-tabs__tab-panels.css-2zi8qu");
  256. let tbody = div_has_tran_table.querySelector("div.ag-body.ag-layout-normal div.ag-center-cols-viewport div.ag-center-cols-container");
  257. async function down() {
  258. interval = setInterval(async () => {
  259. let tbodytrs;
  260. console.log("scroll_times=", scroll_times);
  261. if (scroll_times > 0) {
  262. await sleep(150);
  263. tbodytrs = tbody.children;
  264. tbodytrs[tbodytrs.length - 1].scrollIntoView({ behavior: "smooth", block: "center" });
  265. let bool_get_tbody = await get_tbody_data_toptrader();
  266. if (bool_get_tbody == false) {
  267. scroll_times = 0;
  268. }
  269. } else {
  270. clearInterval(interval);
  271. await get_tbody_data_toptrader();
  272. save_resdata_toptrader();
  273. return;
  274. }
  275. scroll_times--;
  276. // tbodytrs = tbody.children;
  277. if (arr_res_data_toptrader.length == 101) {
  278. clearInterval(interval);
  279. await get_tbody_data_toptrader();
  280. save_resdata_toptrader();
  281. return;
  282. }
  283. await sleep(300);
  284. }, 1200)
  285. }
  286. down()
  287. }
  288. var arr_res_data_toptrader = [];
  289. // window.addEventListener('load', async () => {
  290. (async function () {
  291. console.log("enter load");
  292. await sleep(6000);
  293. console.log("create button");
  294. var mydivbox = document.createElement("div");
  295. var button_get_toptrader = document.createElement("button");//创建 获取 top trader 一个按钮
  296. button_get_toptrader.className = "tam-mybutton-gettran"
  297. button_get_toptrader.textContent = "top_sol"; //按钮内容
  298. button_get_toptrader.style.width = "90px"; //按钮宽度
  299. button_get_toptrader.style.height = "20px"; //按钮高度
  300. button_get_toptrader.style.align = "center"; //文本居中
  301. button_get_toptrader.style.color = "blue"; //按钮文字颜色
  302. button_get_toptrader.style.background = "#717171"; //按钮底色
  303. button_get_toptrader.style.border = "1px solid #717171"; //边框属性
  304. mydivbox.appendChild(button_get_toptrader);
  305. mydivbox.style.position = "fixed";
  306. mydivbox.style.top = "160px";
  307. mydivbox.style.right = "40px";
  308. document.body.appendChild(mydivbox);
  309. button_get_toptrader.addEventListener("click", clickButton_get_toptrader); //监听按钮点击事件
  310. })();
  311. async function clickButton_get_toptrader() {
  312. arr_res_data_toptrader = [];
  313. console.log("enter clickButton_toptrader arr_res_data_toptrader=", arr_res_data_toptrader);
  314. let div_chakra_tabs = document.querySelector('[role="tablist"]');
  315. let arr_buttons_chakra = Array.from(div_chakra_tabs.querySelectorAll("button"));
  316. let tab_top_trader_click = undefined;
  317. for (let button of arr_buttons_chakra) {
  318. if (button.innerText.includes("Traders")) {
  319. tab_top_trader_click = button;
  320. break;
  321. }
  322. }
  323. if (tab_top_trader_click == undefined) {
  324. console.log("no tab_top_trader_click");
  325. return;
  326. }
  327. console.log(" tab_top_trader_click click=");
  328. await tab_top_trader_click.click();
  329. await sleep(7000);
  330. let div_has_tran_table = document.querySelector("div.chakra-tabs__tab-panels.css-2zi8qu");
  331. let _thead = div_has_tran_table.querySelector("div.css-c6kdal div.ag-header-row.ag-header-row-column");
  332. let arr_th = _thead.children;
  333. let tab_click_USD_toptrader = arr_th[5].querySelector("div.css-1vimx2u");
  334. if (tab_click_USD_toptrader.innerText.includes("USD")) {
  335. await tab_click_USD_toptrader.click();
  336. await sleep(4000);
  337. }
  338. let titlearr = get_thead_arr_toptrader();
  339. arr_res_data_toptrader.push(titlearr);
  340. autoScroll_toptrader();
  341. }