Pixiv unread mark

rt

目前為 2015-09-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Pixiv unread mark
// @namespace    https://www.topcl.net/
// @version      0.2
// @description  rt
// @author       VJ
// @match        http://www.pixiv.net/*
// @grant        none
// ==/UserScript==

var PNN_LOCAL_STORE_KEY="PNN_STORE";

function checkWatched(pid,stor){
    var isnew=false;

    var sjson=localStorage[PNN_LOCAL_STORE_KEY];
    if(sjson){
        var arr=JSON.parse(sjson);
        isnew = arr.indexOf(pid)==-1;
        if(isnew && stor){
            arr.push(pid);
            localStorage[PNN_LOCAL_STORE_KEY]=JSON.stringify(arr);
        }
    }else{
        isnew=true;
        if(stor) {
            localStorage[PNN_LOCAL_STORE_KEY]=JSON.stringify([pid]);
        }
    }

    return !isnew;
}

function showNews()
{
    $("#search-result div ul li").each(function(el){
        var agrid= $(this);
        var awurl="http://www.pixiv.net/member_illust.php?id=" + agrid.find("a").attr("href").match('\\d+');

        var abadg=$('<a class="count-badge" href="'+awurl+'" style="position:absolute;top:60px;right:0;margin-right:130px">...</a>');
        agrid.find(".usericon").append(abadg);

        $.get(awurl,function(r){

            var news=0;

            var pagepids=$.unique(
                $(r).find(".image-item a")            
                .map(function(){
                    return this.href.match('\\d+')[0];
                }) 
            );

            $(pagepids).each(function(idx,elm){
                if(!checkWatched(elm))news++;
            });

            abadg.html(news);

            if(news==0) abadg.hide();                

        },"html");
    });
}

function procPage()
{

    var unseens=0;
    var pidns=[];
    var badgens=[];
    $(".image-item").each(function(){

        var pid=$(this).find("a")      .attr('href').match('\\d+')[0];
        if(!checkWatched(pid))
        {
            var badg=$('<span style="position: absolute; left:0;top:0; border-radius: 100%; width: 7px; height: 7px; background-color: red;"></span>');
            $(this).append(badg);
            badgens.push(badg);
            pidns.push(pid);
            unseens++;
        }
    });

    if(unseens!=0)
    {       
        $("<button class='count-badge' style='margin-left:15px'>Clear unread</button>").insertAfter("span.count-badge").click(function(){
            $(pidns).each(function(){
                checkWatched(this,true);
            });
            $(badgens).each(function(){
                this.remove();
            });
            this.remove();
        });
    }
}

$(function(){
    if(window.location.href.indexOf("http://www.pixiv.net/bookmark.php")==0) showNews();
    if(window.location.href.indexOf("http://www.pixiv.net/member_illust.php")==0) procPage();
});