V2EX_Reply

显示被@的用户本楼发言记录。

  1. // ==UserScript==
  2. // @id caoyue@v2ex
  3. // @name V2EX_Reply
  4. // @version 1.6.2
  5. // @namespace 49b569dc5aaa522ad7e0e617b7cc5d44
  6. // @author caoyue
  7. // @description 显示被@的用户本楼发言记录。
  8. // @match https://*.v2ex.com/t/*
  9. // @match https://v2ex.com/t/*
  10. // ==/UserScript==
  11.  
  12. // Author: caoyue
  13. // Created: 2012-04-11
  14. // Version: 1.6
  15. // Updated: 2013-02-05
  16.  
  17.  
  18. var REPLY_TYPE = 1; //TODO:评论显示方式.
  19. var REPLY_COUNT = 2; //只显示最靠近的两条评论
  20. var MAX_LENGTH = 120; //引用评论超过长度则截断
  21. var HIDE_TOPIC_CONTENT = true; //翻页后隐藏主题内容
  22. var REDIRECT = 0; //
  23.  
  24. (function (){
  25. if(REDIRECT && location.host == "www.v2ex.com"){
  26. location.href = location.href.replace(/www./, '');
  27. }
  28. })();
  29.  
  30. document.addEventListener('mouseover',function(e){
  31. var link = e.target;
  32. if(link.nodeName.toLowerCase()=='a'){
  33. var authorLink = getAuthor(link);
  34. if (authorLink.innerHTML != undefined) {
  35. var originID = authorLink.parentNode.parentNode.getElementsByClassName("no")[0].innerHTML;
  36. var authorName = authorLink.innerHTML;
  37.  
  38. var contentArray = getContent(originID,authorName);
  39. var content = "<strong>" + authorName + ":</strong><br />";
  40.  
  41. if (contentArray.length > REPLY_COUNT) {
  42. for (var i = 0; i < REPLY_COUNT; i ++ ) {
  43. content = content + "<p style='padding-bottom:5px;border-bottom:1px solid rgb(226, 226, 226);'>" + contentArray[contentArray.length - REPLY_COUNT + i] + "</p>";
  44. }
  45. }
  46. else{
  47. for (var x in contentArray){
  48. content = content + "<p style='padding-bottom:5px;border-bottom:1px solid rgb(226, 226, 226);'>" + contentArray[x] + "</p>";
  49. }
  50. }
  51.  
  52. var layer = creatDiv(content);
  53. layer.style.display = 'block';
  54. layer.style.left = e.pageX - 60 + "px";
  55. layer.style.top = e.pageY - layer.offsetHeight - 15 + "px";
  56. }
  57. }
  58. });
  59.  
  60. document.addEventListener('mouseout',function(e){
  61. if (document.getElementById("ReplyToolTip") != null) {
  62. document.getElementById("ReplyToolTip").style.display = "none";
  63. }
  64. });
  65.  
  66.  
  67. function getAuthor(link){
  68. var authorLink = "none";
  69. var rex = /\/member\//;
  70. if (rex.test(link) && link.className != "dark") {
  71. authorLink = link;
  72. }
  73. return authorLink;
  74. }
  75.  
  76. function getContent(originID,authorName){
  77. var contentArray = new Array(),x;
  78. var replys = document.getElementById("Main").getElementsByClassName("reply_content");
  79. for (x in replys) {
  80. var reply = replys[x];
  81. if (reply.parentNode != undefined) {
  82. var replyID = reply.parentNode.getElementsByClassName("no")[0].innerHTML;
  83. //GM_log("replyID is " + replyID + " and originID is " + originID);
  84. var replyAuthor = reply.parentNode.getElementsByClassName("dark")[0].innerHTML;
  85. if (parseInt(replyID) < parseInt(originID) && replyAuthor == authorName) {
  86. if (reply.innerHTML != "") {
  87. if (reply.innerHTML.length > MAX_LENGTH) {
  88. contentArray.push(reply.innerHTML.substring(0,MAX_LENGTH) + "<br /><span style='color:gray;'> ……</span>" );
  89. }
  90. else
  91. contentArray.push(reply.innerHTML);
  92. }
  93. }
  94. }
  95. }
  96. return contentArray;
  97. }
  98.  
  99. function creatDiv(content){
  100. var layer = document.getElementById("ReplyToolTip");
  101. if (layer != null) {
  102. layer.innerHTML = content;
  103. }
  104. else{
  105. layer = document.createElement("div");
  106. document.body.appendChild(layer);
  107. layer.setAttribute("id","ReplyToolTip");
  108. layer.setAttribute("style","font-size:14px;background-color:rgba(255,255,255,0.9);box-shadow:0 0 10px rgba(0, 0, 0, 0.8);max-width:550px;max-height:500px;padding:6px 10px;position:absolute;")
  109. layer.innerHTML = content;
  110. }
  111. return layer;
  112. }
  113.  
  114. // 翻页后隐藏主题内容
  115. if(HIDE_TOPIC_CONTENT && window.location.href.indexOf("?p=") >0 && window.location.href.indexOf("?p=1") == -1){
  116. document.getElementsByClassName("topic_content")[0].setAttribute("style","display:none;");
  117. }