TitleSearch

try to take over the world!

当前为 2019-11-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name TitleSearch
  3. // @namespace http://tampermonkey.net/
  4. // @version 2.00
  5. // @description try to take over the world!
  6. // @author TitleSearch
  7. // @match *://www.abooky.com/*
  8. // @match *://www.yousuu.com/search*
  9. // @require http://libs.baidu.com/jquery/2.0.0/jquery.min.js
  10. // ==/UserScript==
  11.  
  12. (function () {
  13. 'use strict';
  14.  
  15. var urllist = [
  16. { name: 'abooky', url: /www\.abooky\.com/, titleid: '.ts', nosign: '' },
  17. ];
  18.  
  19. function make(obj) {
  20. if (obj.url.test(location.href)) {
  21. let t = $(obj.titleid).text();
  22. if (t) {
  23. console.log(t);
  24. let lnum, rnum, title;
  25. lnum = t.indexOf('《');
  26. if (lnum > 0) {
  27. rnum = t.indexOf('》');
  28. if (rnum > 0) {
  29. title = t.substring(lnum + 1, rnum);
  30. }
  31. } else {
  32. lnum = t.indexOf('<');
  33. if (lnum > 0) {
  34. rnum = t.indexOf('>');
  35. if (rnum > 0) {
  36. title = t.substring(lnum + 1, rnum);
  37. }
  38. }
  39. }
  40. console.log(title);
  41. if (title) {
  42. let b = $('<button></button>');
  43. b.text('优书网');
  44. b.css({
  45. "color": " #666",
  46. "background-color": " #EEE",
  47. "border-color": " #EEE",
  48. "font-weight": " 300",
  49. "font-size": " 16px",
  50. "text-decoration": " none",
  51. "text-align": " center",
  52. "line-height": " 25px",
  53. "height": " 25px",
  54. "padding": " 0 15px",
  55. "margin": " 0",
  56. "display": " inline-block",
  57. "appearance": " none",
  58. "cursor": " pointer",
  59. "border": " none",
  60. "-webkit-box-sizing": " border-box",
  61. "-moz-box-sizing": " border-box",
  62. "box-sizing": " border-box",
  63. "-webkit-transition-property": " all",
  64. "transition-property": " all",
  65. "-webkit-transition-duration": " .3s",
  66. "transition-duration": " .3s",
  67. "border-radius": " 4px"
  68. });
  69. b.click(function () {
  70. var content = document.createElement("a");
  71. content.href = 'http://yousuu.com/search/?SearchType=title&SearchValue=' + title + '#TitleSearch';
  72. content.target = '_blank';
  73. document.body.appendChild(content);
  74. content.click();
  75. document.body.removeChild(content);
  76. });
  77. $(obj.titleid).after(b);
  78. }
  79. }
  80.  
  81. }
  82. }
  83.  
  84. function autoclick() {
  85. const books = $('.list-card-layout');
  86. console.log(books);
  87. if (books.length == 1) {
  88. const bookname = books.find('.bookname');
  89. console.log(bookname);
  90. if (bookname.length == 1) {
  91. bookname[0].click();
  92. setTimeout(function () { window.close(); }, 1000);
  93. }
  94. }
  95. }
  96.  
  97. function run() {
  98.  
  99. if (location.hash && location.hash == '#TitleSearch') {
  100. setTimeout(autoclick, 1000);
  101. }
  102. else {
  103. urllist.forEach(make);
  104. }
  105. }
  106.  
  107. run();
  108. })();