preload.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. setInterval(() => {
  29. document.querySelectorAll('a[target]').forEach((el) => {
  30. el.removeAttribute('target')
  31. })
  32. }, 2000);
  33. // window.open = (url)=>{console.log(url)}
  34. window.lastText = ''
  35. setInterval(() => {
  36. // 快手
  37. if (document.querySelectorAll('.virt-list__client .comment-cell')[0]) {
  38. let nowMessage = document.querySelectorAll('.virt-list__client .comment-cell')[document.querySelectorAll('.virt-list__client .comment-cell').length - 1]
  39. let nowText = nowMessage.querySelector('.comment').innerText
  40. if (window.lastText !== nowText) {
  41. window.lastText = nowText
  42. console.log(nowText)
  43. ipcRenderer.send('broadcast-message', nowText)
  44. }
  45. }
  46. // 抖音
  47. if (document.querySelectorAll('.TNg5meqw')[0]) {
  48. let nowMessage = document.querySelectorAll('.TNg5meqw')[document.querySelectorAll('.TNg5meqw').length - 1]
  49. let nowText = nowMessage.innerText
  50. if (window.lastText !== nowText) {
  51. window.lastText = nowText
  52. console.log(nowText)
  53. ipcRenderer.send('broadcast-message', nowText)
  54. }
  55. }
  56. }, 1000);
  57. // 拦截请求
  58. // (function(xhr) {
  59. // var XHR = XMLHttpRequest.prototype;
  60. // var open = XHR.open;
  61. // var send = XHR.send;
  62. // var setRequestHeader = XHR.setRequestHeader;
  63. // XHR.open = function(method, url) {
  64. // this._method = method;
  65. // this._url = url;
  66. // this._requestHeaders = {};
  67. // this._startTime = (new Date()).toISOString();
  68. // return open.apply(this, arguments);
  69. // };
  70. // XHR.setRequestHeader = function(header, value) {
  71. // this._requestHeaders[header] = value;
  72. // return setRequestHeader.apply(this, arguments);
  73. // };
  74. // XHR.send = function(postData) {
  75. // this.addEventListener('load', function() {
  76. // var endTime = (new Date()).toISOString();
  77. // var myUrl = this._url ? this._url.toLowerCase() : this._url;
  78. // if(myUrl) {
  79. // if (postData) {
  80. // if (typeof postData === 'string') {
  81. // try {
  82. // // here you get the REQUEST HEADERS, in JSON format, so you can also use JSON.parse
  83. // this._requestHeaders = postData;
  84. // } catch(err) {
  85. // console.log('Request Header JSON decode failed, transfer_encoding field could be base64');
  86. // console.log(err);
  87. // }
  88. // } else if (typeof postData === 'object' || typeof postData === 'array' || typeof postData === 'number' || typeof postData === 'boolean') {
  89. // // do something if you need
  90. // }
  91. // }
  92. // // here you get the RESPONSE HEADERS
  93. // var responseHeaders = this.getAllResponseHeaders();
  94. // if ( this.responseType != 'blob' && this.responseText) {
  95. // // responseText is string or null
  96. // try {
  97. // // here you get RESPONSE TEXT (BODY), in JSON format, so you can use JSON.parse
  98. // var arr = this.responseText;
  99. // // printing url, request headers, response headers, response body, to console
  100. // // console.log(this._url);
  101. // // console.log(JSON.parse(this._requestHeaders));
  102. // // console.log(responseHeaders);
  103. // // console.log(myUrl);
  104. // if (window.owoHackUrl) {
  105. // for (const key in window.owoHackUrl) {
  106. // if (Object.hasOwnProperty.call(window.owoHackUrl, key)) {
  107. // const element = window.owoHackUrl[key];
  108. // if (myUrl.includes(key)) {
  109. // if (element) element(arr)
  110. // }
  111. // }
  112. // }
  113. // }
  114. // if (window.owoHackUrlSend) {
  115. // for (const key in window.owoHackUrlSend) {
  116. // if (Object.hasOwnProperty.call(window.owoHackUrlSend, key)) {
  117. // const element = window.owoHackUrlSend[key];
  118. // if (myUrl.includes(key)) {
  119. // if (element) element(postData, myUrl)
  120. // }
  121. // }
  122. // }
  123. // }
  124. // } catch(err) {
  125. // console.log("Error in responseType try catch");
  126. // console.log(err);
  127. // }
  128. // }
  129. // }
  130. // });
  131. // return send.apply(this, arguments);
  132. // };
  133. // })(XMLHttpRequest);