Advertisement
Guest User

Restore GameFAQs Board Nav Buttons

a guest
May 27th, 2015
641
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Board Navigation Buttons
  3. // @namespace   GameFAQs
  4. // @description Restore the board navigation buttons, and add an AMP button
  5. // @include     /http://www\.gamefaqs\.com/boards/[0-9][0-9]*/
  6. // @grant       none
  7. // @version     1.0
  8. // @author      Frost_shock_FTW
  9. // ==/UserScript==
  10.  
  11. var paginate_button_lists = document.getElementsByClassName( 'paginate user' );
  12.  
  13. var topiclist_button = document.createElement( 'li' );
  14. var topiclist_link = document.createElement( 'a' );
  15. var topiclist_text = document.createTextNode( 'Topic List' );
  16.  
  17. topiclist_link.appendChild( topiclist_text );
  18. topiclist_link.href = Get_topic_list_url();
  19. topiclist_button.appendChild( topiclist_link );
  20.  
  21. var boardlist_button = document.createElement( 'li' );
  22. var boardlist_link = document.createElement( 'a' );
  23. var boardlist_text = document.createTextNode( 'Board List' );
  24.  
  25. boardlist_link.appendChild( boardlist_text );
  26. boardlist_link.href = Get_board_list_url();
  27. boardlist_button.appendChild( boardlist_link );
  28.  
  29. var amp_button = document.createElement( 'li' );
  30. var amp_link = document.createElement( 'a' );
  31. var amp_text = document.createTextNode( 'Active Messages Posted' );
  32.  
  33. amp_link.appendChild( amp_text );
  34. amp_link.href = '/boards/myposts.php';
  35. amp_button.appendChild( amp_link );
  36.  
  37. // This script runs on board pages and topic pages.
  38. // Only insert a Topic List button if we are on a topic page.
  39. var on_topic_page = document.getElementsByClassName( 'board topics tlist' ).length == 0;
  40.  
  41. for( var i = 0; i < paginate_button_lists.length; ++i ) {
  42.     if ( on_topic_page ) {
  43.         paginate_button_lists[i].insertBefore( topiclist_button.cloneNode( true ),
  44.                                                paginate_button_lists[i].children[1] );
  45.     }
  46.    
  47.     paginate_button_lists[i].insertBefore( boardlist_button.cloneNode( true ),
  48.                                            paginate_button_lists[i].children[1] );
  49.                                            
  50.     paginate_button_lists[i].insertBefore( amp_button.cloneNode( true ),
  51.                                            paginate_button_lists[i].children[1] );
  52. }
  53.  
  54. function Get_board_list_url() {
  55.     return window.location.origin + '/boards';
  56. }
  57.  
  58. function Get_topic_list_url() {
  59.     // A GameFAQs topic post link will be in one of two forms:
  60.     // - http://www.gamefaqs.com/boards/BOARDID-BOARD-NAME/TOPICID#POSTNUM
  61.     // - http://www.gamefaqs.com/boards/BOARDID-BOARD-NAME/TOPICID?page=PAGENUM#POSTNUM
  62.     //
  63.     // In both cases, the topic list URL can be found by truncating before the last '/'
  64.    
  65.     var last_slash_index = window.location.href.lastIndexOf( '/' );
  66.    
  67.     return window.location.href.slice( 0, last_slash_index );
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement