V2ex User Experience Enhance

v2ex体验增强2020版

  1. // ==UserScript==
  2. // @name V2ex User Experience Enhance
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.53
  5. // @description v2ex体验增强2020版
  6. // @author xingis
  7. // @match https://www.v2ex.com/*
  8. // @include http*://*.v2ex.com/*
  9. // @include http*://v2ex.com/*
  10. // @grant none
  11. // @locale zh-CN
  12. // ==/UserScript==
  13.  
  14.  
  15. (function() {
  16. //<editor-fold desc="增加bing, baidu搜索">
  17. // from xingis@v2ex
  18. var box = "<div id='search-result_diy' class='box' style='position: absolute;background-color: var(--box-background-color);top: 36px;left:105%;width: 100%;z-index:99'></div>";
  19. $("#search").after(box);
  20. $("#search").on("input propertychange",function(){
  21. console.log($(this).val().length);
  22. if($(this).val().length > 0) {
  23. var $keyword = "<div class='search-item-group cell active'><a class='search-item active' href='https://www4.bing.com/search?q=site%3Av2ex.com+" + $(this).val() + "' target='_blank'>Bing " + $(this).val() + "</a></div>";
  24. $keyword += "<div class='search-item-group cell active'><a class='search-item active' href='https://www.baidu.com/s?wd=site%3Av2ex.com+" + $(this).val() + "' target='_blank'>Baidu " + $(this).val() + "</a></div>";
  25. $("#search-result_diy").show().html($keyword);
  26. } else {
  27. $("#search-result_diy").hide();
  28. }
  29. });
  30. //</editor-fold>
  31.  
  32. //以下代码来自zjsxwc
  33. //<editor-fold desc="尝试滚到回复,但由于感谢等也算回复,可能不会起效">
  34. var isFromHomepage = (document.referrer == "https://www.v2ex.com/")||(document.referrer == "https://v2ex.com/");
  35. (!isFromHomepage) && (function(){
  36. var replyNo = null;
  37. var replyMatches = window.location.hash.match(/#reply(\d+)/);
  38. if (replyMatches) {
  39. replyNo = replyMatches[1];
  40. }
  41. if (replyNo) {
  42. var targetReplyEle = null;
  43. $(".no").each(function(_,e){
  44. var eHtml = $(e).html();
  45. if (eHtml != replyNo) {
  46. return;
  47. }
  48. targetReplyEle = e;
  49. });
  50. $('html, body').animate({
  51. scrollTop: $(targetReplyEle).offset().top
  52. }, 666);
  53. }
  54. }());
  55. //</editor-fold>
  56.  
  57. //<editor-fold desc="每日签到">
  58. function in_array(search,array){
  59. for(var i in array){
  60. if(array[i]==search){
  61. return true;
  62. }
  63. }
  64. return false;
  65. }
  66. var currentPathName = window.location.pathname;
  67. var ignorePathNameList = [
  68. "/signin", "/forgot", "/signup"
  69. ];
  70. if (!in_array(currentPathName, ignorePathNameList)) {
  71. $.get("/mission/daily",function(r){
  72. var m = r.match(/mission\/daily\/redeem\?once=(\w{5})/);
  73. if (!m) {
  74. return;
  75. }
  76. var code = m[1];
  77. var url = "/mission/daily/redeem?once="+code;
  78. $.get(url);
  79. });
  80. }
  81. //</editor-fold>
  82.  
  83.  
  84. //<editor-fold desc="查看被at人的帖子">
  85. var isInThread = !!window.location.href.match(/\/t\/\d+/);
  86. if (isInThread) {
  87. var $goBottomBtn = $('<a href="#;" class="tb" onclick="$(\'html, body\').animate({scrollTop: 100000}, 1000);">到底部</a>');
  88. $('.topic_buttons').append($goBottomBtn);
  89.  
  90. var getReplyContentByNickname = function(nickname) {
  91. var replyContents = [];
  92. $("strong a").each(function(i,e){
  93. var $el = $(e);
  94. var text =$el.text();
  95. if (text.lastIndexOf(nickname) == 0) {
  96. var $parent = $el.closest("td");
  97. var $content = $parent.find(".reply_content");
  98. var $no = $parent.find(".no");
  99. replyContents.push({
  100. no: $no.text(),
  101. content: $content.text()
  102. });
  103. }
  104. });
  105. return replyContents;
  106. };
  107. $(".reply_content a").each(function(_,e){
  108. var $mayAtMan = $(e);
  109. var $parent = $mayAtMan.parent();
  110. var parentText = $parent.text();
  111. var mayNickname = $mayAtMan.text();
  112. var mayAtManText = "@"+mayNickname;
  113. if (parentText.lastIndexOf(mayAtManText) !== -1) {
  114. $mayAtMan.mouseover(function(){
  115. var replyContents = getReplyContentByNickname(mayNickname);
  116. var $allAtManReply = $("body").find(".js-at-man-reply");
  117. if ($allAtManReply) {
  118. $allAtManReply.remove();
  119. }
  120. var html = "";
  121. $.each(replyContents,function(_,replyContent){
  122. html += "<p>"+"#"+replyContent.no+" "+replyContent.content+"</p><br>";
  123. });
  124. html = "<div class='js-at-man-reply'><h2>"+mayNickname+":</h2><br>"+html+"</div>";
  125. $mayAtMan.parent().append($(html));
  126. });
  127. }
  128. });
  129. }
  130. //</editor-fold>
  131.  
  132.  
  133.  
  134. //标记楼主 代码来自ejin
  135. uid=document.getElementById("Rightbar").getElementsByTagName("a")[0].href.split("/member/")[1];//自己用户名
  136. if (location.href.indexOf(".com/t/") != -1) {
  137. var lzname=document.getElementById("Main").getElementsByClassName("avatar")[0].parentNode.href.split("/member/")[1];
  138. allname='@'+lzname+' ';
  139. all_elem = document.getElementsByClassName("dark");
  140. for(var i=0; i<all_elem.length; i++) {
  141. if (all_elem[i].innerHTML == lzname){
  142. all_elem[i].innerHTML += " <font color=green>[楼主]</font>";
  143. }
  144. //为回复所有人做准备
  145. if ( uid != all_elem[i].innerHTML && all_elem[i].href.indexOf("/member/") != -1 && all_elem[i].innerText == all_elem[i].innerHTML && allname.indexOf('@'+all_elem[i].innerHTML+' ') == -1 ) {
  146. allname+='@'+ all_elem[i].innerHTML+' ';
  147. }
  148. }
  149. }
  150.  
  151. // @所有人 与 @管理员 代码来自ejin
  152. if ( document.getElementById("reply_content") ) {
  153. document.getElementById("reply_content").parentNode.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='if ( document.getElementById(\"reply_content\").value.indexOf(\""+allname+"\") == -1 ) {document.getElementById(\"reply_content\").value+=\"\\r\\n"+allname+"\"}'>@所有人</a>";
  154. if ( document.body.style.WebkitBoxShadow !== undefined ) {
  155. //允许调整回复框高度
  156. document.getElementById("reply_content").style.resize="vertical";
  157. }
  158. document.getElementById("reply_content").style.overflow="auto";
  159. var magagers="@Livid @Kai @Olivia @GordianZ @sparanoid";
  160. document.getElementById("reply_content").parentNode.innerHTML+="&nbsp;&nbsp;&nbsp;&nbsp;<a href='javascript:;' onclick='if ( document.getElementById(\"reply_content\").value.indexOf(\""+magagers+"\") == -1 ) {document.getElementById(\"reply_content\").value+=\"\\r\\n"+magagers+"\"}'>@管理员</a>";
  161. }
  162.  
  163.  
  164. // 图片链接自动转换成图片 代码来自caoyue@v2ex
  165. function linksToImgs() {
  166. var links = document.links;
  167. for (x in links){
  168. var link = links[x];
  169. if (/^http.*\.(?:jpg|jpeg|jpe|bmp|png|gif)/i.test(link.href)
  170. && !/<img\s/i.test(link.innerHTML)){
  171. link.innerHTML = "<img title='" + link.href + "' src='" + link.href + "' />";
  172. }
  173. }
  174. }
  175. linksToImgs();
  176. })();

QingJ © 2025

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