v2ex unread

add unread mark for **visited** post of v2ex.com

  1. // ==UserScript==
  2. // @name v2ex unread
  3. // @name:zh-CN v2ex 标记未读 新回复
  4. // @namespace https://github.com/axipo/v2exUnread
  5. // @version 0.3
  6. // @description add unread mark for **visited** post of v2ex.com
  7. // @description:zh-CN 给v2ex增加未读标记的油猴脚本
  8. // @author axipo
  9. // @match https://*.v2ex.com/*
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. if(location.pathname === '/' || location.pathname === '/my/topics'){
  17. // read visit log
  18. let containers = document.querySelectorAll("#Main .topic_info");
  19. containers = Array.prototype.slice.apply(containers);
  20. let links = document.querySelectorAll("#Main .topic-link");
  21. links = Array.prototype.slice.apply(links);
  22. let replies = links.map(link => /#reply(\d+)/.exec(link.href)[1]);
  23. let postIds = links.map(link => /\/t\/([0-9]+)/.exec(link.href)[1]);
  24. containers.forEach((container, index) => {
  25. if(!replies[index]){
  26. return
  27. }
  28. let oldReply = localStorage.getItem('post' + postIds[index])
  29. oldReply = parseInt(oldReply ? oldReply : 0)
  30. if(!oldReply){
  31. return
  32. }
  33. let recentReply = replies[index] - oldReply
  34. if(!recentReply){
  35. return
  36. }
  37. let span = document.createElement('span')
  38. span.innerText = recentReply + ' new'
  39. span.style = `
  40. margin: 0 0.5rem;
  41. color: white;
  42. background-color: #f56c6c;
  43. padding: 0px 6px;
  44. border-radius: 6px / 50%;
  45. font-weight: bold;
  46. `
  47. container.appendChild(span)
  48. })
  49. return
  50. }
  51.  
  52. var regRes = /\/t\/([0-9]+)$/.exec(location.pathname);
  53.  
  54.  
  55. if(regRes){
  56. let postId = regRes[1]
  57. let text = document.querySelector("#Main > .box:nth-child(4) > .cell:nth-child(1)").innerText;
  58. let recentReply = /(\d+) 条回复/.exec(text)[1];
  59. localStorage.setItem('post' + postId, recentReply);
  60. }
  61. })();

QingJ © 2025

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