9gag_already_seen

display "already seen"-status of posts

当前为 2021-08-19 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         9gag_already_seen
// @namespace    https://greasyfork.org/de/users/157797-lual
// @version      0.2
// @description  display "already seen"-status of posts
// @author       lual
// @match        https://9gag.com/*
// @icon         https://icons.duckduckgo.com/ip2/9gag.com.ico
// @require      https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// @grant        GM_registerMenuCommand
// ==/UserScript==
////////////////////////////////////////////////////////////////////////////////
// changes:        2021-08-19 publish beta-version on greasyfork

////////////////////////////////////////////////////////////////////////////////
//add styles for seen and unseen articles
function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}
addGlobalStyle('.seen   { border-left: 10px solid rgb(0, 0, 255) !important; }');
addGlobalStyle('.unseen { border-left: 10px solid rgb(0, 255, 0) !important; }');

////////////////////////////////////////////////////////////////////////////////
//forget seen/unseen status
var SCRIPT_NAME = '9gag_seen_or_new';
GM_registerMenuCommand(SCRIPT_NAME + ': Forget seen status!', function() {
    localStorage.removeItem('article_ids');
    document.querySelectorAll('.seen').forEach(function(node) {
        node.classList.remove('seen');
        node.classList.add('unseen');
    });
});
////////////////////////////////////////////////////////////////////////////////
var i = 0;
$(window).on('scroll',function(){
    var article_ids = [];
    if (localStorage.getItem('article_ids')) {
        article_ids = JSON.parse(localStorage.getItem('article_ids'));
    }
    var displayedArticle = $("article");
    var articles_i_ids = displayedArticle.eq(i).attr("id");
    if(article_ids.indexOf(articles_i_ids) === -1 && !displayedArticle.eq(i).hasClass('seen')){
        article_ids.push(articles_i_ids);
        displayedArticle.eq(i).addClass('unseen');
    }
    else {
        displayedArticle.eq(i).addClass('seen');
    }

    if($(window).scrollTop() >= displayedArticle.eq(i).offset().top){
        localStorage.setItem("article_ids", JSON.stringify(article_ids));
        displayedArticle.eq(i).removeClass('unseen');
        displayedArticle.eq(i).addClass('seen');
        i++;
    }});