Pixiv动图预览

在搜索页右侧显示预览图(非动图适用),分辨率低慎用。View preview of anime(pictures also supported.)

当前为 2017-06-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Pixiv动图预览
  3. // @namespace
  4. // @version 0.31
  5. // @description 在搜索页右侧显示预览图(非动图适用),分辨率低慎用。View preview of anime(pictures also supported.)
  6. // @author Ocrosoft
  7. // @match https://www.pixiv.net/search.php*
  8. // @match https://www.pixiv.net/member_illust.php*
  9. // @grant none
  10. // @require http://code.jquery.com/jquery-2.1.4.min.js
  11. // @namespace
  12. // ==/UserScript==
  13.  
  14. function downloadAnime(_class){
  15.  
  16. try{
  17. if(!_class)_class='.worksShare';
  18. console.log('append to '+_class);
  19. var t = $('#wrapper')[0].innerHTML;
  20. var reg = new RegExp('<script>[^<]*</script>');
  21. t = reg.exec(t)[0];
  22. reg = new RegExp('http[^"]*','g');
  23. var matches;
  24. var normal = reg.exec(t)[0],full = reg.exec(t)[0];
  25. /*while((matches = reg.exec(t)) !== null){
  26. console.log(matches[0]);
  27. }*/
  28. normal = normal.replace('/\\/g','');
  29. full = full.replace('/\\/g','');
  30. var div=document.createElement('div');
  31. div.innerHTML='<p class="worksShareTitle">下载</p><div class="embed"><dl><form class="_comment-form" style="width:100%;text-align:center;"><input id="dl_normal" type="button" value="普通版" class="submit-button" style="width:45%; padding:0px;"><input id="dl_full" type="button" value="全屏版" class="submit-button" style="width:45%; padding:0px;margin-left:5px;"></form></dl></div>';
  32. $(_class).append(div);
  33. $('#dl_normal').click(function(){
  34. window.open(normal);
  35. });
  36. $('#dl_full').click(function(){
  37. window.open(full);
  38. });
  39. }
  40. catch(e){}
  41. }
  42.  
  43. function addSidePreview() {
  44. 'use strict';
  45. $('._layout-thumbnail').mouseenter(function(){
  46. if($('#preview_div').attr('data-id')==$(this.children[0]).attr('data-id'))return;
  47. //console.log($(this.children[0]).attr('data-id'));
  48. var ifr=document.createElement('iframe');
  49. $(ifr).css({'width':'100%','height':'100%'});
  50. if($(this.parentNode.parentNode).children('a').hasClass('multiple'))ifr.src='https://www.pixiv.net/member_illust.php?mode=manga&illust_id='+$(this.children[0]).attr('data-id')+'#preview'; // 多图
  51. else ifr.src='https://www.pixiv.net/member_illust.php?mode=medium&illust_id='+$(this.children[0]).attr('data-id')+'#preview'; // 单图
  52. $('#preview_div').children().remove();
  53. $('#preview_div').append(ifr);
  54. $('#preview_div').attr('data-id',$(this.children[0]).attr('data-id'));
  55. });
  56. $('._layout-thumbnail').addClass('prev');
  57. }
  58.  
  59. function clearOtherElements(){
  60. if(location.href.indexOf('#preview')==-1)return;
  61. if(location.href.indexOf('=manga')!=-1){ // 多图
  62. $('body').children().each(function(i,d){
  63. if(d.id!='main')d.remove();
  64. });
  65. $('#main').children().each(function(i,d){
  66. if(!$(d).hasClass('manga'))d.remove();
  67. });
  68. return;
  69. }
  70. // 2
  71. var anime=false;
  72. if($('.player').children('canvas').length>0)anime=true;
  73.  
  74. if(anime)downloadAnime('.works_display');
  75. if(!anime){
  76. // 显示原图
  77. $('._illust_modal').removeClass('_hidden');
  78. $('._illust_modal').css('display','');
  79. var t=$('._illust_modal').children().children();
  80. t.each(function(i,d){
  81. if($(d).hasClass('original-image'))$(d).attr('src',$(d).attr('data-src'));
  82. });
  83. $('body').append($('._illust_modal'));
  84. $('body').children().each(function(i,d){
  85. if(!$(d).hasClass('_illust_modal'))d.remove();
  86. });
  87. $('img').attr({'height':'100%','width':'100%'});
  88. $('span').remove();
  89. }
  90. $('body').append($('.works_display')[0]);
  91. $('body').children().each(function(i,d){
  92. if(!$(d).hasClass('works_display')&&!$(d).hasClass('_illust_modal'))d.remove();
  93. });
  94. // 1
  95. /*var c=$('body').children();
  96. c.each(function(i,d){
  97. if(d.id!='wrapper')d.remove();
  98. else{
  99. $(d).children().each(function(j,e){
  100. if(!$(e).hasClass('layout-a'))e.remove();
  101. else{
  102. $('.layout-column-1').remove();
  103. }
  104. });
  105. }
  106. });
  107. c=$('.layout-column-2').children();
  108. c.each(function(i,d){
  109. if(!$(d).hasClass('_unit'))d.remove();
  110. else{
  111. $(d).children().each(function(j,e){
  112. if(!$(e).hasClass('works_display'))e.remove();
  113. });
  114. }
  115. });*/
  116. //$('body').css('display','');
  117. }
  118.  
  119. if(location.href.indexOf('member_illust.php')!=-1){
  120. //$('body').css('display','none');
  121. $('document').ready(clearOtherElements());
  122. }else {
  123. setInterval(function(){
  124. if($('#preview_div').length<=0){
  125. try{$($('.popular-introduction-block')[0].parentNode).remove();}catch(e){}
  126. var d=document.createElement('div');
  127. d.id="preview_div";
  128. $(d).css({"right":"0px","position":"fixed","top":"0px","width":"25%","height":"100%"});
  129. //d.innerHTML='<iframe style="width:100%;height:100%;"></iframe>';
  130. $('body').append(d);
  131. //https://www.pixiv.net/member_illust.php?mode=medium&illust_id=62814980
  132. }
  133. var t=$('._layout-thumbnail');
  134. if(!$(t[t.length-1]).hasClass('prev'))addSidePreview();
  135. },500);
  136. }