stock-tool

stock data tool

  1. // ==UserScript==
  2. // @name stock-tool
  3. // @namespace npm/vite-plugin-monkey
  4. // @version 0.0.4
  5. // @author dd
  6. // @description stock data tool
  7. // @license MIT
  8. // @match *www.google.com/finance/quote*
  9. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  10. // @grant GM.addElement
  11. // @grant GM.addStyle
  12. // @grant GM.deleteValue
  13. // @grant GM.getResourceUrl
  14. // @grant GM.getValue
  15. // @grant GM.info
  16. // @grant GM.listValues
  17. // @grant GM.notification
  18. // @grant GM.openInTab
  19. // @grant GM.registerMenuCommand
  20. // @grant GM.setClipboard
  21. // @grant GM.setValue
  22. // @grant GM.xmlHttpRequest
  23. // @grant GM_addElement
  24. // @grant GM_addStyle
  25. // @grant GM_addValueChangeListener
  26. // @grant GM_cookie
  27. // @grant GM_deleteValue
  28. // @grant GM_download
  29. // @grant GM_getResourceText
  30. // @grant GM_getResourceURL
  31. // @grant GM_getTab
  32. // @grant GM_getTabs
  33. // @grant GM_getValue
  34. // @grant GM_info
  35. // @grant GM_listValues
  36. // @grant GM_log
  37. // @grant GM_notification
  38. // @grant GM_openInTab
  39. // @grant GM_registerMenuCommand
  40. // @grant GM_removeValueChangeListener
  41. // @grant GM_saveTab
  42. // @grant GM_setClipboard
  43. // @grant GM_setValue
  44. // @grant GM_unregisterMenuCommand
  45. // @grant GM_webRequest
  46. // @grant GM_xmlhttpRequest
  47. // @run-at document-start
  48. // @grant unsafeWindow
  49. // @grant window.close
  50. // @grant window.focus
  51. // @grant window.onurlchange
  52. // ==/UserScript==
  53.  
  54. listenForRequests();
  55.  
  56. // 监听XMLHttpRequest网络请求
  57. function listenForRequests() {
  58. const open = XMLHttpRequest.prototype.open;
  59. const send = XMLHttpRequest.prototype.send;
  60.  
  61. XMLHttpRequest.prototype.open = function (method, url) {
  62. //console.log("访问的URL == " + url);
  63. open.apply(this, arguments);
  64. };
  65.  
  66. XMLHttpRequest.prototype.send = function (data) {
  67. //console.log(' send window.location.href -- ' + window.location.href);
  68. //console.log("data ------- " + JSON.stringify(data));
  69.  
  70. // 保存当前 XMLHttpRequest 对象
  71. const currentXHR = this;
  72.  
  73. // 添加 load 事件监听器
  74. currentXHR.addEventListener("load", function () {
  75. var resData = currentXHR.responseText
  76. //console.log('Response data:----', resData);
  77. if (resData.startsWith(")]}'")) {
  78. /// 使用正则表达式匹配模式并提取目标数据
  79. //const regexNum = /,\[(-?\d+\.\d+),/g;
  80. const regexNum = /,\[(-?\d+(\.\d+)?),/g;
  81. let matchNum;
  82. const resultNumArray = [];
  83.  
  84. while ((matchNum = regexNum.exec(resData)) !== null) {
  85. // match[1] 包含匹配的目标数据
  86. resultNumArray.push(parseFloat(matchNum[1]));
  87. }
  88.  
  89. // 输出结果数组
  90. console.log("数据-" + resultNumArray.length + "--" + JSON.stringify(resultNumArray));
  91.  
  92. //const regexDate = /\[\[([\d,]+),/g;
  93. //const regexDate = /\[\[([\d,]+)\d+/g;
  94. const regexDate = /\[\[(\d+,\d+,\d+),/g;
  95. let matchDate;
  96. const resultDateArray = [];
  97.  
  98. while ((matchDate = regexDate.exec(resData)) !== null) {
  99. // match[1] 包含匹配的目标数据
  100. const extractedString = matchDate[1];
  101. const transformedString = extractedString.slice(5).replace(/,/g, '.');
  102. resultDateArray.push(transformedString);
  103. }
  104. console.log("日期-" + resultDateArray.length + "--" + JSON.stringify(resultDateArray));
  105. }
  106. });
  107. return send.apply(this, arguments);
  108. };
  109. }

QingJ © 2025

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