Add pagination to the top of the screen messages page - new and improved

I have a phase beta Javascript that puts a third set of pagination and icons located at the top right of the screen CSA post web page information.

Here is the web page with my improvement Linc Davis is not nearly enough recognition :

If it was not easy for me to code, it must not be easy for you to install.

Installation:

(1) install GreaseMonkey in Firefox. GreaseMonkey does not work in other browsers like Chrome, but I have not tried.

How to install improved pagination

(2) add the javascript code of

http://pastebin.com/raw/9MBCkakf

R

PS. Hiroto has a solution too: Hiroto, javascript fix for CSA.

Hello

Here's my javascript which now includes the cloning of pagination in header. The pagination_in_header() of service as well as the relevant rules of style injected by CSSStyleSheet.insertRule () does the job. You can adjust the positioning of the cloned by CSSRule element defined in javascript.

FC.

Document Object Model (DOM) level 2 Style specification

https://www.w3.org/TR/DOM-level-2-style/

// ==UserScript==
// @name            ASC thread content view (d2)
// @namespace       bubo-bubo/gmscripts
// @description     ASC - disable jquery animation, initially show all replies, hide rollup solved answer in page 2 or later, clone pagination navigator in header.
// @grant           unsafeWindow
// @run-at          document-end
// @include         https://discussions.apple.com/*
// @include         https://discussionsjapan.apple.com/*
// @include         https://discussionskorea.apple.com/*
// @include         https://discussionschinese.apple.com/*
// @include         https://communities.apple.com/*
// @version         0.2.1
// ==/UserScript==

var _debug = 0;
var $ = unsafeWindow.jQuery;
var watchdog1, watchdog2, watchdog3;
var watch_interval          = 300; // [ms]
var re_thread               = new RegExp('^https://[^/]+/thread/');
var re_thread_or_message    = new RegExp('^https://[^/]+/(thread|message)/');

// disable jquery animation (globally)
$.fx.off = true;

// supplementary styles for pagination nagivator cloned in header (.thread-container-wrapper)
// pagination navigator
document.styleSheets[0].insertRule(
'.thread-container-wrapper .j-pagination.top {\
    position: absolute !important;\
    top: -10px !important;\
    right: 0px !important;\
}', 0);
// loading gear icon
document.styleSheets[0].insertRule(
'.thread-container-wrapper .j-loading-big {\
    position: absolute;\
    top: -6px;\
    left: 0;\
    margin-left: -60px;\
    z-index: -1;\
}', 0);

// modify thread content view behaviour (in post-load phase)
window.onload = function() {
    // register event listeners
    window.addEventListener('unload', function(e) {
        if (_debug) console.log('unload is observed');
        stop_watchdog(watchdog1);
        stop_watchdog(watchdog2);
        stop_watchdog(watchdog3);
        window.removeEventListener('_locationchange', _locationchange_handler, true);
        window.removeEventListener(e.type, arguments.callee, true);
    }, true);

    window.addEventListener('_locationchange', _locationchange_handler, true);
    function _locationchange_handler(e) {
        if (_debug) console.log('_locationchange is observed');
        var href = window.location.href;
        if ( href.match(re_thread) ) {
            setTimeout(show_all_replies, 100);
        }
        if ( href.match(re_thread_or_message) ) {
            setTimeout(hide_solved_p2, 100);
            setTimeout(pagination_in_header, 100);
        }
    }

    // _locationchange watch dog
    var prev_href = '';
    watchdog1 = setInterval( function() {
        // watch for location to change
        var curr_href = window.location.href;
        if (curr_href != prev_href) {
            if (_debug) console.log('_locationchange is issued');
            window.dispatchEvent(new Event('_locationchange'));
            prev_href = curr_href;
        }
    }, watch_interval);
};

function show_all_replies() {
    window.addEventListener('_helpfuldisplay', function(e) {
        if (_debug) console.log('_helpfuldisplay is observed');
        $('.helpful-all-switch li.helpful').addClass('inactive').removeClass('active').hide();
        $('.helpful-all-switch li.all-replies').addClass('active').removeClass('inactive').show();
        $('#helpful-container').hide();
        $('.all-replies-container').show();
        window.removeEventListener(e.type, arguments.callee, true);
    }, true);

    watchdog2 = setInterval( function() {
        // watch for helpful container to appear
        if (_debug) console.log('watchdog (for helpful container) is active : ' + watchdog2);
        if ($('#helpful-container').css('display') != 'none') {
            if (_debug) console.log('_helpfuldisplay is issued');
            window.dispatchEvent(new Event('_helpfuldisplay'));
            stop_watchdog(watchdog2);
        }
    }, watch_interval);
    setTimeout(stop_watchdog, 3000, watchdog2);
}

function hide_solved_p2() {
    var u = window.location.href;
    var re = /[?&]start=([0-9]+)/;
    var m = re.exec(u);
    var p = m ? m[1] : 0;
    if (_debug) console.log('current start post numebr = ' + p);
    var div = $('.j-answer-rollup.recommended-answers.span-full-width');
    if (!div) { return; }
    p > 0 ? div.hide() : div.show();
}

function pagination_in_header() {
    window.addEventListener('_pagereday', function(e) {
        if (_debug) console.log('_pagereday is observed');
        var pg = $('.all-replies-container .j-pagination.top');
        if (pg) {
            $('.thread-container-wrapper .j-pagination.top').remove();
            pg.clone(true).appendTo($('.thread-container-wrapper'));
        }
        window.removeEventListener(e.type, arguments.callee, true);
    }, true);

    watchdog3 = setInterval( function() {
        // watch for reply container opacity to be 1 (which is .5 while loading)
        if (_debug) console.log('watchdog (for page ready) is active : ' + watchdog3);
        if ($('.all-replies-container').css('opacity') == 1) {
            if (_debug) console.log('_pagereday is issued');
            window.dispatchEvent(new Event('_pagereday'));
            stop_watchdog(watchdog3);
        }
    }, watch_interval);
//  setTimeout(stop_watchdog, 5000, watchdog3);
}

function stop_watchdog(dog) {
    clearInterval(dog);
    if (_debug) console.log('watchdog is inactive : ' + dog);
}

Tested with Greasemonkey 3.9 and Firefox 45.3.0esr OS X 10.6.8.

All the best,

Hiroto

Tags: Using Support Communities

Similar Questions

Maybe you are looking for