Pixiv 增强

屏蔽广告, 查看热门图片, 按收藏数搜索, 下载gif、多图, 显示画师id、自动加载评论。github:https://github.com/Ahaochan/Tampermonkey,欢迎star和fork。

当前为 2017-11-03 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pixiv 增强
  3. // @namespace https://github.com/Ahaochan/Tampermonkey
  4. // @version 0.0.4
  5. // @description 屏蔽广告, 查看热门图片, 按收藏数搜索, 下载gif、多图, 显示画师id、自动加载评论。github:https://github.com/Ahaochan/Tampermonkey,欢迎star和fork。
  6. // @author Ahaochan
  7. // @match https://*.pixiv.net*
  8. // @match https://*.pixiv.net/*
  9. // @connect i.pximg.net
  10. // @grant GM_xmlhttpRequest
  11. // @require https://code.jquery.com/jquery-2.2.4.min.js
  12. // @require https://cdn.bootcss.com/jszip/3.1.4/jszip.min.js
  13. // @require https://cdn.bootcss.com/FileSaver.js/1.3.2/FileSaver.min.js
  14. // ==/UserScript==
  15.  
  16. (function ($) {
  17. 'use strict';
  18.  
  19. // 删除广告、查看热门图片
  20. (function () {
  21. // 删除广告
  22. $('._premium-lead-tag-search-bar').hide();
  23. // 查看热门图片
  24. $('.popular-introduction-overlay').hide();
  25. })();
  26.  
  27. // 按收藏数搜索
  28. (function () {
  29. $('.navigation-menu-right').append(
  30. '<div class="menu-group">' +
  31. ' <a class="menu-item js-click-trackable-later">' +
  32. ' <img class="_howto-icon" src="https://source.pixiv.net/www/images/knowhow/icon/howto-brush.svg?20171004">' +
  33. ' <span class="label">收藏人数:</span>' +
  34. ' <select id="ahao_favourite_num_select">' +
  35. ' <option value=""></option>' +
  36. ' <option value="10000users入り">10000users入り</option>' +
  37. ' <option value="5000users入り" > 5000users入り</option>' +
  38. ' <option value="1000users入り" > 1000users入り</option>' +
  39. ' <option value="500users入り" > 500users入り</option>' +
  40. ' <option value="300users入り" > 300users入り</option>' +
  41. ' <option value="100users入り" > 100users入り</option>' +
  42. ' <option value="50users入り" > 50users入り</option>' +
  43. ' </select>' +
  44. ' </a>' +
  45. '</div>');
  46.  
  47. // 如果已经有搜索字符串就在改变选项时直接搜索
  48. $('#ahao_favourite_num_select').on('change', function () {
  49. var $text = $('#suggest-input');
  50. if (!!$text.val()) {
  51. $('#suggest-container').submit();
  52. }
  53. });
  54.  
  55. // 在提交搜索前处理搜索关键字
  56. $('#suggest-container').submit(function () {
  57. var $text = $('#suggest-input');
  58. var $favourite = $('#ahao_favourite_num_select');
  59. // 去除旧的搜索选项
  60. $text.val($text.val().replace(/\d*users入り/, ''));
  61. // 去除多余空格
  62. while ($text.val().indexOf(' ') > -1) {
  63. $text.val($text.val().replace(' ', ' '));
  64. }
  65. // 添加新的搜索选项
  66. $text.val($text.val() + ' ' + $favourite.val());
  67. });
  68. })();
  69.  
  70. // 下载图片
  71. (function () {
  72. if (!(location.href.indexOf('member_illust.php') !== -1)) {
  73. return;
  74. }
  75. // 获取参数
  76. var param = $('.bookmark_modal_thumbnail')
  77. .attr('data-src')
  78. .match(/img-master\/img([\s\S]*?)_/)
  79. [1];
  80.  
  81. // 下载动图
  82. (function () {
  83. var hasGIF = !!$('div ._ugoku-illust-player-container').length;
  84. if (hasGIF) {
  85. var url = 'https://i.pximg.net/img-zip-ugoira/img' + param + '_ugoira600x600.zip';
  86. // 添加下载按钮
  87. $('div .bookmark-container').append(
  88. '<a href="' + url + '" class="_bookmark-toggle-button add-bookmark">' +
  89. ' <span class="bookmark-icon"></span><span class="description">下载动图</span>' +
  90. '</a>');
  91. }
  92. })();
  93.  
  94. // 下载多图
  95. (function () {
  96. var hasMore = !!$('a.read-more').length;
  97. if (hasMore) {
  98. var downloaded = 0; // 下载完成数量
  99. var num = $('a.read-more').text().match(/\d+/); // 下载目标数量
  100.  
  101. // 添加下载按钮
  102. var $a = $('<a class="_bookmark-toggle-button add-bookmark">' +
  103. ' <span class="bookmark-icon"></span><span class="description">下载失败</span>' +
  104. '</a>')
  105. .on('click', function () {
  106. if (downloaded < num) {
  107. return;
  108. }
  109. zip.generateAsync({type: "blob", base64: true}).then(function (content) {
  110. saveAs(content, "pic.zip"); // see FileSaver.js'
  111. });
  112. });
  113. $('div .bookmark-container').append($a);
  114.  
  115.  
  116. var zip = new JSZip();
  117. for (var i = 0; i < num; i++) {
  118. (function (index) {
  119. var url = 'https://i.pximg.net/img-master/img' + param + '_p' + index + '_master1200.jpg';
  120. GM_xmlhttpRequest({
  121. method: 'GET',
  122. headers: {referer: 'https://www.pixiv.net/'},
  123. overrideMimeType: 'text/plain; charset=x-user-defined',
  124. url: url,
  125. onload: function (xhr) {
  126. var r = xhr.responseText,
  127. data = new Uint8Array(r.length),
  128. i = 0;
  129. while (i < r.length) {
  130. data[i] = r.charCodeAt(i);
  131. i++;
  132. }
  133.  
  134. var blob = new Blob([data], {type: 'image/jpeg'});
  135.  
  136. downloaded++;
  137. zip.file('pic_' + index + '.jpg', blob, {binary: true});
  138.  
  139. if (downloaded == num) {
  140. $a.find('.description').text('下载多图(' + downloaded + '/' + num + ')');
  141. } else {
  142. $a.find('.description').text('下载中: ' + downloaded + '/' + num);
  143. }
  144. }
  145. });
  146. })(i);
  147. }
  148. }
  149. })();
  150. })();
  151.  
  152. // 显示画师id
  153. (function () {
  154. if (!(location.href.indexOf('member_illust.php') !== -1 ||
  155. location.href.indexOf('member.php') !== -1 )) {
  156. return;
  157. }
  158. $('a.user-name').after('<span>ID: ' + pixiv.context.userId + '</span>');
  159. })();
  160.  
  161. // 自动加载评论
  162. (function () {
  163. if (!(location.href.indexOf('member_illust.php') !== -1)) {
  164. return;
  165. }
  166.  
  167. // 1秒加载一次评论
  168. var timer = setInterval(function () {
  169. var clickEvent = document.createEvent('MouseEvents');
  170. clickEvent.initEvent('click', true, true);
  171.  
  172. var more = document.getElementsByClassName('more-comment')[0];
  173. if (!!more) {
  174. more.dispatchEvent(clickEvent);
  175. } else {
  176. clearInterval(timer);
  177. }
  178. }, 1000);
  179. })();
  180. })(jQuery);