Advertisement
rccharles

ASC Goto Alpha

Aug 12th, 2016
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        ASC Goto Test
  3. // @namespace   https://discussions.apple.com/message
  4. // @description This a is test
  5. // @include     https://discussions.apple.com/message/*
  6. // @include     https://discussions.apple.com/thread/*
  7. // @version     1
  8. // @grant       none
  9. // ==/UserScript==
  10.  
  11. // In case of a serious bug, run in the javascript console on the page you want to change.
  12.  
  13. //Some debug global variables It must be openned before first debugOut() function
  14. // Copy & Past to Javascript console. Press return to run.
  15.  
  16. var aDate = new Date();
  17. var debugMode = "";
  18. var debugPass = "";
  19. var newWindow = "";
  20. var debugWindowName = "debug_ASC_CopyGoto.html"
  21.  
  22. //
  23. // Functions to display debug information in another window.
  24. //
  25.  
  26.  
  27. // ------------------------------------------
  28. function startDebug()
  29. {
  30.  if (debugMode == "yes")
  31.  {
  32.   // In debug mode, pass debug mode on.
  33.   debugPass = "debug=yes";
  34.  
  35.   newWindow = window.open("",debugWindowName,
  36.     "scrollbars=yes,resizable=yes,width=700,height=500");
  37.  
  38.   newWindow.document.writeln(
  39.     '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');    
  40.   newWindow.document.writeln(
  41.     "<html>");
  42.   newWindow.document.writeln(
  43.     "<header><title>Window " + debugWindowName + "</title></header>");
  44.   newWindow.document.writeln(
  45.     "<body><p>======================================================"  
  46.     + "==================="
  47.     + "</p>");
  48.   newWindow.document.writeln(
  49.     "<body><p>The debug information that follows was generated on "  
  50.     + aDate + "</p>");
  51.  }
  52.  
  53. }
  54.  
  55.  
  56. // ------------------------------------------  
  57. function dumpProperties(obj, obj_name)
  58. {
  59.   var i;
  60.   // Example invocation & print: DumpProperties(document,'document');
  61.   if (debugMode == "yes" )
  62.   {
  63.    debugOut('In DumpProperties. obj=' + obj_name);
  64.    for (i in obj)
  65.     {
  66.    
  67.     try
  68.     {
  69.       debugOut(obj_name + "." + i + " = " + obj[i]);
  70.     }
  71.     catch(e)
  72.     {
  73.       debugOut("Error writing out structure. Was " + e + " for " + i);
  74.     }
  75.    
  76.    
  77.    }
  78.   }
  79. }  
  80.  
  81.  
  82. // ------------------------------------------
  83. function debugOut(obj)
  84. {
  85.  
  86. if (debugMode == "yes" )
  87. {
  88.  
  89.   // Put to debug window
  90.   var newString = "";
  91.   var i;
  92.  
  93.   for (i=0;i<obj.length;i++)
  94.   {
  95.    if (obj.substr(i,1) == "<")
  96.     newString += "&lt;";
  97.    else if (obj.substr(i,1) == ">")
  98.     newString += "&gt;";
  99.    else if (obj.substr(i,1) == "&")
  100.     newString += "&amp;";
  101.    else
  102.     newString += obj.substr(i,1);
  103.   }
  104.  
  105.  
  106.  newWindow.document.writeln(newString + "<br>");
  107. }
  108. return;
  109. }  
  110.  
  111.  
  112.  
  113.  
  114. // ------------------------------------------
  115. function countCharacters(n)
  116. {
  117.  if (n.nodeType == 3 &&
  118.      n.parentNode.tagName != "SCRIPT") // Check if n is a Text object
  119.    {
  120.      // dumpProperties(n,"n = ");
  121.      debugOut("n.nodeType = " + n.nodeType +
  122.        " n.tagName = " + n.tagName);
  123.      var theParent = n.parentNode;
  124.      debugOut("theParent.nodeType = " + theParent.nodeType +
  125.        " theParent.tagName = " + theParent.tagName);
  126.      debugOut("length of text node = " + n.length +
  127.               " '" + escape(n.data) + "'");
  128.      
  129.      return n.length;
  130.    }
  131.  
  132.  // Otherwise, n  may have children whose characters we need to count
  133.  var numChars = 0;
  134.  for (var m = n.firstChild; m != null; m = m.nextSibling)
  135.    {
  136.      debugOut("n.nodeType = " + n.nodeType +
  137.        " n.tagName = " + n.tagName);
  138.      numChars += countCharacters(m);
  139.    }
  140.  return numChars;
  141. }
  142.  
  143. // ------------------------------------------
  144. function cloneGoto()
  145. {
  146.   // What the "from" htlm looks like.
  147.   //    <div class="all-replies-container">
  148.   //        <!-- BEGIN pagination-->
  149.   //        <span class="j-pagination pagination top">
  150.   //    ... clipped ...
  151.  
  152. try {
  153.    
  154.  
  155.   //  pageinations are after the original post and after the last post.
  156.   //  They only appear when there is more than one page.
  157.   var item = document.getElementsByClassName("j-pagination pagination top")[0];
  158.  
  159.   // Copy the <span> element and its child nodes
  160.   var clone = item.cloneNode(true);
  161.  
  162.   // Buid data structure
  163.   // Create first <li> note
  164.   var firstLi = document.createElement("lI");
  165.   var node = document.createTextNode(" -- ");
  166.   firstLi.appendChild(node);
  167.  
  168.   document.getElementsByClassName("apple-social-actions-toolbar")[0].appendChild(firstLi)
  169.  
  170.   // Create second <li> node
  171.   var secondLi = document.createElement("LI");  
  172.  
  173.   // Append pagination
  174.   // End of with three paginations on page with multipage document
  175.   secondLi.appendChild(clone);                      
  176.  
  177.   // combine li's
  178.   //firstLi.appendChild(secondLi);
  179.  
  180.   // What the "to" html looks like.
  181.   //    <ul class="apple-social-actions-toolbar" role="toolbar" aria-label="Social Actions">      
  182.   //        <li class="j-js-follow-controls"
  183.   //            data-streamsassoc="2"
  184.   //            data-location="jive-macros"
  185.   //            aria-live="polite" aria-atomic="true"> ... </li>      
  186.   //        <li class="apple-actions"
  187.   //            role="toolbar"
  188.   //            aria-labelledby="jive-action-sidebar-tab-header_thread-actions-tab"> ... </li>
  189.   //    </ul>
  190.  
  191.   // Append the cloned <span> element to follow [pulldown]
  192.   document.getElementsByClassName("apple-social-actions-toolbar")[0].appendChild(secondLi);
  193.  
  194. }  // end of try
  195.  
  196. // avoid repeated errors at least
  197. // first get will fail when there is only one page.
  198. catch(err) {
  199.   //   alert(err.message );
  200.   //   alert(err);
  201. }
  202.  
  203. return;
  204.  
  205. }  // end of cloneGoto function
  206.  
  207.  
  208. // ------------------------------------------------------------------------------
  209.  
  210. debugMode = "yes";
  211.  
  212. //startDebug();
  213.  
  214. cloneGoto();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement