www.webdeveloper.com
Results 1 to 5 of 5

Thread: Can you translate my pseudocode?

  1. #1
    Join Date
    Sep 2009
    Posts
    3

    Can you translate my pseudocode?

    Please help!
    I am making a simple Greasemonkey Script.
    Right now it does the following: (pseudocode)
    if {number of links on page > 0
    then {display: there are more links
    else { display: there are no links!

    Can I add to this a script that does the following?
    if {page contains word "apple"
    do the following
    -load www.domain.com/url1
    -then wait 10 seconds
    -load www.domain.com/url2
    else {do nothing

    Let me know if I need to clarify.
    Thanks!

  2. #2
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    Code:
    if(document.getElementsByTagName('a').length > NUMBER_HERE ){
      // how do you want to display your message?
    }else{
      // because that changes what to write here.
    }
    And
    Code:
    if(document.documentElement.textContent.indexOf('apple') != -1){
      location.href = 'www.domain.com/url1';
    }else{
      location.href = 'www.domain.com/url2';
    }
    You will have to explain what you mean by wait 10 seconds, javascript is reloaded when the page changes, so anything you attempt on the first page would be lost by the second page...
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

  3. #3
    Join Date
    Sep 2009
    Posts
    3
    Yep, I've already got the first part down; the part number of links and displaying messages. Got that. I'm talking about:
    If the current page has the word "apple" on it, go to URL1, wait a little bit, and then Go to URL2.

  4. #4
    Join Date
    Sep 2009
    Posts
    3
    Also, the javascript is running in greasemonkey, in the browser. Won't it consistently monitor the page and carry out functions over a multi-page action? If it was server-side I would understand that it couldn't, but it's not.
    To clarify, I want it to recognize if there is the word "apple" in the page content. If there is, I want to load domain.com/url1, and then load domain.com/url2.
    Incidentally, URL1 is the logout link, and URL2 is the original page.

  5. #5
    Join Date
    Jun 2003
    Location
    here
    Posts
    4,551
    Quote Originally Posted by iamthealex View Post
    Also, the javascript is running in greasemonkey, in the browser. Won't it consistently monitor the page and carry out functions over a multi-page action? If it was server-side I would understand that it couldn't, but it's not.
    To clarify, I want it to recognize if there is the word "apple" in the page content. If there is, I want to load domain.com/url1, and then load domain.com/url2.
    Incidentally, URL1 is the logout link, and URL2 is the original page.
    Unfortunately it doesn't work like that, greasemonkey scripts are run after any onload functions for the page, and that's it, anything else you want the code to do has to be done from within the greasemonkey scripts.
    You could do something like:
    Code:
    var url1 = 'domain.com/url1';
    var url2 = 'domain.com/url2';
    var secDelay = 10;// 10 seconds
    
    if(location.href == url1){
      window.setTimeout(function(){
        location.href = url2;
      }, secDelay*1000);
    }else
    if(document.documentElement.textContent.indexOf('apple') != -1){
      location.href = url1;
    }else{
      location.href = url2;
    }
    Which will always redirect from url1 after 10 secs.
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles