9gag_already_seen

display "already seen"-status of posts

  1. // ==UserScript==
  2. // @name 9gag_already_seen
  3. // @namespace https://gf.qytechs.cn/de/users/157797-lual
  4. // @version 0.7
  5. // @description display "already seen"-status of posts
  6. // @author lual
  7. // @match https://9gag.com/*
  8. // @icon https://icons.duckduckgo.com/ip2/9gag.com.ico
  9. // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
  10. // @grant GM_registerMenuCommand
  11. // ==/UserScript==
  12. ////////////////////////////////////////////////////////////////////////////////
  13. // changes: 2021-08-19 publish beta-version on greasyfork
  14.  
  15. ////////////////////////////////////////////////////////////////////////////////
  16. var SCRIPT_NAME = '9gag_already_seen';
  17. //add styles for seen and unseen articles
  18. function addGlobalStyle(css) {
  19. var head, style;
  20. head = document.getElementsByTagName('head')[0];
  21. if (!head) { return; }
  22. style = document.createElement('style');
  23. style.type = 'text/css';
  24. style.innerHTML = css;
  25. head.appendChild(style);
  26. }
  27. addGlobalStyle('.seen { border-left: 10px solid #0077ff !important; }');
  28. addGlobalStyle('.justseen { border-left: 10px solid #0077ff !important; transition: border-color 3s;}');
  29. addGlobalStyle('.unseen { border-left: 10px solid #007700 !important; }');
  30. addGlobalStyle('#seen-counter { position: fixed; color: #0077ff; padding-top: 0px; padding-left: 13px; right: 20px; top:50px; height: 36px; width: 100px; background-color:#AAAAAA; border-radius: 18px; font-size: 16px; font-weight: 700; line-height: 36px; opacity:70%}');
  31.  
  32. ////////////////////////////////////////////////////////////////////////////////
  33. //forget seen/unseen status
  34. GM_registerMenuCommand(SCRIPT_NAME + ': Forget seen status!', function() {
  35. localStorage.removeItem('article_ids');
  36. document.querySelectorAll('.seen').forEach(function(node) {
  37. node.classList.remove('seen');
  38. node.classList.add('unseen');
  39. });
  40. document.querySelectorAll('.justseen').forEach(function(node) {
  41. node.classList.remove('justseen');
  42. node.classList.add('unseen');
  43. });
  44. });
  45.  
  46. //insert element for "seen articles"-count
  47. function insertCounter(cnt) {
  48. var parent, div;
  49. parent = document.getElementsByTagName('body')[0];
  50. if (!parent) { return; }
  51. div = document.createElement('div');
  52. div.id = 'seen-counter';
  53. div.innerHTML = '&#128065 ' + cnt;
  54. div.title = 'Userscript - ' + SCRIPT_NAME + ' - Counter'
  55. parent.appendChild(div);
  56. }
  57.  
  58. //update element for "seen articles"-count
  59. function updateCounter(cnt) {
  60. var div;
  61. div = document.querySelector('#seen-counter');
  62. if (!div) { return; }
  63. div.innerHTML = '&#128065 '+ cnt;
  64. }
  65.  
  66. $(document).ready(function() {
  67. //insert element for "seen articles"-count
  68. var stored_seen_article_ids = [];
  69. if (localStorage.getItem('article_ids')) {
  70. stored_seen_article_ids = JSON.parse(localStorage.getItem('article_ids'));
  71. }
  72. insertCounter(stored_seen_article_ids.length);
  73.  
  74. //do a minimal scroll to mark articles...
  75. window.scrollTo(window.scrollX, window.scrollY + 1);
  76. });
  77.  
  78. ////////////////////////////////////////////////////////////////////////////////
  79. var i = 0;
  80. $(window).on('scroll',function(){
  81.  
  82. var stored_seen_article_ids = [];
  83. if (localStorage.getItem('article_ids')) {
  84. stored_seen_article_ids = JSON.parse(localStorage.getItem('article_ids'));
  85. }
  86.  
  87. //check if article is unseen / style it / and return bool
  88. function isArticleUnseen(article) {
  89. if(stored_seen_article_ids.indexOf(article.attr("id")) === -1){
  90. article.addClass('unseen');
  91. return true
  92. }
  93. else {
  94. article.addClass('seen');
  95. return false
  96. }
  97. };
  98.  
  99. var displayedArticles = $("article");
  100.  
  101. if (isArticleUnseen(displayedArticles.eq(i))){
  102. stored_seen_article_ids.push(displayedArticles.eq(i).attr("id"));
  103. };
  104. isArticleUnseen(displayedArticles.eq(i+1));
  105. isArticleUnseen(displayedArticles.eq(i+2));
  106. isArticleUnseen(displayedArticles.eq(i+3));
  107. isArticleUnseen(displayedArticles.eq(i+4));
  108. isArticleUnseen(displayedArticles.eq(i+5));
  109. isArticleUnseen(displayedArticles.eq(i+6));
  110.  
  111. //articel scrolled over top - mark it as seen
  112. if($(window).scrollTop() >= displayedArticles.eq(i).offset().top){
  113. updateCounter(stored_seen_article_ids.length);
  114.  
  115. localStorage.setItem("article_ids", JSON.stringify(stored_seen_article_ids));
  116. if (displayedArticles.eq(i).hasClass('unseen')) {
  117. displayedArticles.eq(i).removeClass('unseen');
  118. displayedArticles.eq(i).addClass('justseen');
  119. };
  120. i++;
  121. }});

QingJ © 2025

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