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