Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name ASC adjust to last page on display of posts. Part #2
- // @namespace bubo-bubo/gmscripts
- // @description ASC - Add last page button on list pages
- // @include https://discussions.apple.com/message/*
- // @include https://discussions.apple.com/thread/*
- // @version 1.0
- // @grant none
- // ==/UserScript==
- /* We may not end up on the last page of a display of posts when Apple hosts
- deleted some posts.
- https://discussions.apple.com/thread/5469616?start=1020&tstart=0&begin=yes
- How the input web address is contructed.
- constructedLink = "https://discussions.apple.com/thread/" +
- postNumber +
- "?start=" +
- lastPageStart +
- "&tstart=0&begin=yes";
- */
- var debug = 0; // 0 -- no debug
- // 1 -- normal debug
- // 2 -- intense debug
- var aDate = new Date();
- console.log ("--> adjustLastPage: add fast links. Debug is " + debug +
- " on " + aDate );
- // Setup once page is loaded.
- if (debug) console.log('Loaded; Now, initializing');
- var url = window.location.href;
- var params = url.split('?');
- if (debug) console.log("web page parms " + params[1]);
- // See if we have already adjusted this page.
- try
- {
- pageStatus = Window.asc_jx_last_page_load_remember;
- }// End of try
- catch(err)
- {
- console.log("looking for variable pageStatus " + err.message );
- return;
- }
- if (debug) console.log("pageStatus is " + pageStatus);
- myPassVar = getURLParameter('begin');
- if (debug) console.log("begin parm is " + myPassVar);
- // Do we need to see if we need to adjust to the last page?
- if ( myPassVar == "yes" && pageStatus != "yes")
- {
- // Global remember, so we can check if we already adjusted this page
- Window.asc_jx_last_page_load_remember = "yes";
- if (debug>= 2) console.log("Have set Window.asc_jx_last_page_load_remember to " +
- Window.asc_jx_last_page_load_remember);
- currentPageStart = getURLParameter('start');
- if (debug) console.log("start parm is " + currentPageStart);
- // Check what page we are on.
- var pageNumbers = $("span.current-page").text();
- if (debug) console.log("pageNumbers " + pageNumbers);
- // Ejaz explans how to pull words from a string
- // in http://stackoverflow.com/questions/16223043/get-second-and-third-words-from-string
- // The technique using split() will fail if the string has multiple spaces in it.
- // Don't forget to check your array length using .length property to avoid
- // getting undefined in your variables.
- var actualPages = pageNumbers.match(/\S+/gi);
- if (debug) console.log("closer "+ actualPages);
- var currentPage = parseInt(actualPages[1]);
- var lastPage = parseInt(actualPages[3]);
- if (debug) console.log("current page is " + currentPage.toString() );
- if (debug) console.log("last page is " + lastPage.toString() );
- // If the current page is differernt than the last page, apple removed some post
- // and we need to adjust to last page.
- if ( currentPage != lastPage )
- {
- if (debug) console.log("mismatched pages ");
- // Adjust to the last page.
- // Handy dandy ASC function is used when user clicks on last button, so use it
- jspaginate.init('last', actualPages[3]);
- if (debug) console.log("Page adjusted! " );
- }
- }
- else
- {
- if (debug) console.log("... Nothing to do! ...");
- }
- // Seems that javascript [ or someone ]
- // sends the last value from an assignment statement as the return code to the caller.
- done = 0;
- // ----------------------------------------------------------------------------------------
- //
- // http://stackoverflow.com/questions/11582512/how-to-get-url-parameters-with-javascript
- //
- // example:
- // myvar = getURLParameter('myvar');
- function getURLParameter(name) {
- return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) ||
- [null, ''])[1].replace(/\+/g, '%20')) || null;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement