Chrono-reader

Chronological tag notification reader for wykop.pl

目前為 2017-04-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Chrono-reader
// @namespace    https://github.com/piomar123/
// @version      0.8
// @description  Chronological tag notification reader for wykop.pl
// @author       piomar123
// @match        http://www.wykop.pl/*
// @grant        none
// ==/UserScript==
// Badge bullet style by krejdd

$('div#nav ul.clearfix:last > li.notification.m-tag').last().before($('<li/>', {
    id: 'firstTag',
    html: '<a id="firstTagButton" class="dropdown-show hashtag" href="#"><b id="firstTagBullet" style="background:#0080FF; top:22px; right:16px; min-width:10px; width:10px; min-height:10px; height:10px; border-radius:5px; overflow:hidden;">&nbsp;</b>#</a><div class="notificationsContainer"></div>',
    class: "notification m-tag piomar-firsttag",
    title: "Najstarszy nieprzeczytany tag",
    alt: "Najstarszy nieprzeczytany tag"
}));

$("#firstTagButton").click(function(event){
    event.preventDefault();
    var tagiURL = "http://www.wykop.pl/powiadomienia/tagi/";
    var notificationSelector = '#content ul.menu-list li.type-light-warning a[href*="pl/wpis/"]';
	var emptyPageAlertSelector = "#content ul.menu-list li.type-alert p.empty";
    var lastPage = 3;
    var unreadCount = 0;
    var notifications = [];
    var currentTotal = 0;
    var oldestUrl = null;
    $.ajax(tagiURL)
        .done(firstPageDownloaded)
        .fail(handleFail);

    function firstPageDownloaded(html){
        unreadCount = Number($('#hashtagsNotificationsCount', html).html());
        notifications = $(notificationSelector, html);
        currentTotal = notifications.length;
        oldestUrl = notifications.last().attr("href");
        if(currentTotal < unreadCount){
            downloadPage(2);
            return;
        }
        if(unreadCount === 0){
            alert("Wszystko przeczytane");
            return;
        }
        if(!oldestUrl){
            alert("Nie znalazłem nowszych wpisów");
            return;
        }
        window.location.href = oldestUrl;
    }

    function downloadPage(page){
        $.ajax(tagiURL + "strona/" + page + "/")
            .done(nextPageDownloaded(page))
            .fail(handleFail);
    }

    function nextPageDownloaded(page){
        return function(html){
            //unreadCount = Number($('#hashtagsNotificationsCount', html).html());
            notifications = $(notificationSelector, html);
            // possible race condition
			currentTotal += notifications.length;
            if(page < lastPage && currentTotal < unreadCount){
                downloadPage(page+1);
                return;
            }
            oldestUrl = notifications.last().attr("href") || oldestUrl;
            if(!oldestUrl){
                alert("Nie znalazłem nowszych wpisów");
                return;
            }
            window.location.href = oldestUrl;
        };
    }

    function handleFail(jqXHR, textStatus, err){
        alert(textStatus + ": " + err);
    }
});