煎蛋俠

為煎蛋jandan.net提供左右方向鍵快捷翻頁、上下方向鍵快捷切圖、鼠標懸停顯示大圖、屏蔽指定用戶發言等功能

目前為 2017-08-12 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 煎蛋侠
  3. // @name:en Jiandan Hero
  4. // @name:zh-TW 煎蛋俠
  5. // @namespace hoothin
  6. // @version 1.6
  7. // @icon http://cdn.jandan.net/static/img/favicon.ico
  8. // @description 为煎蛋jandan.net提供左右方向键快捷翻页、上下方向键快捷切图、鼠标悬停显示大图、屏蔽指定用户发言等功能
  9. // @description:en Tools for jandan.net
  10. // @description:zh-TW 為煎蛋jandan.net提供左右方向鍵快捷翻頁、上下方向鍵快捷切圖、鼠標懸停顯示大圖、屏蔽指定用戶發言等功能
  11. // @author hoothin
  12. // @include http*://jandan.net/*
  13. // @grant GM_setValue
  14. // @grant GM_getValue
  15. // @grant GM_deleteValue
  16. // ==/UserScript==
  17.  
  18. (function() {
  19. 'use strict';
  20. var timer,tempImg=document.createElement("img"),getImgWH=function(img,callBack){
  21. if(timer)clearInterval(timer);
  22. tempImg.src="";
  23. tempImg.src=img.src;
  24. var check=function(){
  25. if(tempImg.width>0 || tempImg.height>0){
  26. if(timer)clearInterval(timer);
  27. callBack(tempImg.width,tempImg.height);
  28. return true;
  29. }else{
  30. return false;
  31. }
  32. };
  33. var geted=check();
  34. if(!geted){
  35. timer = setInterval(check,40);
  36. }
  37. };
  38.  
  39. document.addEventListener("keydown", function(e) {
  40. if(/INPUT|TEXTAREA/.test(document.activeElement.tagName))return;
  41. switch(e.keyCode){
  42. case 37://←
  43. var next=document.querySelector("span#nav_next>a");
  44. if(next)next.click();
  45. break;
  46. case 39://→
  47. var pre=document.querySelector("span#nav_prev>a");
  48. if(pre)pre.click();
  49. break;
  50. case 38://↑
  51. if(/jandan\.net\/(ooxx|pic)/.test(location.href)){
  52. moveToPic(false);
  53. }
  54. break;
  55. case 40://↓
  56. if(/jandan\.net\/(ooxx|pic)/.test(location.href)){
  57. moveToPic(true);
  58. }
  59. break;
  60. }
  61. });
  62.  
  63. var pics=document.querySelectorAll(".commentlist .text img"),i;
  64. var currentPic;
  65. for(i=0;i<pics.length;i++){
  66. var pic=pics[i];
  67. if($(window).scrollTop() < ($(pic).offset().top + $(pic).outerHeight()) &&
  68. ($(window).scrollTop() + $(window).height()) > $(pic).offset().top){
  69. currentPic=pic;
  70. break;
  71. }
  72. }
  73. if(!currentPic)currentPic=pics[0];
  74.  
  75. function moveToPic(d){
  76. for(var i=0;i<pics.length;i++){
  77. var pic=pics[i];
  78. if(currentPic==pic){
  79. if(d && pics.length>(i+1)){
  80. currentPic=pics[i+1];
  81. }else if(!d && i>0){
  82. currentPic=pics[i-1];
  83. }
  84. if(currentPic.parentNode.style.display=="none")moveToPic(d);
  85. else currentPic.click();
  86. break;
  87. }
  88. }
  89. }
  90. var authors=document.querySelectorAll("div.author");
  91. var isHttps=location.protocol=="https:";
  92. for(i=0;i<authors.length;i++){
  93. let author=authors[i];
  94. let authorId=author.querySelector("strong").title.replace(/防伪码:/,"");
  95. let changeBtn=document.createElement("a");
  96. changeBtn.href=`javascript:void(0);`;
  97. changeBtn.id="changeBtn";
  98. changeBtn.style.display="none";
  99. author.insertBefore(changeBtn,author.querySelector("br"));
  100. if(GM_getValue("jandanDis_"+authorId)){
  101. author.nextSibling.nextSibling.style.display="none";
  102. changeBtn.innerHTML="显";
  103. }else{
  104. changeBtn.innerHTML="隐";
  105. }
  106. author.onmouseover=function(){
  107. changeBtn.style.display="block";
  108. };
  109. author.onmouseout=function(){
  110. changeBtn.style.display="none";
  111. };
  112. changeBtn.onclick=function(){
  113. var author_s,j,shown;
  114. if(author.nextSibling.nextSibling.style.display=="none"){
  115. shown=false;
  116. GM_deleteValue("jandanDis_"+authorId);
  117. }else{
  118. shown=true;
  119. GM_setValue("jandanDis_"+authorId,true);
  120. }
  121. for(j=0;j<authors.length;j++){
  122. author_s=authors[j];
  123. if(author_s.querySelector("strong").title.replace(/防伪码:/,"")==authorId){
  124. author_s.nextSibling.nextSibling.style.display=shown?"none":"block";
  125. author_s.querySelector("#changeBtn").innerHTML=shown?"显":"隐";
  126. }
  127. }
  128. };
  129. }
  130. var imgs=document.querySelectorAll("img"),left,top,src;
  131. var bigImg=document.createElement("img");
  132. bigImg.style.cssText="pointer-events: none;position:fixed;z-index:999";
  133. for(i=0;i<imgs.length;i++){
  134. let img=imgs[i];
  135. img.onmouseover=function(e){
  136. src=img.src.replace(/\b(custom|square)\b/,"medium").replace(/\.sinaimg\.cn\/(mw600|thumb\d+)/,".sinaimg.cn/large");
  137. src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://");
  138. bigImg.src=img.src;
  139. bigImg.src=src;
  140. left=e.clientX;
  141. top=e.clientY;
  142. document.body.appendChild(bigImg);
  143. relocBigImg(left, top);
  144. getImgWH(bigImg,function(w,h){
  145. relocBigImg(left, top, w, h);
  146. });
  147. bigImg.onload=function(){
  148. relocBigImg(left, top);
  149. };
  150. };
  151. img.onmouseout=function(e){
  152. if(bigImg.parentNode)bigImg.parentNode.removeChild(bigImg);
  153. bigImg.removeAttribute("height");
  154. bigImg.removeAttribute("width");
  155. };
  156. img.onmousemove=function(e){
  157. left=e.clientX;
  158. top=e.clientY;
  159. if(!bigImg.src || bigImg.src===""){
  160. img.onmouseover(e);
  161. }
  162. relocBigImg(left, top);
  163. };
  164. }
  165. $("p").on("mouseover","div.gif-mask",function(e){
  166. src=this.previousSibling.getAttribute("org_src").replace(/\b(custom|square)\b/,"medium").replace(/\.sinaimg\.cn\/(mw600|thumb\d+)/,".sinaimg.cn/large");
  167. src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://");
  168. bigImg.src=this.previousSibling.src;
  169. bigImg.src=src;
  170. document.body.appendChild(bigImg);
  171. getImgWH(bigImg,function(w,h){
  172. relocBigImg(left, top, w, h);
  173. });
  174. bigImg.onload=function(){
  175. relocBigImg(left, top);
  176. };
  177. });
  178. $("p").on("mouseout","div.gif-mask",function(e){
  179. if(bigImg.parentNode)bigImg.parentNode.removeChild(bigImg);
  180. bigImg.removeAttribute("height");
  181. bigImg.removeAttribute("width");
  182. });
  183. $("p").on("mousemove","div.gif-mask",function(e){
  184. if(e){
  185. left=e.clientX;
  186. top=e.clientY;
  187. }
  188. if(!bigImg.src || bigImg.src===""){
  189. this.onmouseover(e);
  190. }
  191. relocBigImg(left, top);
  192. });
  193. function relocBigImg(left, top, w, h){
  194. var imgWidth=w?w:bigImg.width;
  195. var imgHeight=h?h:bigImg.height;
  196. var type=imgHeight/imgWidth>document.documentElement.clientHeight/document.documentElement.clientWidth;
  197. if(type && imgHeight>document.documentElement.clientHeight){
  198. imgHeight=bigImg.height=document.documentElement.clientHeight;
  199. }
  200. if(!type && imgWidth>document.documentElement.clientWidth){
  201. imgWidth=bigImg.width=document.documentElement.clientWidth;
  202. }
  203. if(top-imgHeight<0){
  204. top=0;
  205. }else{
  206. top-=imgHeight;
  207. }
  208. if(left+imgWidth>document.documentElement.clientWidth){
  209. left=document.documentElement.clientWidth-imgWidth;
  210. }
  211. bigImg.style.left=left+10+"px";
  212. bigImg.style.top=top+"px";
  213. }
  214. })();

QingJ © 2025

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