177Viewer

添加三个按钮,免翻页查看整篇漫画,下载全部图片

目前为 2019-03-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 177Viewer
  3. // @namespace https://greasyfork.org/zh-CN/scripts/380478-177viewer
  4. // @version 0.2
  5. // @description 添加三个按钮,免翻页查看整篇漫画,下载全部图片
  6. // @author gfbxy
  7. // @match http://www.177pic.info/html/*.html
  8. // @match http://www.177pic001.info/html/*.html
  9. // @run-at document-end
  10. // @grant GM_setClipboard
  11. // ==/UserScript==
  12.  
  13. (function () {
  14. 'use strict';
  15.  
  16. var btnOne = $('<button style="padding:3px;color:#999;margin-right:5px" >动态加载</button>');
  17. var btnAll = $('<button style="padding:3px;color:#999;margin-right:5px" >加载全部</button>');
  18. var btnLoad = $('<button style="padding:3px;color:#fb9251;" >下载图片</button>');
  19. var config;
  20. var cookieIndex = document.cookie.indexOf('177viewer=')
  21.  
  22. // 读取设置
  23. if (!cookieIndex) {
  24. config = document.cookie.slice(cookieIndex + 10, cookieIndex + 11);
  25. if (config == 1) {
  26. $(btnAll).css('color', '#ff6100');
  27. }
  28. else {
  29. $(btnOne).css('color', '#ff6100');
  30. }
  31. }
  32. else {
  33. document.cookie = '177viewer=0'
  34. config = 0;
  35. $(btnOne).css('color', '#ff6100');
  36. }
  37.  
  38. // 重新设置并刷新
  39. $('.c-top2').after(btnOne, btnAll, btnLoad);
  40. $(btnOne).on('click', function () {
  41. document.cookie = '177viewer=0';
  42. location = location;
  43. });
  44. $(btnAll).on('click', function () {
  45. document.cookie = '177viewer=1';
  46. location = location;
  47. });
  48.  
  49.  
  50. //获取页面链接
  51. var a = $('div.wp-pagenavi a');
  52. var href = [window.location.href];
  53. for (var i = 0; i < a.length - 1; i++) {
  54. href[i + 1] = (a.eq(i).attr('href'));
  55. }
  56.  
  57. var wait = 0;
  58. var pageIndex = 1;
  59. // 一次性加载
  60. if (config == 1) {
  61. loadImg(1, href.length);
  62. }
  63. // 动态加载
  64. else {
  65. // 滚动加载函数
  66. window.onload = function () {
  67. window.onscroll = function () {
  68. if (wait == 1 || pageIndex >= href.length) {
  69. return;
  70. }
  71. wait = 1;
  72. setTimeout(function () {
  73. wait = 0;
  74. }, 500);
  75. // 快滚到底了
  76. if ($(this).scrollTop() + $(this).height() + 1500 >= $(document).height()) {
  77. loadImg(pageIndex, href.length);
  78. pageIndex++;
  79. }
  80. };
  81. };
  82. }
  83.  
  84. // 加载图片函数
  85. function loadImg(page, end) {
  86. if (page == end) {
  87. return;
  88. }
  89. $('<div></div>').load(href[page] + ' .entry-content', function () {
  90. $('#single-navi').before($(this).children().children('p'));
  91.  
  92. if (config == 1) {
  93. page++;
  94. loadImg(page, end);
  95. }
  96. });
  97. }
  98.  
  99.  
  100. // 下载按钮
  101. $(btnLoad).on('click', function () {
  102. var title = $("h1").text();
  103. title = title.replace(/\[|\]|\(|\)"/g, function (matchStr) {
  104. var tokenMap = {
  105. '(': '【',
  106. ')': '】',
  107. '[': '【',
  108. "]": '】'
  109. };
  110. return tokenMap[matchStr];
  111. });
  112.  
  113. $.ajaxSetup({
  114. async: false
  115. });
  116. var doc = [];
  117. for (var l = 0; l < href.length; l++) {
  118. $.get(href[l], function (data) {
  119. doc[l] = new DOMParser().parseFromString(data, "text/html");
  120. });
  121. }
  122. var result = 'md "' + title + '"\r\n' + 'cd "' + title + '"\r\n';
  123. for (var i = 0, n = 0; i < doc.length; i++ , n = n + img.length) {
  124. var img = doc[i].querySelectorAll("img[alt]");
  125. for (var j = 0; j < img.length; j++) {
  126. result = result + "wget -O " + '"' + [n + j] + '.jpg" ' + img[j].src + "\r\n";
  127. }
  128. }
  129. result = result;
  130. GM_setClipboard(result);
  131. alert("已复制!在想保存的文件夹打开cmd,右键粘贴下载!");
  132. });
  133. })();