Jump to content

AutoIt/javascript experiment


Gianni
 Share

Go to solution Solved by mikell,

Recommended Posts

I wrote this experiment using AutoIt/javascript just to learn by testing; it load all online members's avatars and shows those images on the web page;

then set a javascript script to be fired on the OnClick event that moves all the images on the web page;

I have 2 questions:

1) any time I click the page, the speed of moving increases. How to avoid it?

2) to start the image motion, of course I have to click on the page. How can I start the motion just after finishing the load of the images instead of clicking? (already tested with OnLoad without success)

Thanks for suggestions

#include <IE.au3>
Local $sExt[3] = ["jpg", "png", "gif"]
Local $oIE = _IECreate("http://www.autoitscript.com/forum/")
Local $oLinks = _IELinkGetCollection($oIE)
; _IEBodyWriteHTML($oIE, "<html><body>Just a moment please</body></html>"&@CRLF)
Local $sUrl, $sCheckUrl
For $oLink In $oLinks
    ; 'http://www.autoitscript.com/forum/user/
    If StringInStr($oLink.href, "http://www.autoitscript.com/forum/user/") Then
        $sCheckUrl = 'http://static1.autoit-cdn.com/forum/uploads/profile/photo-' & StringMid($oLink.href, 40, StringInStr($oLink.href, "-") - 40) & '.'
        If Not StringInStr($sUrl, $sCheckUrl) Then ; avoid duplicates
            Select
                Case InetGetSize($sCheckUrl & $sExt[0]) ; jpg
                    $sUrl &= '<img src=' & $sCheckUrl & $sExt[0] & ' />' & @CRLF
                Case InetGetSize($sCheckUrl & $sExt[1]) ; png
                    $sUrl &= '<img src=' & $sCheckUrl & $sExt[1] & ' />' & @CRLF
                Case InetGetSize($sCheckUrl & $sExt[2]) ; gif
                    $sUrl &= '<img src=' & $sCheckUrl & $sExt[2] & ' />' & @CRLF
            EndSelect
        EndIf
    EndIf
Next
 _IEBodyWriteHTML($oIE, $sUrl)

; javascript
 $js = 'R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length;' & _
        "function A(){for(i=0; i-DIL; i++){DIS=DI[i].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+" & _
        '"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}' & _
        "setInterval(A ,50); void(0);"
        ConsoleWrite($js&@CRLF)

_IEHeadInsertEventScript($oIE, "document", "onclick",  $js)

edit:

if you are not logged on the site, this script will not work

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

$oIE.document.parentwindow.execscript("javascript:" & $js)

funny script  :)

 

Thanks mikell for the javascript method to inject and execute the script in the web page.

The javascript is not mine, but I found somewhere on the web.

Here a (funny) simplified script that use your method to execute the javascript

Thanks a lot.

#include <IE.au3>
Local $oIE = _IECreate("http://www.123greetings.com/flowers/")

; javascript
$js = 'R=0; x1=.1; y1=.05; x2=.25; y2=.24; x3=1.6; y3=.24; x4=300; y4=200; x5=300; y5=200; DI=document.getElementsByTagName("img"); DIL=DI.length;' & _
        "function A(){for(i=0; i-DIL; i++){DIS=DI[i].style; DIS.position='absolute'; DIS.left=(Math.sin(R*x1+i*x2+x3)*x4+x5)+" & _
        '"px"; DIS.top=(Math.cos(R*y1+i*y2+y3)*y4+y5)+"px"}R++}' & _
        "setInterval(A ,50); void(0);"
; inject script inpage
$oIE.document.parentwindow.execscript("javascript:" & $js)

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...