Zhihu-K

知乎赞同数用K显示

  1. // ==UserScript==
  2. // @name Zhihu-K
  3. // @namespace https://gist.github.com/rain15z3/82f8d7a5d4778d969d92211c9dfe2fed
  4. // @version 1.0
  5. // @description 知乎赞同数用K显示
  6. // @author RainbowBird
  7. // @match https://www.zhihu.com/*
  8. // @grant none
  9. // @require http://code.jquery.com/jquery-1.11.0.min.js
  10. // ==/UserScript==
  11.  
  12. !(function () {
  13. setInterval(refrush, 3000);
  14. })();
  15.  
  16. function refrush() {
  17. console.log("[Zhihu-K] loading...");
  18. $(".Button.VoteButton.VoteButton--up").each(function () {
  19. var text = $(this).contents().eq(1).get(0).nodeValue;
  20.  
  21. text = text.replace(/\u200B/g, "");
  22. var rep = text.replace("赞同 ", "");
  23. if (text.match("万")) {
  24. rep = rep.replace(" 万", "");
  25. var num = parseFloat(rep) * 10000;
  26. } else {
  27. var num = parseFloat(rep);
  28. }
  29.  
  30. if (num >= 10000 || (num >= 1000 && num < 10000)) {
  31. var numk = num / 1000;
  32. if (numk.toString().match(".")) numk = numk.toFixed(1);
  33. text = "赞同 " + numk + " K";
  34. }
  35.  
  36. $(this).contents().eq(1).get(0).nodeValue = text;
  37. });
  38. }