FP Auto Update

w/e

Verze ze dne 10. 09. 2015. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

	

    // ==UserScript==
    // @name        FP Auto Update
    // @namespace   123
    // @description w/e
    // @include     https://facepunch.com/showthread.php*
    // @version     1.1
    // ==/UserScript==
     
    $(function() {
            var title = document.title;
           
            var s = document.createElement('style');
           
            s.appendChild(document.createTextNode(
                    '.updatemenu {\
                            position:relative;\
                            margin-bottom:1em;\
                            float:left;\
                    }\
                    \
                    .updatemenu span {\
                            float:left;\
                    }\
                    \
                    .updatemenu span a {\
                            text-decoration:none;\
                            cursor:pointer;\
                            color:#417394;\
                    }\
                    \
                    .updatemenu span a label {\
                            cursor:inherit;\
                    }\
                    \
                    .updatemenu span a input {\
                            vertical-align:text-top;\
                            margin:0 2px;\
                    }\
                    \
                    .updatemenu span.selected {\
                            cursor:default;\
                            background: url("images/buttons/newbtn_middle.png") repeat-x scroll 0% 0% rgb(117, 159, 187);\
                            font-weight:bold;\
                    }\
                    \
                    .postbitnewline {\
                            border-top:4px solid rgb(199, 13, 13) !important;\
                    }'
            ));
           
            document.getElementsByTagName('head')[0].appendChild(s);
     
            if($('#pagination_bottom').length < 1) {
                    $('#postlist').after(
                            '<div id="below_postlist" class="noinlinemod below_postlist">\
                                    <div id="pagination_bottom" class="pagination_bottom">\
                                    </div>\
                            </div>'
                    );
            };
           
            $('#pagination_bottom').append(
                    '<div class="updatemenu popupmenu nohovermenu">\
                            <span>\
                                    <a class="popupctrl" id="updatemanual">Update</a>\
                            </span>\
                            <span>\
                                    <a>\
                                            <label>\
                                                    <input type="checkbox" id="chkautoupdate"></input>\
                                                    Auto\
                                            </label>\
                                    </a>\
                            </span>\
                            <span id="autoupdatetimer" class="selected" style="display:none;">\
                                    <a>10</a>\
                            </span>\
                    </div>'
            );
           
            var intervalUpdate, isUpdating;
            var delays = [10, 15, 30, 60];
            var updateDelay = 0;
            var endOfPage = false;
            var threadid = $('#qr_threadid').val();
     
            function update(wasAuto) {
                    isUpdating = true;
                   
                    $.get(document.URL, {}, function(data) {
                            var max = 0
                            $('#posts li').each(function() {
                                    max = Math.max(max, parseInt($(this).attr('id').substr(5)));
                                    $(this).removeClass('postbitnew').addClass('postbitold');
                                    $(this).removeClass('postbitnewline');
                                    document.title = title;
                            });
                           
                            var numnew = 0;
                           
                            var posts = $('#posts li', data);
                            posts.each(function() {
                                    var id = parseInt($(this).attr('id').substr(5));
                                    if(id > max) {
                                            if(numnew < 1) {
                                                    $(this).addClass('postbitnewline');
                                            };
                                           
                                            $('#posts').append(this);
                           
                                            numnew++;
                                    } else {
                                            $('#' + $(this).attr('id') + ' .date').html($('.date', this).html());
                                            $('#rating_' + id).html($('#rating_' + id, this).html());
                                    };
                            });
                           
                            $('.pagination').html($('.pagination', data).html());
                           
                            if($('.pagination').length < 1 || $('.pagination span').last().hasClass('selected')) {
                                    if(numnew < 1) {
                                            $('#autoupdatetimer a').text('No new posts.');
                                            if(wasAuto) {
                                                    updateDelay = Math.min(updateDelay + 1, delays.length - 1);
                                            };
                                    } else {
                                            $('#autoupdatetimer a').text(numnew + ' new post' + (numnew > 1 ? 's' : ''));
                                            document.title = title + ' (' + numnew + ')'
                                            if(wasAuto) {
                                                    updateDelay = Math.max(updateDelay - 1, 0);
                                            };
                                    };
                            } else {
                                    wasAuto = false;
                                    endOfPage = true;
                                    $('#autoupdatetimer').css('display', 'inline');
                                    $('#autoupdatetimer a').text('No more posts on this page.');
                                    $('#chkautoupdate').attr('disabled', 'disabled');
                            };
                           
                            if(wasAuto) {
                                    intervalUpdate = setInterval(updateTimer, 1000);
                            }
                           
                            isUpdating = false;
                    });
            };
           
            $('#updatemanual').click(function() {
                    if(!isUpdating && !endOfPage) {
                            $('#autoupdatetimer').css('display', 'inline');
                            $('#autoupdatetimer a').text('Updating...');
                            update(!isNaN(intervalUpdate));
                            intervalUpdate = clearInterval(intervalUpdate);
                            return false;
                    };
            });
           
            function updateTimer() {
                    if(isUpdating) intervalUpdate = clearInterval(intervalUpdate);
                    var span = $('#autoupdatetimer a');
                    var time = parseInt((span.text().search(/[^\d]/) >= 0 ? '' : span.text()));
                   
                    if(!isNaN(time)) {
                            if(time <= 1) {
                                    span.text('Updating...');
                                    intervalUpdate = clearInterval(intervalUpdate);
                                    update(true);
                            } else {
                                    span.text(time - 1);
                            };
                    } else {
                            span.text(delays[updateDelay] - 1);
                    };
            };     
           
            $('#chkautoupdate').change(function() {
                    if($(this).is(':checked')) {
                            $('#autoupdatetimer').css('display', 'inline');
                            $('#autoupdatetimer a').text(delays[updateDelay]);
                            intervalUpdate = setInterval(updateTimer, 1000);
                            localStorage.setItem(threadid, true);
                    } else {
                            $('#autoupdatetimer').css('display', 'none');
                            intervalUpdate = clearInterval(intervalUpdate);
                            localStorage.removeItem(threadid);
                    };
            });
           
            if(localStorage.getItem(threadid) == "true") {
                    $('#chkautoupdate').attr('checked', 'checked');
                    $('#chkautoupdate').change();
            } else {
                    $('#chkautoupdate').removeAttr('checked');
            };
    });