v2ex 免跳转浏览 + 折叠回复少的页面

折叠回复少的页面;在 v2ex 主页面显示鼠标悬停内容

  1. // ==UserScript==
  2. // @name v2ex 免跳转浏览 + 折叠回复少的页面
  3. // @namespace ThomasKara
  4. // @run-at document-end
  5. // @match http*://v2ex.com
  6. // @match http*://*.v2ex.com
  7. // @version 0.1.3
  8. // @description 折叠回复少的页面;在 v2ex 主页面显示鼠标悬停内容
  9. // ==/UserScript==
  10. function insertAfter(newNode, existingNode) {
  11. existingNode.parentNode.insertBefore(newNode, existingNode.nextSibling);
  12. }
  13.  
  14. function getBox(){
  15. let box;
  16. if (location.pathname.startsWith("/go/")){
  17. box=Array.from(document.querySelectorAll("#Main .box")).slice(-1);
  18. } else {
  19. box=Array.from(document.querySelectorAll("#Main .box"));
  20. }
  21. return box[0];
  22. }
  23.  
  24. function getCells(box){
  25. let l=box.querySelectorAll("*>.cell")
  26. if (l.length){
  27. return l
  28. }
  29. l=box.querySelectorAll(".box #TopicsNode .cell.item")
  30. if (l.length){
  31. return l
  32. }
  33. return []
  34. }
  35.  
  36. // 折叠回复小于等于1的页面
  37. (function () {
  38. 'use strict';
  39. var box=getBox();
  40. var l=getCells(box);
  41. var less=[""];
  42.  
  43. if (l.length){
  44. for (var i=0;i<l.length;i++){
  45. var tr=l[i].querySelector("tr");
  46. if (!tr){
  47. continue;
  48. }
  49. if (tr.lastElementChild&&tr.lastElementChild.children.length>1){
  50. continue;
  51. }
  52. if (tr.lastElementChild.querySelector("a")&&parseInt(tr.lastElementChild.querySelector("a").innerText)>1){
  53. continue;
  54. }
  55. l[i].style="padding: 0 10px;overflow: hidden;height: 1.3rem;border: none;";
  56. l[i].querySelector(".item_title").style.fontSize=".9em";
  57. less.push(l[i]);
  58. }
  59. less[0]=less.length+" - "+Math.floor(100*(l.length-less.length)/l.length)+"% ("+(l.length-less.length)+"/"+l.length+")";
  60. box.append(...less);
  61.  
  62. console.log(less[0]);
  63. }
  64. })();
  65.  
  66. // 免跳转预览
  67. (function () {
  68. 'use strict';
  69. var box=getBox();
  70. var l=getCells(box);
  71. var ifrm=document.querySelector("iframe.fast-viewer");
  72. var blocker=document.querySelector("div.blocker");
  73.  
  74. if (l.length){
  75. document.querySelector("#Rightbar").style.display="none";
  76. if (!ifrm){
  77. ifrm=document.createElement("iframe");
  78. ifrm.classList.add("fast-viewer");
  79. ifrm.style="height: 80vh;border: 1px solid gray;z-index: 1;";
  80. blocker=document.createElement("div");
  81. blocker.classList.add("blocker");
  82. blocker.style="position: fixed; bottom: 0px; width: 100%;";
  83. blocker.title="this area is blocked to prevent falling, try to scroll up";
  84. }
  85. for (var i=0;i<l.length;i++){
  86. var a=l[i].querySelector(".item_title a");
  87. if (a){
  88. let current=l[i];
  89. let a=current.querySelector(".item_title a");
  90. a.onmouseenter=()=>{
  91. if (ifrm.src!=a.href){
  92. ifrm.src=a.href;
  93. let margin=40;
  94. ifrm.style.width=document.body.getBoundingClientRect().width-margin-10+"px";
  95. ifrm.style.marginLeft=(margin-current.getBoundingClientRect().x)+"px";
  96. insertAfter(ifrm, current);
  97. window.scrollTo(0, current.getBoundingClientRect().top + document.documentElement.scrollTop)
  98. ifrm.onload=()=>{
  99. let replyBox=ifrm.contentWindow.document.querySelector("#reply-box")
  100. if (replyBox){
  101. replyBox.style.display="none";
  102. }
  103. ifrm.contentWindow.document.querySelector("#Bottom").style.display="none";
  104. };
  105. blocker.style.height=window.innerHeight-ifrm.offsetHeight-current.offsetHeight+"px";
  106. insertAfter(blocker, ifrm);
  107. }
  108. };
  109. }
  110. }
  111. }
  112. })();

QingJ © 2025

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