Advertisement
rccharles

asc hiroto pagination # D

Sep 1st, 2016
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 5.86 KB | None | 0 0
  1. // ==UserScript==
  2. // @name            ASC Combined thread content view (d2)
  3. // @namespace       bubo-bubo/gmscripts
  4. // @description     ASC - disable jquery animation, initially show all replies, hide rollup solved answer in page 2 or later, clone pagination navigator in header.
  5. // @grant           unsafeWindow
  6. // @run-at          document-end
  7. // @include         https://discussions.apple.com/*
  8. // @include         https://discussionsjapan.apple.com/*
  9. // @include         https://discussionskorea.apple.com/*
  10. // @include         https://discussionschinese.apple.com/*
  11. // @include         https://communities.apple.com/*
  12. // @version         0.2.1
  13. // ==/UserScript==
  14.  
  15. var _debug = 0;
  16. var $ = unsafeWindow.jQuery;
  17. var watchdog1, watchdog2, watchdog3;
  18. var watch_interval          = 300; // [ms]
  19. var re_thread               = new RegExp('^https://[^/]+/thread/');
  20. var re_thread_or_message    = new RegExp('^https://[^/]+/(thread|message)/');
  21.  
  22. // disable jquery animation (globally)
  23. $.fx.off = true;
  24.  
  25. // supplementary styles for pagination nagivator cloned in header (.thread-container-wrapper)
  26. // pagination navigator
  27. //       <----------------- September 1, 2016 ----------------->    
  28. // You may need to adjust the valued for top & right
  29. //   for combined set top to -10px and right to 150px
  30. //   for Hiroto set top to -10px and right to 0px
  31. //   for Turingtest2's minimalist set top to  -10px and right to 0px
  32. //       alternative to the left of the following button set top to 45px and right to 150px
  33. //
  34. document.styleSheets[0].insertRule(
  35. '.thread-container-wrapper .j-pagination.top {\
  36.     position: absolute !important;\
  37.     top: -10px !important;\
  38.     right: 150px !important;\
  39. }', 0);
  40. //       <---------- end positioning adjustment --------------->
  41.  
  42. // loading gear icon
  43. document.styleSheets[0].insertRule(
  44. '.thread-container-wrapper .j-loading-big {\
  45.     position: absolute;\
  46.     top: -6px;\
  47.     left: 0;\
  48.     margin-left: -60px;\
  49.     z-index: -1;\
  50. }', 0);
  51.  
  52.  
  53. // modify thread content view behaviour (in post-load phase)
  54. window.onload = function() {
  55.     // register event listeners
  56.     window.addEventListener('unload', function(e) {
  57.         if (_debug) console.log('unload is observed');
  58.         stop_watchdog(watchdog1);
  59.         stop_watchdog(watchdog2);
  60.         stop_watchdog(watchdog3);
  61.         window.removeEventListener('_locationchange', _locationchange_handler, true);
  62.         window.removeEventListener(e.type, arguments.callee, true);
  63.     }, true);
  64.  
  65.     window.addEventListener('_locationchange', _locationchange_handler, true);
  66.     function _locationchange_handler(e) {
  67.         if (_debug) console.log('_locationchange is observed');
  68.         var href = window.location.href;
  69.         if ( href.match(re_thread) ) {
  70.             setTimeout(show_all_replies, 100);
  71.         }
  72.         if ( href.match(re_thread_or_message) ) {
  73.             setTimeout(hide_solved_p2, 100);
  74.             setTimeout(pagination_in_header, 100);
  75.         }
  76.     }
  77.  
  78.     // _locationchange watch dog
  79.     var prev_href = '';
  80.     watchdog1 = setInterval( function() {
  81.         // watch for location to change
  82.         var curr_href = window.location.href;
  83.         if (curr_href != prev_href) {
  84.             if (_debug) console.log('_locationchange is issued');
  85.             window.dispatchEvent(new Event('_locationchange'));
  86.             prev_href = curr_href;
  87.         }
  88.     }, watch_interval);
  89. };
  90.  
  91. function show_all_replies() {
  92.     window.addEventListener('_helpfuldisplay', function(e) {
  93.         if (_debug) console.log('_helpfuldisplay is observed');
  94.         $('.helpful-all-switch li.helpful').addClass('inactive').removeClass('active').hide();
  95.         $('.helpful-all-switch li.all-replies').addClass('active').removeClass('inactive').show();
  96.         $('#helpful-container').hide();
  97.         $('.all-replies-container').show();
  98.         window.removeEventListener(e.type, arguments.callee, true);
  99.     }, true);
  100.  
  101.     watchdog2 = setInterval( function() {
  102.         // watch for helpful container to appear
  103.         if (_debug) console.log('watchdog (for helpful container) is active : ' + watchdog2);
  104.         if ($('#helpful-container').css('display') != 'none') {
  105.             if (_debug) console.log('_helpfuldisplay is issued');
  106.             window.dispatchEvent(new Event('_helpfuldisplay'));
  107.             stop_watchdog(watchdog2);
  108.         }
  109.     }, watch_interval);
  110.     setTimeout(stop_watchdog, 3000, watchdog2);
  111. }
  112.  
  113. function hide_solved_p2() {
  114.     var u = window.location.href;
  115.     var re = /[?&]start=([0-9]+)/;
  116.     var m = re.exec(u);
  117.     var p = m ? m[1] : 0;
  118.     if (_debug) console.log('current start post numebr = ' + p);
  119.     var div = $('.j-answer-rollup.recommended-answers.span-full-width');
  120.     if (!div) { return; }
  121.     p > 0 ? div.hide() : div.show();
  122. }
  123.  
  124. function pagination_in_header() {
  125.     window.addEventListener('_pagereday', function(e) {
  126.         if (_debug) console.log('_pagereday is observed');
  127.         var pg = $('.all-replies-container .j-pagination.top');
  128.         if (pg) {
  129.             $('.thread-container-wrapper .j-pagination.top').remove();
  130.             pg.clone(true).appendTo($('.thread-container-wrapper'));
  131.         }
  132.         window.removeEventListener(e.type, arguments.callee, true);
  133.     }, true);
  134.  
  135.     watchdog3 = setInterval( function() {
  136.         // watch for reply container opacity to be 1 (which is .5 while loading)
  137.         if (_debug) console.log('watchdog (for page ready) is active : ' + watchdog3);
  138.         if ($('.all-replies-container').css('opacity') == 1) {
  139.             if (_debug) console.log('_pagereday is issued');
  140.             window.dispatchEvent(new Event('_pagereday'));
  141.             stop_watchdog(watchdog3);
  142.         }
  143.     }, watch_interval);
  144. //  setTimeout(stop_watchdog, 5000, watchdog3);
  145. }
  146.  
  147. function stop_watchdog(dog) {
  148.     clearInterval(dog);
  149.     if (_debug) console.log('watchdog is inactive : ' + dog);
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement