Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why wont this bookmarklet work?

    I'm trying to make a bookmarklet for easy use of a website that grabs a video's real location so I can watch it in VLC media player. I am not a javascript programmer but I've looked some stuff up and this should work shouldn't it? So far I have this:


    Code:
    var t, vidurl, mathcode;
    
    start();
    
    function start() {
      vidurl=window.location;
      window.location="http://clipnabber.com";
      setTimeout("end()",100);}
    
    function end() {
      alert("in end");
      mathcode=document.getElementById("Math").innerHTML;
      alert(mathcode);
      vidurl=vidurl.replace(/\&/g,"%26");
      vidurl=vidurl.replace(/#/g,"%23");
      vidurl=vidurl.replace(/=/g,"%3D");
      vidurl=vidurl.replace(/\?/g,"%3F");
      vidurl=vidurl.replace(/.html/g,"dothtml");
      window.location="http://clipnabber.com/gethint.php?mode=1&url="+vidurl+"&sid="+mathcode;}
    I added the setTimeout because I don't know how to tell if the page is loaded fully. If there is a better way I'm all ears.

    Here is bookmarklet form:

    Code:
    javascript:var t, vidurl, mathcode; start(); function start(){vidurl=window.location; window.location="http://clipnabber.com"; setTimeout("end()",100);} function end(){alert("in end"); mathcode=document.getElementById("Math").innerHTML; alert(mathcode); vidurl=vidurl.replace(/\&/g,"%26"); vidurl=vidurl.replace(/#/g,"%23"); vidurl=vidurl.replace(/=/g,"%3D"); vidurl=vidurl.replace(/\?/g,"%3F"); vidurl=vidurl.replace(/.html/g,"dothtml"); window.location="http://clipnabber.com/gethint.php?mode=1&url="+vidurl+"&sid="+mathcode;}
    When I test it the alert box saying "in end" will show but then it stops. I can't get the alert box showing the mathcode to show and it won't go to the new location either. In the firefox error console it says "Error: uncaught exception: unknown (can't convert to string)".

    I tried changing alert(mathcode) to alert(String(mathcode)) hoping that would do it but had no success. Please help, I'm not sure what I'm doing wrong here.
    Last edited by rig99; 05-15-2009 at 07:47 AM.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    mathcode is not your problem. The problem is that vidurl is an object, not a string.

    Code:
    function end() {
      alert("in end");
      mathcode=document.getElementById("Math").innerHTML;
      alert(mathcode);
    alert (typeof vidurl);
    vidurl = vidurl.toString();
    alert (typoeof vidurl);
     vidurl=vidurl.replace(/\&/g,"%26");

    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
    Last edited by Philip M; 05-15-2009 at 09:22 AM. Reason: Typo

  • #3
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you, I changed vidurl=window.location to vidurl=location.href now I don't get that error about converting string.

    I have found another problem though.

    There appears to be a 100ms limit for setTimeout. This limit doesn't give me enough time to load all the page so when I try to getElementById('Math') it is null.

    example

    works -> javascript:location.href="http://clipnabber.com";setTimeout("alert('HI')",10);
    works -> javascript:location.href="http://clipnabber.com";setTimeout("alert('HI')",100);
    don't see alert box -> javascript:location.href="http://clipnabber.com";setTimeout("alert('HI')",1000);

    Is there a possible workaround for this?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,079
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    [QUOTE=rig99;817570]There appears to be a 100ms limit for setTimeout. [QUOTE]

    There is no limit to the number of milliseconds in setTimeout().
    But when you change the location of the page the content of the previous page is lost. It looks as though it takes 100ms or so for the change to take place.

  • #5
    New to the CF scene
    Join Date
    May 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Very good information

  • #6
    New to the CF scene
    Join Date
    May 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So then is what I'm wanting to do even possible?

    My goal is to be able to click the bookmarklet when I'm on a site that has the video embedded in it, then get the "Math" code from clipnabber's homepage, and finally have the video site's url and the "Math" code sent to clipnabber's script.

    So far none of my methods have worked. I've tried pausing script execution with setTimeout to delay my code so the clipnabber homepage has time to load fully. That doesn't work because, like Phillip says, the script is gone once the clipnabber homepage loads. I've also tried loading the clipnabber homepage into an iframe on the video's page. The problem with that is I can't get any info from the iframed page so I can't get the "Math" code I need.

    I find it very hard to believe something like this is impossible because it seems so simple to do. Store current URL, load new page, store a variable from new page, create URL with stored URL and stored variable as arguments. Honestly I thought this would take me no time at all, but here I am on day 5 and still have no solution.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •