ACGN-Stock股票事件監聽

監聽ACGN網頁變化並給予Addevent

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.gf.qytechs.cn/scripts/33945/223014/ACGN-Stock%E8%82%A1%E7%A5%A8%E4%BA%8B%E4%BB%B6%E7%9B%A3%E8%81%BD.js

  1. // ==UserScript==
  2. // @name ACGN-Stock股票事件監聽
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.003
  5. // @description 監聽ACGN網頁變化並給予Addevent
  6. // @author Ming
  7. // @match http://acgn-stock.com/*
  8. // @match https://acgn-stock.com/*
  9. // @grant none
  10. // ==/UserScript==
  11. // ==/UserScript==
  12.  
  13. class BaseEvent {
  14. constructor(pattern) {
  15. this.pattern = pattern;
  16. this.callbacklist = [];
  17. }
  18. AddEventListner(callback) { this.callbacklist.push(callback); }
  19. RunCallback() {
  20. for (let i = 0; i < this.callbacklist.length; i++) {
  21. this.callbacklist[i]();
  22. }
  23. }
  24. CheckUrllState() {
  25. if (document.location.href.search(this.pattern) !== -1) {
  26. setTimeout(this.RunCallback.bind(this), 1000);
  27. }
  28. }
  29. }
  30. class Company extends BaseEvent {
  31. constructor() {
  32. super(/company\/detail/);
  33. }
  34. }
  35. class StockSummary extends BaseEvent {
  36. constructor() {
  37. super(/company\/[0-9]+/);
  38. }
  39. }
  40. class AccountInfo extends BaseEvent {
  41. constructor() {
  42. super(/accountInfo/);
  43. }
  44. }
  45. class Foundation extends BaseEvent {
  46. constructor() {
  47. super(/foundation\/[0-9]+/);
  48. }
  49. }
  50. class ACGNClass {
  51. constructor() {
  52. this.oldUrl = "";
  53. this.EventList = [];
  54. this.EventList.push(new Company());
  55. this.EventList.push(new StockSummary());
  56. this.EventList.push(new AccountInfo());
  57. this.EventList.push(new Foundation());
  58. setTimeout(this.BindMain.bind(this),5000);
  59. }
  60. BindMain(){
  61. console.log(this);
  62. $("#main").bind("DOMNodeInserted DOMNodeRemoved", this.MainDivCheck.bind(this));
  63. console.log("ACGN-Stock Listener Done");
  64. }
  65. MainDivCheck() {
  66. // 因AJAX動態生成不斷執行,所以有時候main的變動並不代表換頁,此時無須重新加入事件
  67. if (this.oldUrl === document.location.href) return;
  68. this.oldUrl = document.location.href;
  69.  
  70. //偵測網址並呼叫callback
  71. for(let i = 0 ;i < this.EventList.length;i++)
  72. this.EventList[i].CheckUrllState();
  73. }
  74. AddCompanyListener(callback){
  75. this.EventList[0].AddEventListner(callback);
  76. }
  77. AddStockSummaryListener(callback){
  78. this.EventList[1].AddEventListner(callback);
  79. }
  80. AddAccountInfoListener(callback){
  81. this.EventList[2].AddEventListner(callback);
  82. }
  83. AddFoundationListener(callback){
  84. this.EventList[3].AddEventListner(callback);
  85. }
  86. AddCutsomEvent(event){
  87. this.EventList.push(event);
  88. return this.EventList.indexOf(event);
  89. }
  90. AddCutsomListener(eventIndex,callback){
  91. this.EventList[eventIndex].AddEventListner(callback);
  92. }
  93. }
  94. var ACGNListener;
  95. (function(){
  96. ACGNListener = new ACGNClass();
  97. })();
  98. ////////////以上為程式碼,以下為使用範例
  99. function ListenerDebugMode(){
  100. console.log("ACGN-Stock股票事件監聽開啟除錯模式");
  101.  
  102. //新增監聽
  103. ACGNListener.AddCompanyListener(function(){console.log("AddCompanyListener");});
  104. ACGNListener.AddStockSummaryListener(function(){console.log("AddStockSummaryListener");});
  105. ACGNListener.AddAccountInfoListener(function(){console.log("AddAccountInfoListener");});
  106. ACGNListener.AddFoundationListener(function(){console.log("AddFoundationListener");});
  107.  
  108. //註冊客製化事件,輸入網址辨識片段
  109. let seasonalReportEventindex = ACGNListener.AddCutsomEvent(new BaseEvent(/seasonalReport/));
  110. //新增客製化事件監聽
  111. ACGNListener.AddCutsomListener(seasonalReportEventindex, function(){console.log("AddSeasonalReportListener");});
  112. }

QingJ © 2025

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