Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ASC Goto Test
- // @namespace https://discussions.apple.com/message
- // @description This a is test
- // @include https://discussions.apple.com/message/*
- // @include https://discussions.apple.com/thread/*
- // @version 1
- // @grant none
- // ==/UserScript==
- // In case of a serious bug, run in the javascript console on the page you want to change.
- //Some debug global variables It must be openned before first debugOut() function
- // Copy & Past to Javascript console. Press return to run.
- var aDate = new Date();
- var debugMode = "";
- var debugPass = "";
- var newWindow = "";
- var debugWindowName = "debug_ASC_CopyGoto.html"
- //
- // Functions to display debug information in another window.
- //
- // ------------------------------------------
- function startDebug()
- {
- if (debugMode == "yes")
- {
- // In debug mode, pass debug mode on.
- debugPass = "debug=yes";
- newWindow = window.open("",debugWindowName,
- "scrollbars=yes,resizable=yes,width=700,height=500");
- newWindow.document.writeln(
- '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">');
- newWindow.document.writeln(
- "<html>");
- newWindow.document.writeln(
- "<header><title>Window " + debugWindowName + "</title></header>");
- newWindow.document.writeln(
- "<body><p>======================================================"
- + "==================="
- + "</p>");
- newWindow.document.writeln(
- "<body><p>The debug information that follows was generated on "
- + aDate + "</p>");
- }
- }
- // ------------------------------------------
- function dumpProperties(obj, obj_name)
- {
- var i;
- // Example invocation & print: DumpProperties(document,'document');
- if (debugMode == "yes" )
- {
- debugOut('In DumpProperties. obj=' + obj_name);
- for (i in obj)
- {
- try
- {
- debugOut(obj_name + "." + i + " = " + obj[i]);
- }
- catch(e)
- {
- debugOut("Error writing out structure. Was " + e + " for " + i);
- }
- }
- }
- }
- // ------------------------------------------
- function debugOut(obj)
- {
- if (debugMode == "yes" )
- {
- // Put to debug window
- var newString = "";
- var i;
- for (i=0;i<obj.length;i++)
- {
- if (obj.substr(i,1) == "<")
- newString += "<";
- else if (obj.substr(i,1) == ">")
- newString += ">";
- else if (obj.substr(i,1) == "&")
- newString += "&";
- else
- newString += obj.substr(i,1);
- }
- newWindow.document.writeln(newString + "<br>");
- }
- return;
- }
- // ------------------------------------------
- function countCharacters(n)
- {
- if (n.nodeType == 3 &&
- n.parentNode.tagName != "SCRIPT") // Check if n is a Text object
- {
- // dumpProperties(n,"n = ");
- debugOut("n.nodeType = " + n.nodeType +
- " n.tagName = " + n.tagName);
- var theParent = n.parentNode;
- debugOut("theParent.nodeType = " + theParent.nodeType +
- " theParent.tagName = " + theParent.tagName);
- debugOut("length of text node = " + n.length +
- " '" + escape(n.data) + "'");
- return n.length;
- }
- // Otherwise, n may have children whose characters we need to count
- var numChars = 0;
- for (var m = n.firstChild; m != null; m = m.nextSibling)
- {
- debugOut("n.nodeType = " + n.nodeType +
- " n.tagName = " + n.tagName);
- numChars += countCharacters(m);
- }
- return numChars;
- }
- // ------------------------------------------
- function cloneGoto()
- {
- // What the "from" htlm looks like.
- // <div class="all-replies-container">
- // <!-- BEGIN pagination-->
- // <span class="j-pagination pagination top">
- // ... clipped ...
- try {
- // pageinations are after the original post and after the last post.
- // They only appear when there is more than one page.
- var item = document.getElementsByClassName("j-pagination pagination top")[0];
- // Copy the <span> element and its child nodes
- var clone = item.cloneNode(true);
- // Buid data structure
- // Create first <li> note
- var firstLi = document.createElement("lI");
- var node = document.createTextNode(" -- ");
- firstLi.appendChild(node);
- document.getElementsByClassName("apple-social-actions-toolbar")[0].appendChild(firstLi)
- // Create second <li> node
- var secondLi = document.createElement("LI");
- // Append pagination
- // End of with three paginations on page with multipage document
- secondLi.appendChild(clone);
- // combine li's
- //firstLi.appendChild(secondLi);
- // What the "to" html looks like.
- // <ul class="apple-social-actions-toolbar" role="toolbar" aria-label="Social Actions">
- // <li class="j-js-follow-controls"
- // data-streamsassoc="2"
- // data-location="jive-macros"
- // aria-live="polite" aria-atomic="true"> ... </li>
- // <li class="apple-actions"
- // role="toolbar"
- // aria-labelledby="jive-action-sidebar-tab-header_thread-actions-tab"> ... </li>
- // </ul>
- // Append the cloned <span> element to follow [pulldown]
- document.getElementsByClassName("apple-social-actions-toolbar")[0].appendChild(secondLi);
- } // end of try
- // avoid repeated errors at least
- // first get will fail when there is only one page.
- catch(err) {
- // alert(err.message );
- // alert(err);
- }
- return;
- } // end of cloneGoto function
- // ------------------------------------------------------------------------------
- debugMode = "yes";
- //startDebug();
- cloneGoto();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement