9gag_already_seen

display "already seen"-status of posts

目前为 2021-08-19 提交的版本。查看 最新版本

// ==UserScript==
// @name         9gag_already_seen
// @namespace    https://gf.qytechs.cn/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++;
    }});

QingJ © 2025

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