Advertisement
rccharles

lastReadPage v1

Feb 6th, 2017
696
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        ASC Add link to last page of long discussions -- February 3, 2017 --
  3. // @namespace   ASCPaginationGoto
  4. // @description script functions
  5. // @include     https://discussions.apple.com/content?*
  6. // @include     https://discussions.apple.com/community/*/content?*
  7. // @version     1
  8. // @grant       none
  9. // ==/UserScript==
  10. /*
  11.    Add link to last page of long discussions.
  12.  
  13. Supported lists:
  14.   https://discussions.apple.com/content?filterID=following~objecttype~objecttype[thread]
  15.   https://discussions.apple.com/community/ipad/ipad_in_business_and_education/content?filterID=contentstatus
  16.     %5Bpublished%5D%7Eobjecttype%7Eobjecttype%5Bthread%5D
  17.   https://discussions.apple.com/community/mac_os/os_x_el_capitan/content?filterID=contentstatus[published]
  18.     ~objecttype~objecttype[thread]
  19.  
  20. but not:
  21.   https://discussions.apple.com/community/lounge/full_host_bar
  22.  
  23.    
  24. Why does apple slow down old devices?            66 18035   February 2, 2017 9:15 PM
  25. in Using iPad by gail from maine                 by gail from maine
  26.  
  27.   https://discussions.apple.com/thread/7527129
  28.   https://discussions.apple.com/thread/7527129?start=15&tstart=0
  29.   https://discussions.apple.com/thread/7527129?start=30&tstart=0
  30.   https://discussions.apple.com/thread/7527129?start=45&tstart=0
  31.   https://discussions.apple.com/thread/7527129?start=60&tstart=0
  32.  
  33. */
  34.  
  35. var debug = 0;
  36. var replyCounts = new Array();
  37. var titleCounts = new Array();
  38. var done = 0;
  39. var entrySize = 15;  // number of discussion listed on web page
  40. var lastPageStart = 0;
  41. var constructedLink = "";
  42. var insertA = "";
  43.  
  44. var aDate = new Date();
  45. console.log ("--> lastReadPage: add fast links " + aDate );
  46.  
  47. $("table tr.js-browse-item td.j-td-replies").each(  
  48.   function( index )  
  49.     {  
  50.     replyCounts[index] = $( this ).text();
  51.     }  
  52.  );
  53.  
  54.  
  55. if (debug) for ( i = 0;i<replyCounts.length;++i )
  56.   {
  57.     console.log("reply " + i + " is " + replyCounts[i] );
  58.   }
  59.  
  60. if (debug) console.log("Find the titles");
  61.  
  62. var trSection = $("table tr.js-browse-item td.j-td-title");
  63.  
  64. $("a:first", trSection ).each(  
  65.   function( index )  
  66.     {  
  67.       titleCounts[index] = $( this ).text();
  68.       if (debug) console.log("------  " + $( this ).html() + " ------");
  69.      
  70.       postNumber = $( this ).attr("href").split("/")[2].trim();
  71.       if (debug) console.log("a post number is " + postNumber);
  72.  
  73.       mathFloorInt = Math.floor(replyCounts[index]/entrySize);
  74.       console.log ("repies = " + replyCounts[index] + " mathFloorInt is " + mathFloorInt );
  75.       if (mathFloorInt) {
  76.         lastPageStart = mathFloorInt * entrySize;
  77.         constructedLink = "https://discussions.apple.com/thread/" +
  78.                       postNumber +
  79.                       "?start=" +
  80.                       lastPageStart +
  81.                       "&tstart=0";
  82.          if (debug) console.log("link is " + constructedLink);
  83.        
  84.          insertA = '<span class="rcUserASCModLastReadPage">' +
  85.                    '<a style=" color: SlateBlue; margin-left: 15px; border: 1px dotted black;" ' +
  86.                    'href="' +
  87.                    constructedLink +
  88.                    '">Last Page</a>' +
  89.                    '</span>';
  90.          if (debug) console.log("inserted is " + insertA);
  91.          $( this ).after( insertA );  
  92.        }          
  93.     } // end of function
  94.  ); // end of .each
  95.  
  96. // Seems that javascript [ or someone ]
  97. // sends the last value from an assignment statement as the return code to the caller.
  98. done = 0;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement