Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ASC Combined 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
- // <----------------- September 1, 2016 ----------------->
- // You may need to adjust the valued for top & right
- // for combined set top to -10px and right to 150px
- // for Hiroto set top to -10px and right to 0px
- // for Turingtest2's minimalist set top to -10px and right to 0px
- // alternative to the left of the following button set top to 45px and right to 150px
- //
- document.styleSheets[0].insertRule(
- '.thread-container-wrapper .j-pagination.top {\
- position: absolute !important;\
- top: -10px !important;\
- right: 150px !important;\
- }', 0);
- // <---------- end positioning adjustment --------------->
- // 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);
- }
Add Comment
Please, Sign In to add comment