TitleSearch

try to take over the world!

当前为 2021-02-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name TitleSearch
  3. // @namespace http://tampermonkey.net/
  4. // @version 5.02
  5. // @description try to take over the world!
  6. // @author TitleSearch
  7. // @match *://www.abooky.com/*
  8. // @match *://www.yousuu.com/search*
  9. // @match *://dushuxiaozi.com/category*
  10. // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
  11. // ==/UserScript==
  12. (function ( ) {
  13. "use strict";
  14. var $ = $ || window.$;
  15. var urllist = [
  16. { name: "abooky", url: /www\.abooky\.com/, titleid: ".ts", nosign: "" },
  17. ];
  18.  
  19. var run_mk = false;
  20. function gettitle(t, str1, str2) {
  21. let lnum, rnum, title;
  22. lnum = t.indexOf(str1);
  23. rnum = t.indexOf(str2);
  24. if (lnum < 0) lnum = 0;
  25. if (rnum < 0) rnum = 0;
  26. if (lnum > 0 || rnum > 0) {
  27. title = t.substring(lnum + 1, rnum);
  28. }
  29. if (title) title = title.replace("[TXT格式]", "").replace("\n", "");
  30.  
  31. return title;
  32. }
  33.  
  34. function addbutton(t) {
  35. if (t) {
  36. console.log(t);
  37. let title = gettitle(t, "《", "》");
  38. if (!title) {
  39. title = gettitle(t, "<", ">");
  40. }
  41. if (!title) {
  42. title = gettitle(t, "]", "⊙");
  43. }
  44.  
  45. console.log(title);
  46. if (title) {
  47. let b = $("<button></button>");
  48. b.text("优书网");
  49. b.css({
  50. color: " #666",
  51. "background-color": " #EEE",
  52. "border-color": " #EEE",
  53. "font-weight": " 300",
  54. "font-size": " 16px",
  55. "text-decoration": " none",
  56. "text-align": " center",
  57. "line-height": " 25px",
  58. height: " 25px",
  59. padding: " 0 15px",
  60. margin: " 0",
  61. display: " inline-block",
  62. appearance: " none",
  63. cursor: " pointer",
  64. border: " none",
  65. "-webkit-box-sizing": " border-box",
  66. "-moz-box-sizing": " border-box",
  67. "box-sizing": " border-box",
  68. "-webkit-transition-property": " all",
  69. "transition-property": " all",
  70. "-webkit-transition-duration": " .3s",
  71. "transition-duration": " .3s",
  72. "border-radius": " 4px",
  73. });
  74. b.click(function () {
  75. var content = document.createElement("a");
  76. content.href =
  77. "http://www.yousuu.com/search/?search_type=title&search_value=" +
  78. title +
  79. "#TitleSearch";
  80. content.target = "_blank";
  81. document.body.appendChild(content);
  82. content.click();
  83. document.body.removeChild(content);
  84. });
  85.  
  86. return b;
  87. }
  88. }
  89. }
  90.  
  91. function addDownbutton(t) {
  92. if (t) {
  93. console.log(t);
  94. let title = gettitle(t, "《", "》");
  95. if (!title) {
  96. title = gettitle(t, "<", ">");
  97. }
  98. if (!title) {
  99. title = gettitle(t, "]", "⊙");
  100. }
  101.  
  102. console.log(title);
  103. if (title) {
  104. let b = $("<button></button>");
  105. b.text("下载");
  106. b.css({
  107. color: " #666",
  108. "background-color": " #EEE",
  109. "border-color": " #EEE",
  110. "font-weight": " 300",
  111. "font-size": " 16px",
  112. "text-decoration": " none",
  113. "text-align": " center",
  114. "line-height": " 25px",
  115. height: " 25px",
  116. padding: " 0 15px",
  117. margin: " 0",
  118. display: " inline-block",
  119. appearance: " none",
  120. cursor: " pointer",
  121. border: " none",
  122. "-webkit-box-sizing": " border-box",
  123. "-moz-box-sizing": " border-box",
  124. "box-sizing": " border-box",
  125. "-webkit-transition-property": " all",
  126. "transition-property": " all",
  127. "-webkit-transition-duration": " .3s",
  128. "transition-duration": " .3s",
  129. "border-radius": " 4px",
  130. });
  131. b.click(function () {
  132. var content = document.createElement("a");
  133. content.href =
  134. "https://dushuxiaozi.com/wp-content/uploads/2019/book/" +
  135. title +
  136. ".zip";
  137. content.target = "_blank";
  138. document.body.appendChild(content);
  139. content.click();
  140. document.body.removeChild(content);
  141. });
  142.  
  143. return b;
  144. }
  145. }
  146. }
  147.  
  148. function make(obj) {
  149. if (obj.url.test(location.href)) {
  150. let t = $(obj.titleid).text();
  151. let b = addbutton(t);
  152. if (b) $(obj.titleid).after(b);
  153. }
  154. }
  155.  
  156. /**
  157. * @description : 根据ID检查元素是否可见,再点击
  158. * @param {*} cssid
  159. * @return {*}
  160. */
  161. function loop(cssid) {
  162. function checkVisible(elm) {
  163. var rect = elm.getBoundingClientRect();
  164. var viewHeight = Math.max(
  165. document.documentElement.clientHeight,
  166. window.innerHeight
  167. );
  168. return !(rect.bottom < 0 || rect.top - viewHeight >= 0);
  169. }
  170.  
  171. const s = document.querySelector(cssid);
  172. if (s) {
  173. let r = checkVisible(s);
  174. if (r) {
  175. s.click();
  176. // serch();
  177. }
  178. }
  179.  
  180. }
  181.  
  182. function autoclick() {
  183. let num = 0;
  184. const _Interval = setInterval(
  185. () => {
  186. let books = $(".list-card-layout");
  187. console.log(books);
  188. if (books.length == 0) books = $(".result-item-layout");
  189. console.log(books.length);
  190. if (books.length == 1) {
  191. const bookname = books.find(".book-name");
  192. console.log(bookname);
  193. if (bookname.length == 1) {
  194. bookname[0].click();
  195. clearInterval(_Interval)
  196. setTimeout(function () {
  197. window.close();
  198. }, 200);
  199. }
  200. } else {
  201. if (window.document.body.innerText.indexOf('找不到你要的结果:-)') > 0 || num > 10) {
  202. clearInterval(_Interval)
  203. window.close();
  204. }
  205. num++
  206. }
  207. }, 200
  208. )
  209.  
  210. }
  211.  
  212. function dushuxiaozi() {
  213. var count = 0;
  214. var isok = false;
  215. function serch() {
  216. var list = document.querySelectorAll("#main h2 > a");
  217. console.log(list);
  218. if (count != list.length && !isok) {
  219. isok = true;
  220. for (var i = 0; i < list.length; i++) {
  221. let t = $(list[i]).text();
  222. console.log(t);
  223. if (list[i].getAttribute("titlesearch_mk") != "true") {
  224. let b = addbutton(t);
  225. let b2 = addDownbutton(t);
  226. if (b) {
  227. $(list[i]).after(b2);
  228. $(list[i]).after(b);
  229. list[i].parentNode.style.cssText =
  230. "font-size: 18px;width: 750px;";
  231. list[i].setAttribute("titlesearch_mk", "true");
  232. }
  233. }
  234. }
  235. isok = false;
  236. }
  237. }
  238.  
  239. setInterval(() => loop(".ias-trigger-next"), 2000);
  240. serch();
  241.  
  242. document.querySelector("#main").addEventListener("DOMNodeInserted", serch);
  243. }
  244.  
  245. function run() {
  246. if (location.hash && location.hash == "#TitleSearch") {
  247. setTimeout(autoclick, 1100);
  248. } else {
  249. // if (/dushuxiaozi/.test(location.href)) {
  250. // dushuxiaozi();
  251. // } else {
  252. urllist.forEach(make);
  253. // }
  254. }
  255.  
  256. if (/www\.abooky\.com/.test(location.href)) {
  257. $(window).scroll(function () {
  258. var scrollTop = $(this).scrollTop();
  259. var scrollHeight = $(document).height();
  260. var windowHeight = $(this).height();
  261. if (scrollTop + windowHeight >= scrollHeight - 350) {
  262. if (!run_mk) {
  263. run_mk = true;
  264. loop("#autopbn");
  265. run_mk = false;
  266. }
  267. }
  268. });
  269. }
  270. }
  271.  
  272. run();
  273. })( );