Greasy Fork is available in English.

Pixiv unread mark

rt

  1. // ==UserScript==
  2. // @name Pixiv unread mark
  3. // @namespace https://www.topcl.net/
  4. // @version 0.21
  5. // @description rt
  6. // @author VJ
  7. // @match http://www.pixiv.net/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. var PNN_LOCAL_STORE_KEY="PNN_STORE";
  12.  
  13. function checkWatched(pid,stor){
  14. var isnew=false;
  15.  
  16. var sjson=localStorage[PNN_LOCAL_STORE_KEY];
  17. if(sjson){
  18. var arr=JSON.parse(sjson);
  19. isnew = arr.indexOf(pid)==-1;
  20. if(isnew && stor){
  21. arr.push(pid);
  22. localStorage[PNN_LOCAL_STORE_KEY]=JSON.stringify(arr);
  23. }
  24. }else{
  25. isnew=true;
  26. if(stor) {
  27. localStorage[PNN_LOCAL_STORE_KEY]=JSON.stringify([pid]);
  28. }
  29. }
  30.  
  31. return !isnew;
  32. }
  33.  
  34. function showNews()
  35. {
  36. $("#search-result div ul li").each(function(el){
  37. var agrid= $(this);
  38. var awurl="http://www.pixiv.net/member_illust.php?id=" + agrid.find("a").attr("href").match('\\d+');
  39.  
  40. var abadg=$('<a class="count-badge" href="'+awurl+'" style="position:absolute;top:-5px;right:25px;margin-right:130px">...</a>');
  41. agrid.find(".usericon").append(abadg);
  42.  
  43. $.get(awurl,function(r){
  44.  
  45. var news=0;
  46.  
  47. var pagepids=$.unique(
  48. $(r).find(".image-item a")
  49. .map(function(){
  50. return this.href.match('\\d+')[0];
  51. })
  52. );
  53.  
  54. $(pagepids).each(function(idx,elm){
  55. if(!checkWatched(elm))news++;
  56. });
  57.  
  58. abadg.html(news);
  59.  
  60. if(news==0) abadg.hide();
  61.  
  62. },"html");
  63. });
  64. }
  65.  
  66. function procPage()
  67. {
  68.  
  69. var unseens=0;
  70. var pidns=[];
  71. var badgens=[];
  72. $(".image-item").each(function(){
  73.  
  74. var pid=$(this).find("a") .attr('href').match('\\d+')[0];
  75. if(!checkWatched(pid))
  76. {
  77. var badg=$('<span style="position: absolute; left:0;top:0; border-radius: 100%; width: 7px; height: 7px; background-color: red;"></span>');
  78. $(this).append(badg);
  79. badgens.push(badg);
  80. pidns.push(pid);
  81. unseens++;
  82. }
  83. });
  84.  
  85. if(unseens!=0)
  86. {
  87. $("<button class='count-badge' style='margin-left:15px'>Clear unread</button>").insertAfter("span.count-badge").click(function(){
  88. $(pidns).each(function(){
  89. checkWatched(this,true);
  90. });
  91. $(badgens).each(function(){
  92. this.remove();
  93. });
  94. this.remove();
  95. });
  96. }
  97. }
  98.  
  99. $(function(){
  100. if(window.location.href.indexOf("http://www.pixiv.net/bookmark.php")==0) showNews();
  101. if(window.location.href.indexOf("http://www.pixiv.net/member_illust.php")==0) procPage();
  102. });
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.