StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Can s + net get the loading status of the window?
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 Location: 北京 Thanks: 18 times Was thanked: 1 time(s) in 1 post(s)
|
Similar to 'document. ReadyState', I want to make sure that s + net starts executing a script after the page is loaded. Thank you.
|
|
|
|
Rank: Administration
Groups: Translators, Members, Administrators Joined: 1/11/2018(UTC) Posts: 1,349 Location: Tampa, FL Thanks: 28 times Was thanked: 416 time(s) in 354 post(s)
|
If you're referring to a web page in the browser, there's no direct way for S+ to look inside the browsers code to know that. You can usually find a way to make this work, but it can be a little bit of trial and error to get it just right. For example, I have this script which I run to log into my bank's website. Read the comments in the script for an explanation of how it works. Code: sp.SendKeys("my_bank_username~");
sp.StoreHandle("BankName", action.Window.HWnd);
sp.CreateTimer("BankNameTimer",
1000,
-1,
String.raw`var ct = 0;
var wnd = sp.WindowFromHandle(sp.GetStoredHandle("BankName"));
//Wait until the tital of the window changes to the banking login area
while(wnd.Title.indexOf("Bank_Website_Partial_Title") == -1){
sp.Sleep(500);
ct++;
if(ct > 20){
//If more than 20 attempts (10 seconds), just try to continue anyway
break;
}
}
ct = 0;
//Get the pixel color from the CENTER of the Chrome Stop/Refresh icon
//While the page is loading, the center of the icon is a different color since it's an "X"
//instead of the Refresh icon, which is a like a circle
var bclr = sp.GetPixelColorFromPoint(new Point(85,50));
//While the color is NOT the standard theme color (because the page is loading and the icon is the "X"
//keep witing
while(bclr.B != 87 && bclr.G != 87 && bclr.R != 87) {
sp.Sleep(500);
ct++;
if(ct > 20){
break;
}
bclr = sp.GetPixelColorFromPoint(new Point(85,50));
}
bclr = sp.GetPixelColorFromPoint(new Point(85,50));
//If the pixel color is the same as the other theme background colors, then it must be
//showing the Refresh icon, meaning the page is finished loading
if(bclr.B == 87 && bclr.G == 87 && bclr.R == 87) {
//Send the Enter key to login (Chrome autofills the password)
sp.SendKeys("~");
}
//Clean up - remove the timer and stored handle
sp.DeleteStoredHandle("BankName");
sp.DeleteTimer("BankNameTimer");`
);
|
|
|
|
Rank: Advanced Member
Groups: Approved
Joined: 9/26/2018(UTC) Posts: 73 Location: 北京 Thanks: 18 times Was thanked: 1 time(s) in 1 post(s)
|
|
|
|
|
StrokesPlus.net Forum
»
General Discussion
»
Scripts
»
Can s + net get the loading status of the window?
Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.
Important Information:
The StrokesPlus.net Forum uses cookies. By continuing to browse this site, you are agreeing to our use of cookies.
More Details
Close