Bookmarklets for navigating TA

Discussion in 'Off-Topic Lounge' started by Prab, Sep 2, 2009.

  1. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    #1 Prab, Sep 2, 2009
    Last edited: Sep 2, 2009
    Hi everyone,

    I browse TA on my iPhone a lot and I find the page navigation of the forum to be a little small for my fingers to press. The "First", "Prev" and "Next" links are a little bigger but it can still be a little difficult to press sometimes.

    So what I did was to make some bookmarklets to help page navigation for "First Page", "Previous Page", and "Next Page". These bookmarklets would work on navigating pages of a forum as well as pages of a thread.

    With these bookmarklets, for example: instead of clicking on the small "next" link on the page, you can just open the "Next Page" bookmarklet and it will correctly take you there. I thought I'd share the bookmarklets here:

    First Page bookmarklet:
    HTML:
    javascript:if(document.location.href.indexOf("&page=")!=-1)%7BpageNumber=parseInt(document.location.href.match(/\d+$/));if(pageNumber>1)%7BpageNumber=1;document.location=document.location.href.replace(/\d+$/,pageNumber);%7D%7Dvoid(0)
    Previous Page bookmarklet:
    HTML:
    javascript:if(document.location.href.indexOf("&page=")!=-1)%7BpageNumber=parseInt(document.location.href.match(/\d+$/));if(pageNumber>1)%7BpageNumber=pageNumber-1;document.location=document.location.href.replace(/\d+$/,pageNumber);%7D%7Dvoid(0)
    Next Page bookmarklet:
    HTML:
    javascript:if(document.location.href.indexOf("&page=")==-1)%7Bif(document.location.href.indexOf("showthread")==-1)%7Bdocument.location=document.location.href+"&order=desc&page=2";%7Delse%7Bdocument.location=document.location.href+"&page=2";%7D%7Delse%7BpageNumber=parseInt(document.location.href.match(/\d+$/))+1;document.location=document.location.href.replace(/\d+$/,pageNumber);%7Dvoid(0)
    If you already know how to install / use these bookmarklets, you may skip the rest of my post. I hope they are useful for you. PM me if you find any bugs Thanks! :)

    To install the above bookmarklets from your iPod Touch / iPhone, do the following steps for each bookmarklet separately:
    1. Copy the code of the bookmarklet you would like to add (you will need OS 3.0 for this step to be convenient). The code is the long text that starts with "javascript" and ends with "void(0)".
    2. Tap the "+" button from the bottom bar of Safari, and select "Add Bookmark" to bookmark the current page. You will be able to edit the name of the bookmark (Enter the name of the bookmarklet, e.g. "Previous Page") and also select where to save the bookmark. The location of the bookmark is not editable (and will point to the current page: "http://forums.toucharcade.com/....". This is fine. We will change it in the next step. Tap save to save the bookmark.
    3. Tap the book icon from the bottom bar of Safari to bring up the list of bookmarks. Navigate to where you chose to save the bookmark from the step above and then tap the Edit button (bottom left corner of the screen). Then tap on the bookmark you created earlier. You will be brought to an edit screen but this time, the location of the bookmark is editable (see image below). Delete the location of the bookmark ("http://forums.toucharcade.com/....") and replace it with the code you copied in the first step ("javascript...void(0)"). Tap Done to exit the edit screen, tap Done again to exit editing the bookmarks, and tap Done again to go back to the browser.
      photo.3.jpg
    4. You are done :) Do these 4 steps for each of the bookmarklets that you would like to install. I hope its useful.

    Cheers,

    Prab

    PS: In case any of you would like to check the code, here it is in full form:
    HTML:
    /* First Page Bookmarklet */
    if (document.location.href.indexOf("&page=") != -1) { // if not at the first page
      pageNumber = parseInt(document.location.href.match(/\d+$/));
      if (pageNumber > 1) { // if not at the first page, set the page number to 1
        pageNumber = 1;
        document.location = document.location.href.replace(/\d+$/,pageNumber);
      }
    } void(0)
    
    /* Previous Page Bookmarklet */
    if (document.location.href.indexOf("&page=") != -1) { // if not at the first page
      pageNumber = parseInt(document.location.href.match(/\d+$/));
      if (pageNumber > 1) { // if not at the first page, decrease the page number
        pageNumber = pageNumber - 1;
        document.location = document.location.href.replace(/\d+$/,pageNumber);
      }
    } void(0)
    
    /* Next Page Bookmarklet */
    if (document.location.href.indexOf("&page=") == -1) { // if at the first page
      if (document.location.href.indexOf("showthread") == -1) { // if its a forum page
        document.location = document.location.href + "&order=desc&page=2";
      } else { // else a thread page
        document.location = document.location.href + "&page=2";
      }
    } else { // else just increase the page number
      pageNumber = parseInt(document.location.href.match(/\d+$/)) + 1;
      document.location = document.location.href.replace(/\d+$/,pageNumber);
    } void(0)
     
  2. ImNoSuperMan

    ImNoSuperMan Well-Known Member

    Jun 28, 2009
    10,506
    19
    0
    whoa. Thats way too much of code for someone like me. :eek:

    Anyways let me give it a try. May be it`ll be easier than what it looks. Now where is that iPhone...
     
  3. ImNoSuperMan

    ImNoSuperMan Well-Known Member

    Jun 28, 2009
    10,506
    19
    0
    Tried the next command. It worked like a charm :D

    Are there more such bookmarklets? I think I did read about them some where else too. It was quite a while back and it was supposed to bring find, copy, translate etc. I never really tried it back then as it looked too complicated. Do you also have one which allows you to scroll to the bottom of the page?

    Anyways, great job done buddy, Thanx a lot.:)
     
  4. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    Scroll to the bottom of the page?

    How about this:
    HTML:
    javascript:window.scrollBy(0,100000);
    Its actually a hack but it should work for virtually all pages :)
     
  5. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    Okay I just found a bug. The bookmarklets don't work for TA pages with anchors (eg when you click on the little blue checkbox on the left of a thread title).

    I'll fix this when I have time or if there's any interest.
     
  6. ImNoSuperMan

    ImNoSuperMan Well-Known Member

    Jun 28, 2009
    10,506
    19
    0
    That worked too :)

    Thank you X 2 :D
     
  7. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    Sure :) No problem.

    Let me know if you need a bookmarklet that does anything else (hopefully not too complicated) lol
     
  8. Zincous

    Zincous Well-Known Member

    Dec 23, 2008
    4,567
    46
    48
    Sacramento, CA
    This is cool. Didn't see this thread first time around. I'll definitely be using these.

    How about a "last button"? When in threads with a lot of pages it will say "1, 2, 3, 10, 20, Last"

    There's even a Last button when inside each sub-forum, although I don't use it very much :p

    View attachment 7330
     
  9. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    A bit more difficult but will try to make one :p
     
  10. Zincous

    Zincous Well-Known Member

    Dec 23, 2008
    4,567
    46
    48
    Sacramento, CA
    Thanks. If not, that's fine. I'm happy enough with my next, previous, and first buttons :)
     
  11. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    Its fine :D Its the same problem as the bug I found for the next, previous buttons :p (see post #5)
     
  12. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    #12 Prab, Dec 3, 2009
    Last edited: Dec 3, 2009
    New bookmarklet for Searching in thread titles (all forums) from any sub FORUM in TA
    This wont work if you are viewing a thread or a list of sub forums.

    [​IMG]

    The bookmarklet:
    HTML:
    javascript:function%20m(n,v)%20%7Bvar%20i=document.createElement('INPUT');i.setAttribute('type','hidden');i.setAttribute('name',n);i.setAttribute('value',v);return%20i;%20%7Dfunction%20s(q,t)%20%7Bvar%20f=document.createElement('FORM');f.setAttribute('action','search.php?do=process');f.setAttribute('method','post');f.setAttribute('name','pbsc');var%20i1=m('securitytoken',t);var%20i2=m('do','process');var%20i3=m('query',q);var%20i4=m('titleonly','1');var%20i5=m('searchdate','0');var%20i6=m('sortby','lastpost');var%20i7=m('order','descending');var%20i8=m('showposts','0');var%20i9=m('forumchoice[]','0');var%20i10=m('childforums','1');var%20i11=m('dosearch','Search%20Now');f.appendChild(i1);f.appendChild(i2);f.appendChild(i3);f.appendChild(i4);f.appendChild(i5);f.appendChild(i6);f.appendChild(i7);f.appendChild(i8);f.appendChild(i9);f.appendChild(i10);f.appendChild(i11);document.body.appendChild(f);document.forms["pbsc"].submit();%20%7D%20function%20s2()%7Bvar%20q=prompt("Search%20Titles:","");if%20(q!=null%20&%20q!="")%20%7Bs(q,document.getElementById("forumsearch_menu").childNodes[1].securitytoken.value);%7D%20%7Ds2();
    Unobfuscated:
    HTML:
    function m(n,v) {
      var i=document.createElement('INPUT');
      i.setAttribute('type','hidden');
      i.setAttribute('name',n);
      i.setAttribute('value',v);
      return i;
    }
    function s(q,t) {
      var f=document.createElement('FORM');
      f.setAttribute('action','search.php?do=process');
      f.setAttribute('method','post');
      f.setAttribute('name','pbsc');
      var i1=m('securitytoken',t);
      var i2=m('do','process');
      var i3=m('query',q);
      var i4=m('titleonly','1');
      var i5=m('searchdate','0');
      var i6=m('sortby','lastpost');
      var i7=m('order','descending');
      var i8=m('showposts','0');
      var i9=m('forumchoice[]','0');
      var i10=m('childforums','1');
      var i11=m('dosearch','Search Now');
      f.appendChild(i1);
      f.appendChild(i2);
      f.appendChild(i3);
      f.appendChild(i4);
      f.appendChild(i5);
      f.appendChild(i6);
      f.appendChild(i7);
      f.appendChild(i8);
      f.appendChild(i9);
      f.appendChild(i10);
      f.appendChild(i11);
      document.body.appendChild(f);
      document.forms["pbsc"].submit();
    }
    function s2(){
      var q=prompt("Search Titles:","");
      if (q!=null & q!="") {
        s(q,document.getElementById("forumsearch_menu").childNodes[1].securitytoken.value);
      }
    } s2();
    
     
  13. Squeaker

    Squeaker Well-Known Member

    May 31, 2009
    3,366
    7
    38
    Bookland
    Stumbled on this today. Have to say, great job!
    I ALWAYS press the wrong links when I browse TA on iPhone,
    these bookmarklets are going to save me so much trouble.
     
  14. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    Thanks :D I'm doing this in my spare time so it'll be awhile before there's a bookmarklet for everything. Lol

    I plan to make the search work on all pages of the forum and also, a bookmarklet to go to the last page of a thread, go to page XX of a thread.

    If there are any other ideas, just post them here :)
     
  15. eggzbacon

    eggzbacon Well-Known Member

    May 17, 2009
    5,808
    38
    38
    The Golden State
    I missed this thread, great thinking Prab :D
     
  16. Bluellama1

    Bluellama1 Well-Known Member

    Jul 25, 2009
    919
    3
    18
    Student
    Metro Detroit, Michigan
    These are great! Keep on making these!
     
  17. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
  18. Prab

    Prab Moderator
    Staff Member Patreon Silver Patreon Gold Patreon Bronze

    Dec 17, 2008
    3,549
    7
    0
    CS student
    SG
    Another bookmarklet to mark a subforum (list of thread) as read:
    You need to be in the actual subforum (that lists the threads)

    Bookmarklet:
    HTML:
    javascript:function%20pbrd()%7Bif(document.location.href.indexOf("forumdisplay.php?")!=-1)%7Bfid=parseInt(document.location.href.match(/(\?|&)f=(\d+)($|&)/)[2]);mark_forum_read(fid);return;%7D%7Dpbrd();
    Unobfuscated:
    HTML:
    function pbrd() {
      if(document.location.href.indexOf("forumdisplay.php?")!=-1) {
        fid=parseInt(document.location.href.match(/(\?|&)f=(\d+)($|&)/)[2]);
        mark_forum_read(fid);
        return;
      }
    } pbrd();
     
  19. MidianGTX

    MidianGTX Well-Known Member

    Jun 16, 2009
    3,738
    10
    38
    Sweet. Now we just need a "Ban user X for all eternity" bookmarklet and we're ready to go!

    Actually I'm concerned Hodapp may already have one of those...
     

Share This Page