V2ex User Experience Enhance

v2ex体验增强

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