preload.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. const { contextBridge, ipcRenderer } = require('electron');
  2. contextBridge.exposeInMainWorld('electronAPI', {
  3. openWindow: (msg) => ipcRenderer.send('openWindow', msg),
  4. closeAllWindow: (msg) => ipcRenderer.send('window-all-closed', msg),
  5. getData: (msg) => ipcRenderer.send('getData', msg),
  6. postData: (msg) => ipcRenderer.send('postData', msg),
  7. setProxy: (msg) => ipcRenderer.send('setProxy', msg),
  8. addPreLoadCode: (msg) => ipcRenderer.send('addPreLoadCode', msg),
  9. setStoData: (msg) => ipcRenderer.send('setStoData', msg),
  10. getStoData: (msg) => ipcRenderer.send('getStoData', msg),
  11. openWindow: (msg) => ipcRenderer.send('openWindow', msg),
  12. closeWindow: (msg) => ipcRenderer.send('closeWindow', msg),
  13. changeProxy: (msg) => ipcRenderer.send('changeProxy', msg),
  14. readConfig: (msg) => ipcRenderer.send('readConfig', msg),
  15. saveConfig: (msg) => ipcRenderer.send('saveConfig', msg),
  16. setMaxWindowOpenNum: (msg) => ipcRenderer.send('setMaxWindowOpenNum', msg),
  17. readdir: (msg) => ipcRenderer.send('readdir', msg),
  18. download: (msg) => ipcRenderer.send('download', msg),
  19. broadcast: (msg) => ipcRenderer.send('broadcast-message', msg),
  20. onBroadcast: (callback) => ipcRenderer.on('message-broadcast', (event, data) => callback(data)),
  21. });
  22. document.addEventListener('click', function (e) {
  23. if (e.target.tagName === 'A' && e.target.href) {
  24. e.preventDefault();
  25. window.location.href = e.target.href;
  26. }
  27. });
  28. window.lastText = ''
  29. setInterval(() => {
  30. // 快手
  31. if (document.querySelectorAll('.virt-list__client .comment-cell')[0]) {
  32. let nowMessage = document.querySelectorAll('.virt-list__client .comment-cell')[document.querySelectorAll('.virt-list__client .comment-cell').length - 1]
  33. let nowText = nowMessage.querySelector('.comment').innerText
  34. if (window.lastText !== nowText) {
  35. window.lastText = nowText
  36. console.log(nowText)
  37. ipcRenderer.send('broadcast-message', nowText)
  38. }
  39. }
  40. // 抖音
  41. if (document.querySelectorAll('.TNg5meqw')[0]) {
  42. let nowMessage = document.querySelectorAll('.TNg5meqw')[document.querySelectorAll('.TNg5meqw').length - 1]
  43. let nowText = nowMessage.innerText
  44. if (window.lastText !== nowText) {
  45. window.lastText = nowText
  46. console.log(nowText)
  47. ipcRenderer.send('broadcast-message', nowText)
  48. }
  49. }
  50. }, 1000);
  51. // 拦截请求
  52. // (function(xhr) {
  53. // var XHR = XMLHttpRequest.prototype;
  54. // var open = XHR.open;
  55. // var send = XHR.send;
  56. // var setRequestHeader = XHR.setRequestHeader;
  57. // XHR.open = function(method, url) {
  58. // this._method = method;
  59. // this._url = url;
  60. // this._requestHeaders = {};
  61. // this._startTime = (new Date()).toISOString();
  62. // return open.apply(this, arguments);
  63. // };
  64. // XHR.setRequestHeader = function(header, value) {
  65. // this._requestHeaders[header] = value;
  66. // return setRequestHeader.apply(this, arguments);
  67. // };
  68. // XHR.send = function(postData) {
  69. // this.addEventListener('load', function() {
  70. // var endTime = (new Date()).toISOString();
  71. // var myUrl = this._url ? this._url.toLowerCase() : this._url;
  72. // if(myUrl) {
  73. // if (postData) {
  74. // if (typeof postData === 'string') {
  75. // try {
  76. // // here you get the REQUEST HEADERS, in JSON format, so you can also use JSON.parse
  77. // this._requestHeaders = postData;
  78. // } catch(err) {
  79. // console.log('Request Header JSON decode failed, transfer_encoding field could be base64');
  80. // console.log(err);
  81. // }
  82. // } else if (typeof postData === 'object' || typeof postData === 'array' || typeof postData === 'number' || typeof postData === 'boolean') {
  83. // // do something if you need
  84. // }
  85. // }
  86. // // here you get the RESPONSE HEADERS
  87. // var responseHeaders = this.getAllResponseHeaders();
  88. // if ( this.responseType != 'blob' && this.responseText) {
  89. // // responseText is string or null
  90. // try {
  91. // // here you get RESPONSE TEXT (BODY), in JSON format, so you can use JSON.parse
  92. // var arr = this.responseText;
  93. // // printing url, request headers, response headers, response body, to console
  94. // // console.log(this._url);
  95. // // console.log(JSON.parse(this._requestHeaders));
  96. // // console.log(responseHeaders);
  97. // // console.log(myUrl);
  98. // if (window.owoHackUrl) {
  99. // for (const key in window.owoHackUrl) {
  100. // if (Object.hasOwnProperty.call(window.owoHackUrl, key)) {
  101. // const element = window.owoHackUrl[key];
  102. // if (myUrl.includes(key)) {
  103. // if (element) element(arr)
  104. // }
  105. // }
  106. // }
  107. // }
  108. // if (window.owoHackUrlSend) {
  109. // for (const key in window.owoHackUrlSend) {
  110. // if (Object.hasOwnProperty.call(window.owoHackUrlSend, key)) {
  111. // const element = window.owoHackUrlSend[key];
  112. // if (myUrl.includes(key)) {
  113. // if (element) element(postData, myUrl)
  114. // }
  115. // }
  116. // }
  117. // }
  118. // } catch(err) {
  119. // console.log("Error in responseType try catch");
  120. // console.log(err);
  121. // }
  122. // }
  123. // }
  124. // });
  125. // return send.apply(this, arguments);
  126. // };
  127. // })(XMLHttpRequest);