知乎

统计知乎回答时间

  1. // ==UserScript==
  2. // @name 知乎
  3. // @namespace zgzhihu
  4. // @version 0.31
  5. // @description 统计知乎回答时间
  6. // @author You
  7. // @match *://www.zhihu.com/people/*
  8. // @match *://www.zhihu.com/question/*
  9. // @require https://cdn.bootcss.com/jquery/3.4.1/jquery.js
  10. // @run-at document-end
  11. // @grant unsafeWindow
  12. // @grant GM_setClipboard
  13. // ==/UserScript==
  14. (function() {
  15. 'use strict';
  16. function getDateStr(seconds){
  17. var date = new Date(seconds*1000)
  18. var year = date.getFullYear();
  19. var month = date.getMonth() + 1;
  20. var day = date.getDate();
  21. var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
  22. var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
  23. var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
  24. var currentTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
  25. return currentTime
  26. }
  27. function utc2beijing(utc_datetime) {
  28. // 转为正常的时间格式 年-月-日 时:分:秒
  29. var T_pos = utc_datetime.indexOf('T');
  30. var Z_pos = utc_datetime.indexOf('Z');
  31. var year_month_day = utc_datetime.substr(0,T_pos);
  32. var hour_minute_second = utc_datetime.substr(T_pos+1,Z_pos-T_pos-1);
  33. var new_datetime = year_month_day+" "+hour_minute_second;
  34. // 处理成为时间戳
  35. timestamp = new Date(Date.parse(new_datetime));
  36. timestamp = timestamp.getTime();
  37. timestamp = timestamp/1000;
  38. // 增加8个小时,北京时间比utc时间多八个时区
  39. var timestamp = timestamp+8*60*60;
  40. // 时间戳转为时间
  41. return getDateStr(timestamp);
  42. //var beijing_datetime = new Date(parseInt(timestamp) * 1000).toLocaleString().replace(/年|月/g, "-").replace(/日/g, " ");
  43. //return beijing_datetime;
  44. }
  45.  
  46. //个人主页回答
  47. function loadPeopleContent() {
  48. let checkLoadListTimer = setInterval(function(){
  49. if(!$('.PlaceHolder.List-item').length) {
  50. clearInterval(checkLoadListTimer);
  51. let tabType = location.href.includes('/answers');
  52. //1回答 0文章
  53. $(".List-item").each(function() {
  54. let createdTime = utc2beijing($(this).find("meta[itemprop="+(tabType ? "dateCreated" : "datePublished")+"]").eq(0).attr('content'));
  55. let content = "<span style='color:#f00;font-weight:900'>"+createdTime+"</span>"
  56. $(this).find(".AuthorInfo."+(tabType?"AnswerItem":"ArticleItem")+"-authorInfo").append(content);
  57. });
  58. }
  59. },200);
  60. }
  61. //翻页
  62. $('body').on('click', ".Pagination button", function(event) {
  63. loadPeopleContent();
  64. });
  65.  
  66. //tab点击
  67. $('body').on('click', '.Tabs.ProfileMain-tabs li[aria-controls="Profile-answers"]', function(event) {
  68. loadPeopleContent();
  69. });
  70. $('body').on('click', '.Tabs.ProfileMain-tabs li[aria-controls="Profile-posts"]', function(event) {
  71. loadPeopleContent();
  72. });
  73. //排序
  74. $('body').on('click', ".Select-list button", function(event) {
  75. loadPeopleContent();
  76. });
  77. if(location.href.match(/www.zhihu.com\/people\/.+\/answers/) || location.href.match(/www.zhihu.com\/people\/.+\/posts/)) {
  78. loadPeopleContent();
  79. }
  80.  
  81.  
  82.  
  83. //问题回答列表自动跳转到该回答底部
  84. setInterval(function(){
  85. let toAnswerBottomEle = $(".toAnswer-bottom");
  86. if(toAnswerBottomEle.parents(".is-fixed").length) {
  87. return;
  88. }else {
  89. toAnswerBottomEle.remove();
  90. $(".ContentItem-actions.Sticky.RichContent-actions.is-fixed.is-bottom Button.ContentItem-action.ContentItem-rightButton.Button--plain").before("<button class='toAnswer-bottom Button ContentItem-action Button--plain'>直达底部</button>");
  91. }
  92. }, 1000);
  93.  
  94. $("#root").on("click", ".toAnswer-bottom", function() {
  95. let scrollEle = $(this).parents(".ContentItem.AnswerItem").find(".ContentItem-time");
  96. if(scrollEle&&scrollEle.length) {
  97. let offsetTop = scrollEle.offset().top - 0.8*document.documentElement.clientHeight;
  98. $('body,html').animate({scrollTop: offsetTop}, 50);
  99. }
  100. })
  101.  
  102.  
  103.  
  104. })();

QingJ © 2025

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