TitleSearch

try to take over the world!

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

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