StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
StrokesPlus Fan  
#1 Posted : Saturday, June 27, 2020 1:30:05 AM(UTC)
StrokesPlus Fan

Rank: Newbie

Reputation:

Groups: Approved
Joined: 6/26/2020(UTC)
Posts: 2

Thanks: 1 times
Hi, Everyone!

I have used StrokesPlus for some years and I am new to StrokesPlus.net.
Would you tell me how to write a script which can navigate to a parent directory (URL) of a webpage?
(Example: https://abc.def/ghi/jkl/ -> https://abc.def/ghi/ )

The script for StrokesPlus was like this (Lua Script):

acActivateWindow(nil, gex, gey)
acSendKeys("^l{DELAY 50}^c")
url=acGetClipboardText()
new_url=string.gsub(url,"(.+)/.+/?","%1")
acSetClipboardText(new_url)
acSendKeys("^v{DELAY 50}{ENTER}")

Thanks in advance.
Rob  
#2 Posted : Saturday, June 27, 2020 4:14:49 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 667
United States

Thanks: 13 times
Was thanked: 149 time(s) in 130 post(s)
Haven't tested this with a large variety of URLs, but it seems like it should be good.
Code:
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_L]); //Control+L
sp.Sleep(40);
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_C]); //Control+C
//Take URL from clipboard and remove last segment, then save result to clipboard
clip.SetText(clip.GetText().split("/").slice(0,-1).join("/")); 
sp.SendModifiedVKeys([vk.LCONTROL], [vk.VK_V]); //Control+V
sp.SendVKey(vk.RETURN); //Enter

Edited by user Saturday, June 27, 2020 4:15:41 AM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
StrokesPlus Fan on 6/27/2020(UTC)
StrokesPlus Fan  
#3 Posted : Saturday, June 27, 2020 7:46:58 AM(UTC)
StrokesPlus Fan

Rank: Newbie

Reputation:

Groups: Approved
Joined: 6/26/2020(UTC)
Posts: 2

Thanks: 1 times
Rob, thank you for your quick reply!
Your script worked well in my environment.
I got occasional error (related to Text? Null?, I could not understand),
but it was not a big problem.
I'll try to learn more about JavaScript and your code by myself.
Anyway, thanks for your help!
Rob  
#4 Posted : Sunday, June 28, 2020 7:36:41 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 667
United States

Thanks: 13 times
Was thanked: 149 time(s) in 130 post(s)
Let me know what the error is next time it happens. Odds are it may be a timing issue - for example it didn't get to copy the URL or something in time before it tried to parse the string from the clipboard.

We may need to increase the delay or add in some other logic to check and catch those conditions, etc. Or it might be that the URL didn't have enough "/" in it, like http://abc.com/test so it had trouble parsing off the last directory.

Edited by user Sunday, June 28, 2020 7:38:21 AM(UTC)  | Reason: Not specified

Users browsing this topic
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.