Chrono-reader

Chronological tag notification reader for wykop.pl

当前为 2017-04-07 提交的版本,查看 最新版本

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

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

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

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

您需要先安装一款用户脚本管理器扩展,例如 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);
    }
});