Casanova Direct Links

Adds Direct Links to the online reader

  1. // ==UserScript==
  2. // @name Casanova Direct Links
  3. // @namespace https://github.com/ToostInc/userscripts
  4. // @description Adds Direct Links to the online reader
  5. // @include http://casanovascans.com/read/*
  6. // @author Joost Bremmer < toost dot b at gmail dot com >
  7. // @copyright 2014, Joost Bremmer
  8. // @license MIT
  9. // @version 1.3.3
  10. // @date 08-01-2015
  11. // @require http://code.jquery.com/jquery-latest.min.js
  12. // @grant GM_addStyle
  13. // @grant GM_xmlhttpRequest
  14. // ==/UserScript==
  15.  
  16.  
  17. // The MIT License
  18. //
  19. // Copyright (c) 2014 Joost Bremmer
  20. //
  21. // Permission is hereby granted, free of charge, to any person obtaining a
  22. // copy of this software and associated documentation files
  23. // (the "Software"), to deal in the Software without restriction,
  24. // including without limitation the rights to use, copy, modify, merge,
  25. // publish, distribute, sublicense, and/or sell copies of the Software, and
  26. // to permit persons to whom the Software is furnished to do so, subject to
  27. // the following conditions:
  28. //
  29. // The above copyright notice and this permission notice shall be included
  30. // in all copies or substantial portions of the Software.
  31. //
  32. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  33. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  34. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  35. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  36. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  37. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  38. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  39. //
  40.  
  41. $(document).ready (function () {
  42.  
  43.  
  44.  
  45.  
  46. //Add various tabs
  47. var dlinks = "<div id='dlinks' class='uk-navbar-nav dlinks'>\n" +
  48. "\t<h3>Direct Links:</h3>\n" +
  49. "</div>";
  50. var dlinksanchor = "<li class='uk-parent' id='dlinksli'>\n" +
  51. "\t<a href='#' id='dlinksanchor' style=''>" +
  52. "<p>Direct Links</p>" +
  53. "</a>\n" +
  54. "</li>";
  55.  
  56.  
  57.  
  58.  
  59. //insert tabs
  60. $("nav.uk-navbar > ul.uk-navbar-nav").append(dlinksanchor);
  61. $("div.uk-container nav.uk-navbar").after(dlinks);
  62.  
  63. //style tabs
  64.  
  65. GM_addStyle("#dlinks {" +
  66. "background-color: #FFFFFF;" +
  67. "padding-top: 10px;" +
  68. "padding-bottom: 05px;" +
  69. "display: none;" +
  70. "text-align: center;" +
  71. "z-index: 999; position: absolute;" +
  72. "width: 100%;"+
  73. "left: 0px;"+
  74. "}"
  75. );
  76.  
  77. //get image source
  78. var imgsrc = $("img.open").attr("src");
  79. //console.log(imgsrc);
  80.  
  81. //get total amount of pages
  82. var pages = $("a[title$='Pages']").html();
  83. var pages = pages.replace(/\s\<i.*\<\/i\>$/, "");
  84. //console.log(pages);
  85.  
  86. //insert message into Direct Links div.
  87. var dlmesg = '<p>\n' +
  88. '\tUse "Right-click > Save As" dialogue,' +
  89. 'or a download manager like ' +
  90. '<a href="http://www.downthemall.net/" id="dta">' +
  91. 'DownThemAll'+
  92. '</a> ' +
  93. 'to save the images.\n' +
  94. '<br />' +
  95. '</p>\n' +
  96. '<a href="#" id="dlloading">' +
  97. '\tLoading...'+
  98. '\t<br />\n' +
  99. '</a>';
  100.  
  101. $("#dlinks").append(dlmesg);
  102. $("#dlinks ").css("font-family", "'Courier'");
  103.  
  104. //event handler click on 'Direct Links' button.
  105. $("#dlinksanchor").click( function() {
  106. $("#dlinks").slideToggle("slow");
  107. });
  108.  
  109. //fetch links
  110. $(".uk-dropdown-small > ul:nth-child(1) li").each(function() {
  111. var nextpage = $(this).children("a").attr("href");
  112. //console.log(nextpage);
  113.  
  114. GM_xmlhttpRequest({
  115. method: "GET",
  116. url: nextpage,
  117. onload: function(response) {
  118. //console.log(response.responseText);
  119.  
  120.  
  121.  
  122. if ( response.responseText.indexOf('class="open"') > 0 ) {
  123. var raw = response.responseText;
  124. var content = /<img.*open.*>/.exec(raw)
  125. //console.log(content);
  126. var imglink = /"http.*"/.exec(content);
  127. //console.log(imglink[0]);
  128.  
  129.  
  130. var pagenum = /\d{2}\.(png|jpg)/.exec(imglink[0]);
  131. //console.log(pagenum[0]);
  132. var newpageanchor= '<a href=' + imglink[0] + 'id="page' +
  133. /\d{2}/.exec(pagenum[0]) + '">' +
  134. "\n\tPage " + (parseInt(/\d*/.exec(pagenum[0]))) + "<br />" +
  135. '</a>';
  136.  
  137. }
  138.  
  139. else {
  140. imglink[0] = "image not found!";
  141. pagenum = [""];
  142. pagenum.push(/\d*$/.exec(newpage));
  143. var newpageanchor='<a href="#" class="404">Uh-oh.something went wrong</a>' +
  144. '<br />';
  145. }
  146.  
  147. //insert links
  148. $("#dlinks").append(newpageanchor);
  149.  
  150. //sort links
  151. $('#dlinks a[id^="page"]').sort(function (a, b) {
  152. var re = /[^\d]/g;
  153. return ~~a.id.replace(re, '') > ~~b.id.replace(re, '');
  154. })
  155. .appendTo("#dlinks");
  156.  
  157.  
  158.  
  159. }
  160. });
  161.  
  162. //remove loading text
  163. if ( $(this).is(":last-child") ) {
  164. $("#dlloading").remove();
  165. }
  166.  
  167.  
  168. });
  169.  
  170.  
  171.  
  172.  
  173. });
  174.  

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址