一键截图

截图

Този скрипт не може да бъде инсталиран директно. Това е библиотека за други скриптове и може да бъде използвана с мета-директива // @require https://update.greasyfork.org/scripts/515031/1474955/%E4%B8%80%E9%94%AE%E6%88%AA%E5%9B%BE.js

  1. (function () {
  2. let a = document['getElementById']('yl_8') && document['getElementById']('yl_8')['onclick'] || jQuery;
  3. var b;
  4. var c;
  5. var d;
  6. var e = {
  7. 'x':0,
  8. 'y':0
  9. };
  10. GM_registerMenuCommand(b ? '关闭截图识别文字(shift+↓)' : '装载截图识别文字(shift+↑)', function () {
  11. b ? document['body']['removeEventListener']('mousedown', jietu_mouse) : jietu_onload();
  12. b = null;
  13. });
  14. document['addEventListener']('keydown', function (g) {
  15. if (g['shiftKey'] && g['key'] === 'ArrowUp') {
  16. jietu_onload();
  17. } else if (g['shiftKey'] && g['key'] === 'ArrowDown') {
  18. console['log']('shift\x20+\x20下\x20关闭截图');
  19. document['body']['removeEventListener']('mousedown', jietu_mouse);
  20. }
  21. });
  22. jietu_onload = g => {
  23. c = document['createElement']('div');
  24. c['className'] = 'select_box';
  25. let h =`
  26. .select_box {
  27. overflow: hidden; /* 隐藏超出的内容 */
  28. border: 1px dashed #f00;
  29. position: absolute;
  30. pointer-events: none;
  31. display:block;
  32. z-index:999;
  33. // background-color: #f0f0f0;
  34. }
  35. .select_box canvas{
  36. cursor : move;
  37. position: absolute;
  38. z-index:1;
  39. }
  40. .select_box *{
  41. pointer-events: none;
  42. width:100%;
  43. font-size: 12px;
  44. position: absolute;
  45. z-index:2;
  46. text-shadow: 0 0 gray;
  47. }
  48. `
  49. GM_addStyle(h);
  50. a('html')[0x0]['appendChild'](c);
  51. var i = ![];
  52. var j =0;
  53. var k =0;
  54. var l =0;
  55. var m =0;
  56. c['addEventListener']('mousedown', r => {
  57. i = !![];
  58. j = r['clientX'];
  59. k = r['clientY'];
  60. l = parseInt(b['style']['top']);
  61. m = parseInt(b['style']['left']);
  62. });
  63. var n =0;
  64. var o =0;
  65. c['addEventListener']('mousemove', r => {
  66. if (i) {
  67. n = r['clientX'];
  68. o = r['clientY'];
  69. b['style']['top'] = l - Math['floor'](k - o) + 'px';
  70. b['style']['left'] = m - Math['floor'](j - n) + 'px';
  71. }
  72. });
  73. c['addEventListener']('mouseup', () => {
  74. if (i && (n || o)) {
  75. e['y'] = e['y'] + Math['floor'](k - o);
  76. e['x'] = e['x'] + Math['floor'](j - n);
  77. console['log'](e);
  78. k = j = n = o =0;
  79. }
  80. i = ![];
  81. });
  82. console['log']('shift\x20+\x20上箭头被按下,更新截图页面');
  83. document['body']['addEventListener']('mousedown', jietu_mouse);
  84. f();
  85. const p = 'chi_sim';
  86. const q = 'https://unpkg.com/@tesseract.js-data/' + p + '/4.0.0_best_int';
  87. ((async () => {
  88. d = await Tesseract['createWorker'](p, 0x1, {
  89. 'corePath': 'https://unpkg.com/tesseract.js-core@v5',
  90. 'workerPath': 'https://unpkg.com/tesseract.js@v5/dist/worker.min.js',
  91. 'langPath': q,
  92. 'logger': function (r) {
  93. console['log'](r);
  94. }
  95. });
  96. })());
  97. };
  98. jietu_mouse = g => {
  99. c['innerHTML'] = '';
  100. startX = g['pageX'];
  101. startY = g['pageY'];
  102. c['style']['left'] = startX + 'px';
  103. c['style']['top'] = startY + 'px';
  104. c['style']['width'] = '0px';
  105. c['style']['height'] = '0px';
  106. c['style']['display'] = 'block';
  107. document['body']['style']['cursor'] = 'crosshair';
  108. document['body']['style']['user-select'] = 'none';
  109. const h = j => {
  110. endX = j['pageX'];
  111. endY = j['pageY'];
  112. c['style']['width'] = Math['abs'](endX - startX) + 'px';
  113. c['style']['height'] = Math['abs'](endY - startY) + 'px';
  114. c['style']['left'] = Math['min'](startX, endX) + 'px';
  115. c['style']['top'] = Math['min'](startY, endY) + 'px';
  116. };
  117. const i = () => {
  118. document['body']['style']['cursor'] = 'default';
  119. document['body']['style']['user-select'] = 'text';
  120. document['removeEventListener']('mousemove', h);
  121. document['removeEventListener']('mouseup', i);
  122. var j;
  123. try {
  124. j = b['getContext']('2d');
  125. } catch {
  126. c['innerHTML'] = '<p>正在渲染图片请稍后重新框选</p>';
  127. }
  128. const k = parseInt(c['style']['width']);
  129. const l = parseInt(c['style']['height']);
  130. if (!k || !l) {
  131. return;
  132. }
  133. b['style']['pointer-events'] = 'auto';
  134. c['appendChild'](b);
  135. const m = parseInt(c['style']['left']);
  136. const n = parseInt(c['style']['top']);
  137. const o = j['getImageData']((m + e['x']) * 0x2, (n + e['y']) * 0x2, k * 0x2, l * 0x2);
  138. const p = document['createElement']('canvas');
  139. p['width'] = k * 0x2;
  140. p['height'] = l * 0x2;
  141. p['getContext']('2d')['putImageData'](o,0,0);
  142. base64 = p['toDataURL']()['replace'](/^data:image\/(png|jpg);base64,/, '');
  143. value = 'data:image/png;base64,' + base64;
  144. b['style']['top'] = -e['y'] - n + 'px';
  145. b['style']['left'] = -e['x'] - m + 'px';
  146. console['log'](e);
  147. try {
  148. d['recognize'](value, 'chi_sim', {})['then'](q => {
  149. var r = q?.['data']?.['text']['replace'](/\s/g, '');
  150. if (r) {
  151. console['log']('【识别结果】', r);
  152. div_set['parent']()['show']();
  153. div_set['show']();
  154. find_input['value'] = r;
  155. } else {
  156. msg_box = document['createElement']('div');
  157. msg_box['innerHTML'] = '<p>未识别到文字,如选区中无内容请拖动选区到合适位置</br>并重新框选,如有BUG请QQ频道反馈</p>';
  158. c['appendChild'](msg_box);
  159. }
  160. })['catch'](q => {
  161. console['error']('【错误】', q);
  162. });
  163. } catch {
  164. c['innerHTML'] = '<p>识别工具暂未加载完毕,请稍等</p>';
  165. }
  166. };
  167. document['addEventListener']('mousemove', h);
  168. document['addEventListener']('mouseup', i);
  169. };
  170. function f() {
  171. const g = document['body'];
  172. var h = {
  173. 'useCORS': !![],
  174. 'scrollY':0,
  175. 'scrollX':0
  176. };
  177. html2canvas(g, h)['then'](i => {
  178. b = i;
  179. });
  180. }
  181. }());