tamper_has_startdate_dexscreengetitran_solana_scroll.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. // ==UserScript==
  2. // @name DexScreen-GetTran-HasStartDate
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description try to take over the world!
  6. // @author You
  7. // @match https://dexscreener.com/solana/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=tampermonkey.net
  9. // @grant none
  10. // ==/UserScript==
  11. function funcDownload(content, filename) {
  12. console.log('begin download');
  13. // 创建隐藏的可下载链接
  14. var eleLink = document.createElement('a');
  15. eleLink.download = filename;
  16. eleLink.style.display = 'none';
  17. // 字符内容转变成blob地址
  18. var 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 monthmatch = {
  41. "January": "01",
  42. "February": "02",
  43. "March": "03",
  44. "Apr": "04",
  45. "May": "05",
  46. "June": "06",
  47. "July": "07",
  48. "August": "08",
  49. "September": "09",
  50. "October": "10",
  51. "November": "11",
  52. "December": "12",
  53. };
  54. var number_chars_arr = ["k", "m", "b", "t", "p"];
  55. function get_thead_arr(_thead) {
  56. let titlearr = _thead.innerText.trim().split(/\r?\n/);
  57. titlearr = ['DATE', 'TYPE', 'USD', 'Token', 'SOL', 'PRICE', 'MAKER', 'TXN'];
  58. return titlearr;
  59. }
  60. function handletime(res) {
  61. for (let i = 1; i < res.length; i++) {
  62. let md = res[i][0].slice(0, 2);
  63. let hms = res[i][0].slice(2);
  64. res[i][0] = md.join("-") + " " + hms.join(":");
  65. }
  66. return res
  67. }
  68. function autoScroll(downstep, upstep, element, tbody, indexstart, startdate_timestamp) {
  69. let interval;
  70. let timeout;
  71. let equaltimes = 0
  72. let dataindex, totaldataindex;
  73. async function notimeoutup(upstep) {
  74. console.log("enter notimeoutup")
  75. let tbodytrs = tbody.querySelectorAll('tr[class*="custom-"]');
  76. let firdataindex = parseInt(tbodytrs[0].getAttribute('data-index'));
  77. let print_idx = 0;
  78. while (firdataindex >= indexstart) {
  79. print_idx++;
  80. tbodytrs = tbody.querySelectorAll('tr[class*="custom-"]');
  81. firdataindex = parseInt(tbodytrs[0].getAttribute('data-index'));
  82. if (print_idx % 30 == 0) {
  83. console.log("firdataindex,dataindex", firdataindex, dataindex);
  84. }
  85. let curpos = dataindex - 1 - firdataindex;
  86. for (let i = curpos; i >= 0; i--) {
  87. dataindex--;
  88. let arr_tds;
  89. while (true) {
  90. try {
  91. arr_tds = Array.from(tbodytrs[i].getElementsByTagName("td")[0].children);
  92. break;
  93. } catch (err) {
  94. await sleep(150);
  95. }
  96. }
  97. let tdtexts = [];
  98. for (let i = 0; i < arr_tds.length; i++) {
  99. if (i == 0) {
  100. //date
  101. //title 01:36:59, Saturday, February 4, 2023
  102. //text Feb 4 10:54:35 PM
  103. //有bug 12AM 为凌晨0点 -12 12PM就是中午12
  104. let month, day, hour, minute, second, isPM;
  105. let cur_date = new Date(arr_tds[0].innerText.trim());
  106. month = cur_date.getMonth() + 1;// Returns the month (0-11)
  107. day = cur_date.getDate();//Returns the day of the month (1-31)
  108. hour = cur_date.getHours(); // Returns the hour (0-23)
  109. minute = cur_date.getMinutes(); // Returns the minute (0-59)
  110. second = cur_date.getSeconds(); // Returns the second (0-59)
  111. //if want UTCtimestamp
  112. let utctime = [month, day, hour, minute, second];
  113. tdtexts.push(utctime);
  114. // simtdtexts.push(utctime);
  115. } else if (i >= 6) {
  116. tdtexts.push(arr_tds[i].querySelector("a").href.split('/').pop());
  117. } else if (i == 5) {
  118. if (arr_tds[5].querySelectorAll("span").length == 2) {
  119. tdtexts.push(arr_tds[5].querySelector("span").title.trim().replace(/[(\$),]/g, ""));
  120. // simtdtexts.push(tds[5].querySelector("span").title.trim().replace(/[(\$),]/g, ""));
  121. } else {
  122. tdtexts.push(arr_tds[i].innerText.trim().replace(/[(\$),]/g, ""));
  123. // simtdtexts.push(tds[i].innerText.trim().replace(/[(\$),]/g, ""));
  124. }
  125. } else if (i == 2) {
  126. let usdstr = arr_tds[i].innerText.trim().replace(/[(\$)<,]/g, "");
  127. if (usdstr == '-') usdstr = '0';
  128. tdtexts.push(usdstr);
  129. } else {
  130. //make $ , replace ''
  131. tdtexts.push(arr_tds[i].innerText.trim().replace(/[(\$)<,]/g, ""));
  132. }
  133. }
  134. res.push(tdtexts);
  135. }
  136. // element.scrollTop -= upstep;
  137. tbodytrs[0].scrollIntoView({ behavior: "smooth", block: "end" });
  138. await sleep(200);
  139. }
  140. console.log('reslen totalindex', res.length, totaldataindex);
  141. res = handletime(res);
  142. res.forEach((val, index, arr) => { arr[index] = val.join() + "\n" });
  143. let urlpathname = window.location.pathname.slice(1).split('/');
  144. urlpathname = urlpathname.pop()
  145. funcDownload(res.join(""), urlpathname + "_raydium" + ".csv");
  146. }
  147. function down() {
  148. interval = setInterval(async () => {
  149. let sTop = element.scrollTop;
  150. element.scrollTop += downstep;
  151. let tbodytrs;
  152. if (sTop == element.scrollTop) {
  153. equaltimes++;
  154. console.log("equaltimes=", equaltimes)
  155. await sleep(300);
  156. if (startdate_timestamp != 0) {
  157. return;
  158. }
  159. if (equaltimes >= 20) {
  160. clearInterval(interval);
  161. tbodytrs = tbody.querySelectorAll('tr[class*="custom-"]');
  162. dataindex = parseInt(tbodytrs[tbodytrs.length - 1].getAttribute('data-index'));
  163. totaldataindex = dataindex;
  164. console.log('totaldataindex', totaldataindex);
  165. try {
  166. arr_tds = Array.from(tbodytrs[0].getElementsByTagName("td")[0].children);
  167. } catch (err) {
  168. await sleep(100);
  169. arr_tds = Array.from(tbodytrs[0].getElementsByTagName("td")[0].children);
  170. }
  171. let cur_date = new Date(arr_tds[0].innerText.trim());
  172. console.log("cur_date=", cur_date);
  173. notimeoutup(upstep);
  174. }
  175. } else {
  176. equaltimes = 0;
  177. tbodytrs = tbody.querySelectorAll('tr[class*="custom-"]');
  178. let arr_tds;
  179. try {
  180. arr_tds = Array.from(tbodytrs[0].getElementsByTagName("td")[0].children);
  181. } catch (err) {
  182. await sleep(100);
  183. arr_tds = Array.from(tbodytrs[0].getElementsByTagName("td")[0].children);
  184. }
  185. let cur_date = new Date(arr_tds[0].innerText.trim());
  186. if (cur_date.valueOf() >= startdate_timestamp) {
  187. return;
  188. }
  189. console.log("startate=", cur_date);
  190. clearInterval(interval);
  191. await sleep(2000);
  192. tbodytrs = tbody.querySelectorAll('tr[class*="custom-"]');
  193. dataindex = parseInt(tbodytrs[tbodytrs.length - 1].getAttribute('data-index'));
  194. totaldataindex = dataindex;
  195. console.log('totaldataindex', totaldataindex);
  196. notimeoutup(upstep);
  197. }
  198. }, 1300)
  199. }
  200. down()
  201. }
  202. var res = [];
  203. // var simres = [];
  204. // window.addEventListener('load', () => {
  205. (async function () {
  206. console.log("enter load");
  207. await sleep(6000);
  208. console.log("create button");
  209. var mydivbox = document.createElement("div");
  210. var input = document.createElement("input")
  211. var input_startdate = document.createElement("input")
  212. var button_tran = document.createElement("button");//创建 获取toptran一个按钮
  213. mydivbox.appendChild(input);
  214. mydivbox.appendChild(input_startdate);
  215. mydivbox.appendChild(button_tran);
  216. input.value = "300";
  217. input.className = "tam-myinput";
  218. input.type = "number";
  219. input.style.width = "80px";
  220. input_startdate.value = "0101-0000";
  221. input_startdate.className = "tam-myinput-startdate";
  222. input_startdate.type = "text";
  223. input_startdate.style.width = "80px";
  224. button_tran.className = "tam-mybutton-gettran"
  225. button_tran.textContent = "gettran"; //按钮内容
  226. button_tran.style.width = "90px"; //按钮宽度
  227. //button.style.height = "28px"; //按钮高度
  228. button_tran.style.align = "center"; //文本居中
  229. button_tran.style.color = "blue"; //按钮文字颜色
  230. button_tran.style.background = "#e33e33"; //按钮底色
  231. button_tran.style.border = "1px solid #e33e33"; //边框属性
  232. button_tran.addEventListener("click", clickButton); //监听按钮点击事件
  233. mydivbox.style.position = "fixed";
  234. mydivbox.style.top = "60px";
  235. mydivbox.style.right = "40px";
  236. document.body.appendChild(mydivbox);
  237. // var theadtr = document.getElementsByClassName("custom-19qkkht")[0].getElementsByTagName("thead")[0];
  238. var theadtr = document.getElementsByTagName("table")[0].getElementsByTagName("thead")[0];
  239. theadtr.style.color = "blue";
  240. function clickButton() {
  241. res = [];
  242. console.log("enter clickButton res=", res);
  243. let arr_urlpathname = window.location.pathname.slice(1).split('/');
  244. // let table_div_ep1 = document.getElementsByClassName('custom-p3e2vj')[0];
  245. // let divscrollerdep2 = table_div_ep1.querySelector('[data-testid="virtuoso-scroller"]');
  246. let divscrollerdep2 = document.querySelector('[data-testid="virtuoso-scroller"]');
  247. var table_ = document.getElementsByTagName("table")[0];
  248. let thead_ = table_.getElementsByTagName('thead')[0];
  249. let titlearr = get_thead_arr(thead_);
  250. res.push(titlearr);
  251. let tbody_ = table_.getElementsByTagName('tbody')[0];
  252. // let tbody_ = document.getElementsByClassName('custom-p3e2vj')[0].getElementsByTagName('table')[0].getElementsByTagName('tbody')[0];
  253. let upstep = parseInt(input.value);
  254. let startdate_timestamp = 0;
  255. if (input_startdate.value.trim() == "0101-0000") {
  256. ;
  257. } else {
  258. let cur_month = input_startdate.value.trim().slice(0, 2);
  259. let cur_day = input_startdate.value.trim().slice(2, 4);
  260. let cur_hour = input_startdate.value.trim().slice(5, 7);
  261. let cur_minute = input_startdate.value.trim().slice(7, 9);
  262. console.log("date", cur_month + "-" + cur_day + " " + cur_hour + ":" + cur_minute + ":" + "00");
  263. startdate_timestamp = new Date(cur_month + "-" + cur_day + " " + cur_hour + ":" + cur_minute + ":" + "00").valueOf();
  264. }
  265. console.log(upstep, startdate_timestamp);
  266. autoScroll(7000, upstep, divscrollerdep2, tbody_, 30, startdate_timestamp);
  267. }
  268. })();