Greasy Fork 还支持 简体中文。

zelluloza_one_list

Books in one list

  1. // ==UserScript==
  2. // @name zelluloza_one_list
  3. // @namespace https://zelluloza.ru/grub
  4. // @description Books in one list
  5. // @include https://zelluloza.ru/books/*
  6. // @include http://zelluloza.ru/books/*
  7. // @version 0.1
  8. // @run-at document-end
  9. // ==/UserScript==
  10.  
  11. var isStoped = false;
  12.  
  13. /*
  14. * copy book window
  15. */
  16. var bookBlock = document.createElement('div');
  17.  
  18. bookBlock.style.width = '800px';
  19. bookBlock.style.height = '200px';
  20. bookBlock.contentEditable = 'true';
  21. bookBlock.style.overflow = 'scroll';
  22. bookBlock.style.resize = 'both';
  23. bookBlock.hidden = true;
  24. bookBlock.style.border = '2px solid white';
  25.  
  26. /*
  27. * copy book menu
  28. */
  29. var copyMenu = document.createElement('div');
  30.  
  31. copyMenu.innerHTML = 'CopyBook: ';
  32. copyMenu.style.position = 'fixed';
  33. copyMenu.style.zIndex = 999;
  34. copyMenu.style.display = 'block !important';
  35. copyMenu.style.border = '4px solid yellow';
  36. copyMenu.style.backgroundColor = "black";
  37. copyMenu.style.color = 'white';
  38. copyMenu.style.width = '100%';
  39. copyMenu.id = 'oneListMenu';
  40.  
  41. /*
  42. * flip button
  43. */
  44. var flipButton = document.createElement('button');
  45.  
  46. flipButton.innerHTML = 'Flip copy';
  47. flipButton.onclick = function() {
  48. flipBookBlock();
  49. };
  50.  
  51. /*
  52. * clear button
  53. */
  54. var clearButton = document.createElement('button');
  55.  
  56. clearButton.innerHTML = 'Clear';
  57. clearButton.onclick = function() {
  58. clearCopyBook();
  59. };
  60.  
  61. /*
  62. * input field for dellay
  63. */
  64. var dellayInput = document.createElement('input');
  65. var dellayField = document.createElement('span');
  66. var dellayName = document.createElement('span');
  67.  
  68. dellayName.innerHTML = 'dellay: ';
  69.  
  70. dellayField.appendChild(dellayName);
  71. dellayField.appendChild(dellayInput);
  72.  
  73. dellayField.type = 'number';
  74. dellayInput.defaultValue = 1500;
  75.  
  76. /*
  77. * run button
  78. */
  79. var runButton = document.createElement('button');
  80.  
  81. runButton.innerHTML = 'Run';
  82. runButton.id = 'oneListButton';
  83.  
  84. runButton.onclick = function() {
  85. clearCopyBook();
  86. setTimeout(function() { inBookBegin() }, 2000);
  87. setTimeout(function() { copyBook(getBookCanvas(), 0) }, 4000);
  88. isStoped = false;
  89. changeStatus(statusVal.running);
  90. };
  91.  
  92. /*
  93. * interrupt button
  94. */
  95. var stopButton = document.createElement('button');
  96.  
  97. stopButton.innerHTML = 'Stop';
  98. stopButton.onclick = function() {
  99. isStoped = true;
  100. };
  101.  
  102. /*
  103. * status
  104. */
  105. var statusBar = document.createElement('span');
  106. var statusName = 'status: ';
  107. var statusVal = {
  108. 'stopped' : 'stopped',
  109. 'running' : 'running',
  110. 'done' : 'done'
  111. };
  112.  
  113. statusBar.style.color = 'orange';
  114. statusBar.style.border = '3px solid grey';
  115.  
  116. var progressBar = document.createElement('span');
  117. var progressBarName = 'progress: ';
  118.  
  119. progressBar.style.color = 'orange';
  120. progressBar.style.border = '3px solid grey';
  121. setProgress('none');
  122.  
  123. /*
  124. * flip
  125. */
  126. function flipBookBlock() {
  127. if(bookBlock.hidden)
  128. bookBlock.hidden = false;
  129. else bookBlock.hidden = true;
  130. }
  131.  
  132. function createControlMenu() {
  133. copyMenu.appendChild(runButton);
  134. copyMenu.appendChild(stopButton);
  135. copyMenu.appendChild(flipButton);
  136. copyMenu.appendChild(clearButton);
  137. copyMenu.appendChild(dellayField);
  138. copyMenu.appendChild(statusBar);
  139. copyMenu.appendChild(progressBar);
  140. copyMenu.appendChild(bookBlock);
  141. addElemToBody(copyMenu);
  142. changeStatus(statusVal.stopped);
  143. }
  144.  
  145. function getBookProgress() {
  146. return document.getElementById('bookpg').innerHTML;
  147. }
  148.  
  149. function changeStatus(status) {
  150. statusBar.innerHTML = statusName + status;
  151. }
  152.  
  153. function setProgress(progress) {
  154. progressBar.innerHTML = progressBarName + progress;
  155. }
  156.  
  157. function addElemToBody(newElem) {
  158. var bodyTag = document.getElementsByTagName('body')[0];
  159. var bodyTagChilds = bodyTag.getElementsByTagName('*');
  160. bodyTag.insertBefore(newElem, bodyTagChilds[0]);
  161. }
  162.  
  163.  
  164.  
  165. function getBookCanvas() {
  166. var pagesCanvas = document.getElementsByTagName('canvas')[0];
  167. console.log('get canvas id: ' + pagesCanvas.id);
  168. return pagesCanvas;
  169. }
  170.  
  171.  
  172. function getImgFromCanvas(bookCanvas) {
  173. var img = bookCanvas.toDataURL();
  174. return img;
  175. }
  176.  
  177. function toNextPageDown() {
  178. var rightButton = document.getElementsByClassName('boxb2')[1];
  179. rightButton.click();
  180. console.log('toNextPageDown');
  181.  
  182. }
  183.  
  184. function rexp100Perc(str) {
  185. var re = /100\%.*/;
  186. console.log('100 perc is ' + re.test(str) );
  187. return re.test(str);
  188. }
  189.  
  190. function lastPage() {
  191. var progressText = getBookProgress();
  192. var arr = progressText.split('/');
  193. var leftPageNum = +arr[0].split('-')[1];
  194. var rightPageNum = +arr[1];
  195. console.log('leftPageNum ' + leftPageNum);
  196. console.log('rightPageNum ' + rightPageNum);
  197. return leftPageNum === rightPageNum;
  198. }
  199.  
  200. function isPageEnd() {
  201. var progressText = document.getElementById('bookpg').innerHTML;
  202. var isEnd = rexp100Perc(progressText);
  203. console.log('is end ' + isEnd);
  204. return isEnd;
  205. }
  206.  
  207. function clearCopyBook() {
  208. bookBlock.innerHTML = "";
  209. }
  210.  
  211. function inBookBegin() {
  212. var beginButton = document.getElementsByClassName('boxb3')[0];
  213. beginButton.click();
  214. }
  215.  
  216. function copyBook(bookCanvas, i) {
  217. if(isStoped) {
  218. changeStatus(statusVal.stopped);
  219. return;
  220. }
  221. setProgress(getBookProgress());
  222.  
  223. copyPage(bookCanvas, i);
  224.  
  225. console.log('page numb: ' + i);
  226.  
  227. if( !lastPage() ) {
  228. setTimeout(function() {
  229. toNextPageDown();
  230. i++;
  231. copyBook(bookCanvas, i);
  232. }, dellayInput.value);
  233. } else {
  234. setTimeout(function() { changeStatus(statusVal.done) }, 2100);
  235. }
  236.  
  237. }
  238.  
  239. function copyPage(bookCanvas, i) {
  240. var image = new Image();
  241.  
  242. image.id = i;
  243. image.src = getImgFromCanvas(bookCanvas);
  244. printPage(image);
  245. }
  246.  
  247. function printPage(page) {
  248. bookBlock.appendChild(page);
  249. }
  250.  
  251.  
  252. function testBlock() {
  253. lastPage();
  254. }
  255.  
  256. window.onload = function() {
  257. testBlock();
  258. createControlMenu();
  259. };