网页版微信助手

shows how to use coffeescript compiler

目前为 2020-04-28 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 网页版微信助手
  3. // @namespace https://muxueqz.top
  4. // @version 0.1
  5. // @description shows how to use coffeescript compiler
  6. // @author You
  7. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
  8. // @match *://wx.qq.com/*
  9. // @grant GM_addStyle
  10. // @grant GM_notification
  11.  
  12. // ==/UserScript==
  13. /* jshint ignore:start */
  14. // Generated by CoffeeScript 1.12.8
  15. (function() {
  16. var bind_mention_user, click_user, close_userselect, contact_list, editarea, get_input_user, get_users, html, origOpen, poll, send_msg, webwxgetcontact_url, webwxinit_url, webwxsync_url;
  17.  
  18. origOpen = XMLHttpRequest.prototype.open;
  19.  
  20. webwxsync_url = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxsync?';
  21.  
  22. webwxinit_url = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxinit?';
  23.  
  24. webwxgetcontact_url = 'https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact?';
  25.  
  26. contact_list = {};
  27.  
  28. XMLHttpRequest.prototype.open = function() {
  29. this.addEventListener('readystatechange', function() {
  30. var i, j, k, len, len1, modified_response, original_response, ref, ref1, ref2, results, results1, wx_msg;
  31. bind_mention_user();
  32. if (this.responseURL.lastIndexOf(webwxgetcontact_url) === 0) {
  33. original_response = this.responseText;
  34. modified_response = JSON.parse(original_response);
  35. console.log('webwxgetcontact_url request');
  36. ref = modified_response.MemberList;
  37. results = [];
  38. for (j = 0, len = ref.length; j < len; j++) {
  39. i = ref[j];
  40. results.push(contact_list[i.UserName] = i.NickName);
  41. }
  42. return results;
  43. } else if (this.responseURL.lastIndexOf(webwxinit_url) === 0) {
  44. original_response = this.responseText;
  45. modified_response = JSON.parse(original_response);
  46. console.log('webwxinit_url request');
  47. return console.log(modified_response);
  48. } else if (this.responseURL.lastIndexOf(webwxsync_url) === 0 && this.readyState === 4) {
  49. original_response = this.responseText;
  50. modified_response = JSON.parse(original_response);
  51. if (modified_response.AddMsgList.length > 0) {
  52. ref1 = modified_response.AddMsgList;
  53. results1 = [];
  54. for (k = 0, len1 = ref1.length; k < len1; k++) {
  55. wx_msg = ref1[k];
  56. console.log(wx_msg);
  57. console.log(contact_list[wx_msg.FromUserName], wx_msg.FromUserName);
  58. if (wx_msg.MsgType === 10002) {
  59. Object.defineProperty(this, "response", {
  60. writable: true
  61. });
  62. wx_msg.Content = 'test防撤回';
  63. GM_notification("有人想撤回消息噢");
  64. modified_response = JSON.stringify(modified_response);
  65. results1.push(this.response = modified_response);
  66. } else if (((ref2 = wx_msg.MsgType) === 10000 || ref2 === 10001) && (wx_msg.Content.indexOf("发出红包")) > -1) {
  67. results1.push(console.log("据说发出了红包"));
  68. } else if (wx_msg.MsgType === 10000) {
  69. results1.push(GM_notification("据说收到红包"));
  70. } else {
  71. results1.push(void 0);
  72. }
  73. }
  74. return results1;
  75. }
  76. }
  77. });
  78. return origOpen.apply(this, arguments);
  79. };
  80.  
  81. get_users = function(source_text) {
  82. var select;
  83. select = document.getElementById("userSelectionBox");
  84. return select.onclick = function() {
  85. var text, val;
  86. text = select.value;
  87. if (text.length > 1) {
  88. val = text;
  89. return console.log(val);
  90. }
  91. };
  92. };
  93.  
  94. click_user = function() {
  95. return console.log('click');
  96. };
  97.  
  98. close_userselect = function() {
  99. return $('#userSelectionBox').css('display', 'none');
  100. };
  101.  
  102. console.log('console log');
  103.  
  104. GM_notification("wx_helper enable");
  105.  
  106. GM_addStyle('.main_inner{max-width:70%}');
  107.  
  108. GM_addStyle('.main{height:88%; padding-top:50px}');
  109.  
  110. GM_addStyle('.bubble{font-size:16px}');
  111.  
  112. GM_addStyle('.chat .box_ft .content .flex{font-size:16px}');
  113.  
  114. send_msg = angular.element(document.querySelector(".btn.btn_send")).scope();
  115.  
  116. editarea = document.getElementById("editArea");
  117.  
  118. html = "<ul class=\"dropdown_menu\" id=\"userSelectionBox\" style=\"\n position: absolute;\n display: none;\n width: auto;\n left: 0;\n right: auto;\n top: 50%;\n max-height: 25%;\n /* z-index: 900; */\n right: auto;\n float: left;\n min-height: auto;\n min-width: auto;\n background: transparent;\n\">\n</ul>";
  119.  
  120. $("#chatArea").append(html);
  121.  
  122. document.getElementById('userSelectionBox').onclick = function(a) {
  123. var text;
  124. text = a.target.name;
  125. console.log(text);
  126. return click_user();
  127. };
  128.  
  129. get_input_user = function() {
  130. var clean_index, editarea_ng, editarea_scope, html_item, input, input_user, input_user_lower, item, j, len, member, member_list, newMessage, new_msg, ref, scope, source_text;
  131. source_text = editarea.innerHTML;
  132. input = editarea.innerHTML.replace('<br>', '').replace('</br>', '').split(' ').slice(-1)[0];
  133. if ('@' === input[0] && input.length > 1) {
  134. console.log('@input:' + input);
  135. html = "<select id=\"userSelectionBox\">\n <option value='" + item + "'>" + item + "</option>\n</select>";
  136. newMessage = html;
  137. scope = angular.element('#chatArea').scope();
  138. member_list = [];
  139. input_user = input.slice(1, -1);
  140. input_user_lower = input.slice(1, -1).toLowerCase();
  141. $('#userSelectionBox').empty();
  142. ref = scope.currentContact.MemberList;
  143. for (j = 0, len = ref.length; j < len; j++) {
  144. member = ref[j];
  145. item = member.NickName;
  146. if (item.toLowerCase().lastIndexOf(input_user_lower) !== -1 && input_user_lower.length > 0) {
  147. html_item = "<li>\n <a href=\"javascript:;\" title=\"" + item + "\" name=\"" + item + "\">\n " + item + " </a>\n</li>";
  148. $('#userSelectionBox').append(html_item);
  149. console.log(html_item);
  150. member_list.push(item);
  151. }
  152. }
  153. console.log(member_list);
  154. clean_index = input.lastIndexOf(input_user) - (2 + input_user.length + 1);
  155. console.log('clean_index:' + clean_index);
  156. console.log('input_user:' + input_user);
  157. console.log('source:' + source_text.slice(0, +clean_index + 1 || 9e9));
  158. console.log('member_list length:' + member_list.length);
  159. if (member_list.length > 0) {
  160. new_msg = source_text.slice(0, +clean_index + 1 || 9e9) + member_list.pop() + ' ';
  161. editarea_ng = angular.element('#editArea');
  162. editarea_ng.focus();
  163. editarea_ng.html('');
  164. editarea_scope = editarea_ng.scope();
  165. editarea_scope.insertToEditArea(new_msg);
  166. console.log('new_msg:' + new_msg);
  167. $('#userSelectionBox').css('display', 'block');
  168. return setTimeout(close_userselect, 3000);
  169. }
  170. }
  171. };
  172.  
  173. editarea.onkeypress = function(key) {
  174. console.log('keypress:' + key.key);
  175. if (key.key === '@') {
  176. return setTimeout(get_input_user, 10);
  177. }
  178. };
  179.  
  180. bind_mention_user = function() {
  181. editarea = document.getElementById("editArea");
  182. return editarea.onkeypress = function(key) {
  183. console.log('keypress:' + key.key);
  184. if (key.key === '@') {
  185. return setTimeout(get_input_user, 10);
  186. }
  187. };
  188. };
  189.  
  190. (poll = function() {
  191. bind_mention_user();
  192. return setTimeout(poll, 1000);
  193. })();
  194.  
  195. }).call(this);