javascript scripts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • colore
    New Member
    • Mar 2007
    • 6

    #1

    javascript scripts

    hello

    I would like to hit a keyboard shortcut
    and parse the current webpage and then do stuff in the
    webpage (eg autosave links that contain a specific
    string, autosave images, autoclick specific buttons
    etc etc)

    can you tell me how to do that?

    I use Opera Browser

    thanks
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Welcome to TSDN.

    For keyboard shortcuts, see this example. It gives you the keycode of the key pressed. You can also see this ref. for alt/shift/ctrl keys.

    You can simulate button clicks with the click() method, see link.

    Comment

    • colore
      New Member
      • Mar 2007
      • 6

      #3
      thanks

      can you give me a guided example of a script that will recognize a button and click it whenever it appears (whenever I visit a webpage that it contains it) ?

      thanks

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        You could look for all input elements:
        Code:
        var allInput = document.getElementsByTagName("input");
        and check for their type. If it's button, then call the click() method.

        Comment

        • colore
          New Member
          • Mar 2007
          • 6

          #5
          ummm

          can you tell me the script that whenever I visit google.com it will autoput "something" inside the search form, it will select and then it will autoclick the "I am feeling lucky button" ?

          thanks

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            Look at the source code of the page. Find the name or id of the search box and likewise for the button. Then it should be trivial to set the value and click the button respectively.

            Comment

            • colore
              New Member
              • Mar 2007
              • 6

              #7
              Originally posted by acoder
              Look at the source code of the page. Find the name or id of the search box and likewise for the button.
              this is the easy part...

              Originally posted by acoder
              Then it should be trivial to set the value and click the button respectively.
              this is the hard part... :S

              can you give me an example?

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                Say the id is "searchbox" , then:
                Code:
                document.getElementById("searchbox").value='the value to set';
                If the id for the button is "searchButt on", then to click:
                Code:
                document.getElementById("searchButton").click();

                Comment

                • colore
                  New Member
                  • Mar 2007
                  • 6

                  #9
                  thanks much appreciated

                  so to autoclick google search button whenever I visit google.com, I should use this script:

                  Code:
                  document.addEventListener('DOMContentLoaded',function() {
                  document.getElementById("btnG").click();
                  }
                  but it doesnt work :s

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    Is this Google page in an iframe? You need to access the iframe first, see this page.

                    Comment

                    • colore
                      New Member
                      • Mar 2007
                      • 6

                      #11
                      Originally posted by acoder
                      Is this Google page in an iframe? You need to access the iframe first, see this page.
                      no its the simple www.google.com webpage

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        Originally posted by colore
                        no its the simple www.google.com webpage
                        Well, in that case, it shouldn't be possible, but since you're using Opera, you can use something called User Javascript, see link.

                        Comment

                        Working...