煎蛋侠

为煎蛋jandan.net提供左右方向键快捷翻页、上下方向键快捷切图、鼠标悬停显示大图、屏蔽指定用户发言等功能

  1. // ==UserScript==
  2. // @name 煎蛋侠
  3. // @name:en Jandan Hero
  4. // @name:zh-TW 煎蛋俠
  5. // @namespace hoothin
  6. // @version 2.0
  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. // @match http*://jandan.net/*
  13. // @match http*://i.jandan.net/*
  14. // @grant GM_setValue
  15. // @grant GM_getValue
  16. // @grant GM_deleteValue
  17. // @grant GM_addStyle
  18. // @run-at document-idle
  19. // ==/UserScript==
  20.  
  21. (function() {
  22. 'use strict';
  23. var timer,tempImg=document.createElement("img"),getImgWH=function(img,callBack){
  24. if(timer)clearInterval(timer);
  25. tempImg.src="";
  26. tempImg.src=img.src;
  27. var check=function(){
  28. if(tempImg.width>0 || tempImg.height>0){
  29. if(timer)clearInterval(timer);
  30. callBack(tempImg.width,tempImg.height);
  31. return true;
  32. }else{
  33. return false;
  34. }
  35. };
  36. var geted=check();
  37. if(!geted){
  38. timer = setInterval(check,40);
  39. }
  40. };
  41.  
  42. document.addEventListener("keyup", function(e) {
  43. if(/INPUT|TEXTAREA/.test(document.activeElement.tagName))return;
  44. switch(e.keyCode){
  45. case 37://←
  46. var next=document.querySelector("span#nav_next>a");
  47. if(next)next.click();
  48. break;
  49. case 39://→
  50. var pre=document.querySelector("span#nav_prev>a");
  51. if(pre)pre.click();
  52. break;
  53. case 38://↑
  54. if(/jandan\.net\/(ooxx|pic|girl|top|zoo|dzh)/.test(location.href)){
  55. moveToPic(false);
  56. }
  57. break;
  58. case 40://↓
  59. if(/jandan\.net\/(ooxx|pic|girl|top|zoo|dzh)/.test(location.href)){
  60. moveToPic(true);
  61. }
  62. break;
  63. }
  64. });
  65.  
  66. var pic,pics,currentPic,i;
  67. var isHttps=location.protocol=="https:",selector;
  68. var isTucao=document.querySelector(".tucao-list")!=null;
  69. var isTop=location.href.indexOf("jandan.net/top")!=-1;
  70. var isMobile=location.href.indexOf("i.jandan.net")!=-1;
  71.  
  72. function moveToPic(d){
  73. pics=document.querySelectorAll(".commentlist .text img,.tucao-list img");
  74. if(!currentPic && pics)currentPic=pics[0];
  75. else{
  76. for(i=0;i<pics.length;i++){
  77. pic=pics[i];
  78. if(isTucao){
  79. if(($(window).scrollTop() + $(window).height() / 2) < ($(pic).offset().top + $(pic).outerHeight()) &&
  80. ($(window).scrollTop() + $(window).height() / 2) > $(pic).offset().top){
  81. currentPic=pic;
  82. break;
  83. }
  84. }else{
  85. if($(window).scrollTop() < ($(pic).offset().top + $(pic).outerHeight()) &&
  86. ($(window).scrollTop() + $(window).height()) > $(pic).offset().top){
  87. currentPic=pic;
  88. break;
  89. }
  90. }
  91. }
  92. if(!currentPic && pics)currentPic=pics[0];
  93. for(var i=0;i<pics.length;i++){
  94. pic=pics[i];
  95. var pi;
  96. if(currentPic==pic){
  97. if(d && pics.length>(i+1)){
  98. pi=i+1;
  99. currentPic=pics[pi];
  100. while($(currentPic).is(":hidden") && ++pi<pics.length){
  101. currentPic=pics[pi];
  102. }
  103. }else if(!d && i>0){
  104. pi=i-1;
  105. currentPic=pics[pi];
  106. while($(currentPic).is(":hidden") && --pi>0){
  107. currentPic=pics[pi];
  108. }
  109. }
  110. break;
  111. }
  112. }
  113. }
  114. setTimeout(()=>{
  115. if(isTucao){
  116. currentPic.scrollIntoView({behavior: "smooth", block: "center", inline: "center"});
  117. }else if(currentPic.nextSibling && currentPic.nextSibling.className=="gif-mask"){
  118. currentPic.nextSibling.click();
  119. }
  120. currentPic.click();
  121. },100);
  122. }
  123.  
  124. function checkBan(author){
  125. let authorId;
  126. let changeBtn = author.querySelector("#changeBtn");
  127. if(changeBtn == null){
  128. changeBtn=document.createElement("a");
  129. changeBtn.href=`javascript:void(0);`;
  130. changeBtn.id="changeBtn";
  131. if(isMobile){
  132. author=author.querySelector("b");
  133. if(!author)return;
  134. authorId=author.innerText;
  135. author.parentNode.insertBefore(changeBtn,author.parentNode.querySelector(".righttext"));
  136. }else if(isTucao){
  137. authorId=author.querySelector(".tucao-author").innerText;
  138. author.insertBefore(changeBtn,author.querySelector(".tucao-author").nextSibling);
  139. }else{
  140. authorId=isTop?author.querySelector("strong").innerText:author.querySelector("strong").title.replace(/防伪码:/,"");
  141. author.insertBefore(changeBtn,author.querySelector("br"));
  142. }
  143. changeBtn.onclick=function(){
  144. var author_s,j,shown;
  145. if(author.parentNode.classList.contains("hide")){
  146. shown=false;
  147. GM_deleteValue("jandanDis_"+authorId);
  148. }else{
  149. shown=true;
  150. GM_setValue("jandanDis_"+authorId,true);
  151. }
  152. var authors=document.querySelectorAll("div.author,.tucao-author-bar,.commentlist>li>b");
  153. for(j=0;j<authors.length;j++){
  154. author_s=authors[j];
  155. var changeBtn_s=author_s.querySelector("#changeBtn");
  156. var isSame=false;
  157. if(isMobile){
  158. isSame=author_s.childNodes[0].nodeValue==authorId;
  159. }else if(isTucao){
  160. isSame=author_s.querySelector(".tucao-author").innerText==authorId;
  161. }else if(isTop){
  162. isSame=author_s.querySelector("strong").innerText==authorId;
  163. }else{
  164. isSame=author_s.querySelector("strong").title.replace(/防伪码:/,"")==authorId;
  165. }
  166. if(isSame){
  167. //author_s.nextSibling.nextSibling.style.display=shown?"none":"block";
  168. if(shown){
  169. author_s.parentNode.classList.add("hide");
  170. if(changeBtn_s)changeBtn_s.innerHTML="显";
  171. }else{
  172. author_s.parentNode.classList.remove("hide");
  173. if(changeBtn_s)changeBtn_s.innerHTML="隐";
  174. }
  175. }
  176. }
  177. };
  178. if(GM_getValue("jandanDis_"+authorId)){
  179. author.parentNode.classList.add("hide");
  180. changeBtn.innerHTML="显";
  181. }else{
  182. changeBtn.innerHTML="隐";
  183. }
  184. }
  185. return changeBtn;
  186. }
  187.  
  188. if(isMobile){
  189. selector=".commentlist>li";
  190. }else{
  191. selector="div.author,.tucao-author-bar";
  192. }
  193. [].forEach.call(document.querySelectorAll(selector), item=>{
  194. checkBan(item);
  195. });
  196. var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
  197. var observer = new MutationObserver(function(records){
  198. records.map(function(record) {
  199. for(var i=0;i<record.addedNodes.length;i++){
  200. var curNode=record.addedNodes[i];
  201. if(curNode.className=="tucao-row"){
  202. checkBan(curNode.querySelector(selector));
  203. }
  204. }
  205. });
  206. });
  207. var option = {
  208. 'childList': true
  209. };
  210. var tucaoList=document.querySelector("div.tucao-list");
  211. if(tucaoList)observer.observe(tucaoList, option);
  212. $("body").on("mouseover", selector, e=>{
  213. let changeBtn=checkBan(e.currentTarget);
  214. changeBtn.style.display="initial";
  215. //console.log(e);
  216. });
  217. $("body").on("mouseout", selector, e=>{
  218. let author=e.currentTarget;
  219. let changeBtn = author.querySelector("#changeBtn");
  220. if(changeBtn)changeBtn.style.display="";
  221. });
  222. /*for(i=0;i<authors.length;i++){
  223. let author=authors[i];
  224. let changeBtn=document.createElement("a");
  225. changeBtn.href=`javascript:void(0);`;
  226. changeBtn.id="changeBtn";
  227. changeBtn.style.display="none";
  228. let authorId;
  229. if(isTucao){
  230. authorId=author.querySelector(".tucao-author").innerText;
  231. author.appendChild(changeBtn);
  232. }else{
  233. authorId=isTop?author.querySelector("strong").innerText:author.querySelector("strong").title.replace(/防伪码:/,"");
  234. author.insertBefore(changeBtn,author.querySelector("br"));
  235. }
  236. if(GM_getValue("jandanDis_"+authorId)){
  237. author.parentNode.classList.add("hide");
  238. changeBtn.innerHTML="显";
  239. }else{
  240. changeBtn.innerHTML="隐";
  241. }
  242. author.onmouseover=function(){
  243. changeBtn.style.display="block";
  244. };
  245. author.onmouseout=function(){
  246. changeBtn.style.display="none";
  247. };
  248. changeBtn.onclick=function(){
  249. var author_s,j,shown;
  250. if(author.parentNode.classList.contains("hide")){
  251. shown=false;
  252. GM_deleteValue("jandanDis_"+authorId);
  253. }else{
  254. shown=true;
  255. GM_setValue("jandanDis_"+authorId,true);
  256. }
  257. for(j=0;j<authors.length;j++){
  258. author_s=authors[j];
  259. if((isTucao && author_s.querySelector(".tucao-author").innerText==authorId) || !isTucao &&(
  260. (!isTop && author_s.querySelector("strong").title.replace(/防伪码:/,"")==authorId) ||
  261. (isTop && author_s.querySelector("strong").innerText==authorId))){
  262. //author_s.nextSibling.nextSibling.style.display=shown?"none":"block";
  263. if(shown){
  264. author_s.parentNode.classList.add("hide");
  265. author_s.querySelector("#changeBtn").innerHTML="显";
  266. }else{
  267. author_s.parentNode.classList.remove("hide");
  268. author_s.querySelector("#changeBtn").innerHTML="隐";
  269. }
  270. }
  271. }
  272. };
  273. }*/
  274. var left,top,src;
  275. var bigImg=document.createElement("img");
  276. bigImg.className="big_img";
  277. $("body").on("mouseover","img",e=>{
  278. if(isMobile)return;
  279. let img=e.currentTarget;
  280. src=img.src.replace(/\b(!(custom|square))\b/,"").replace(/\b(custom|square)\b/,"medium").replace(/\.sinaimg\.cn\/thumb\d+/,".sinaimg.cn/large");
  281. src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://");
  282. bigImg.src=img.src;
  283. bigImg.src=src;
  284. left=e.clientX;
  285. top=e.clientY;
  286. document.body.appendChild(bigImg);
  287. setTimeout(()=>{
  288. bigImg.style.opacity=1;
  289. },0);
  290. relocBigImg(left, top);
  291. getImgWH(bigImg,function(w,h){
  292. relocBigImg(left, top, w, h);
  293. });
  294. bigImg.onload=function(){
  295. relocBigImg(left, top);
  296. };
  297. });
  298. $("body").on("mouseout","img",e=>{
  299. if(isMobile)return;
  300. if(bigImg.parentNode){
  301. bigImg.style.opacity=0;
  302. bigImg.parentNode.removeChild(bigImg);
  303. }
  304. bigImg.removeAttribute("height");
  305. bigImg.removeAttribute("width");
  306. });
  307. $("body").on("mousemove","img",e=>{
  308. if(isMobile)return;
  309. left=e.clientX;
  310. top=e.clientY;
  311. if(!bigImg.src || bigImg.src===""){
  312. img.onmouseover(e);
  313. }
  314. relocBigImg(left, top);
  315. });
  316. /*for(i=0;i<imgs.length;i++){
  317. let img=imgs[i];
  318. img.onmouseover=function(e){
  319. src=img.src.replace(/\b(!(custom|square))\b/,"").replace(/\b(custom|square)\b/,"medium").replace(/\.sinaimg\.cn\/thumb\d+/,".sinaimg.cn/large");
  320. src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://");
  321. bigImg.src=img.src;
  322. bigImg.src=src;
  323. left=e.clientX;
  324. top=e.clientY;
  325. document.body.appendChild(bigImg);
  326. setTimeout(()=>{
  327. bigImg.style.opacity=1;
  328. },500);
  329. relocBigImg(left, top);
  330. getImgWH(bigImg,function(w,h){
  331. relocBigImg(left, top, w, h);
  332. });
  333. bigImg.onload=function(){
  334. relocBigImg(left, top);
  335. };
  336. };
  337. img.onmouseout=function(e){
  338. if(bigImg.parentNode){
  339. bigImg.style.opacity=0;
  340. bigImg.parentNode.removeChild(bigImg);
  341. }
  342. bigImg.removeAttribute("height");
  343. bigImg.removeAttribute("width");
  344. };
  345. img.onmousemove=function(e){
  346. left=e.clientX;
  347. top=e.clientY;
  348. if(!bigImg.src || bigImg.src===""){
  349. img.onmouseover(e);
  350. }
  351. relocBigImg(left, top);
  352. };
  353. }*/
  354. $("body").on("mouseover","div.gif-mask",function(e){
  355. if(isMobile)return;
  356. src=this.previousSibling.getAttribute("org_src").replace(/\b(!(custom|square))\b/,"").replace(/\b(custom|square)\b/,"medium").replace(/\.sinaimg\.cn\/(mw600|thumb\d+)/,".sinaimg.cn/large");
  357. src=isHttps?src.replace(/http\:\/\//,"https://"):src.replace(/https\:\/\//,"http://");
  358. bigImg.src=this.previousSibling.src;
  359. bigImg.src=src;
  360. document.body.appendChild(bigImg);
  361. setTimeout(()=>{
  362. bigImg.style.opacity=1;
  363. },0);
  364. getImgWH(bigImg,function(w,h){
  365. relocBigImg(left, top, w, h);
  366. });
  367. bigImg.onload=function(){
  368. relocBigImg(left, top);
  369. };
  370. });
  371. $("body").on("mouseout","div.gif-mask",function(e){
  372. if(isMobile)return;
  373. if(bigImg.parentNode){
  374. bigImg.style.opacity=0;
  375. bigImg.parentNode.removeChild(bigImg);
  376. }
  377. bigImg.removeAttribute("height");
  378. bigImg.removeAttribute("width");
  379. });
  380. $("body").on("mousemove","div.gif-mask",function(e){
  381. if(isMobile)return;
  382. if(e){
  383. left=e.clientX;
  384. top=e.clientY;
  385. }
  386. if(!bigImg.src || bigImg.src===""){
  387. this.onmouseover(e);
  388. }
  389. relocBigImg(left, top);
  390. });
  391. function relocBigImg(left, top, w, h){
  392. var imgWidth=w?w:bigImg.width;
  393. var imgHeight=h?h:bigImg.height;
  394. var type=imgHeight/imgWidth>document.documentElement.clientHeight/document.documentElement.clientWidth;
  395. if(type && imgHeight>document.documentElement.clientHeight){
  396. imgHeight=bigImg.height=document.documentElement.clientHeight;
  397. }
  398. if(!type && imgWidth>document.documentElement.clientWidth){
  399. imgWidth=bigImg.width=document.documentElement.clientWidth;
  400. }
  401. if(top-imgHeight<0){
  402. top=0;
  403. }else{
  404. top-=imgHeight;
  405. }
  406. if(left>document.documentElement.clientWidth/2){
  407. if(left+imgWidth>document.documentElement.clientWidth){
  408. left=document.documentElement.clientWidth-imgWidth;
  409. }
  410. left+=10;
  411. }else{
  412. left=left-imgWidth;
  413. if(left<0){
  414. left=0;
  415. }else left-=10;
  416. }
  417. bigImg.style.left=left+"px";
  418. bigImg.style.top=top+"px";
  419. }
  420. GM_addStyle(`
  421. .row.hide,.tucao-row.hide{
  422. opacity: 0.1;
  423. }
  424. .row.hide div.text,.tucao-row.hide .tucao-content,.tucao-row.hide .tucao-image,li.hide>.commenttext{
  425. display: none;
  426. }
  427. .row.hide:hover,.tucao-row.hide:hover{
  428. opacity: 0.5;
  429. }
  430. .tucao-author-bar #changeBtn{
  431. padding: 0 10px;
  432. }
  433. #changeBtn{
  434. display: none;
  435. }
  436. .big_img{
  437. pointer-events: none;
  438. position: fixed;
  439. z-index: 999;
  440. opacity: 0;
  441. transition: opacity .5s ease-in-out;
  442. -moz-transition: opacity .5s ease-in-out;
  443. -o-transition: opacity .5s ease-in-out;
  444. -webkit-transition: opacity .5s ease-in-out;
  445. }
  446. `);
  447. })();