StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Register | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Lua Scripts
 General Action Scripts
 search in the current Website
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

defpt

18 Posts

Posted - 02/17/2013 :  05:27:14  Show Profile  Reply with Quote
I want to do a gestures for search in the current Website, so it is necessary to obtain the domain name. Is there a function to achieve this purpose?
Thank you very much Rob. The following is the improved Script for search in the current Website:Search for the selected text, or display an inputbox for input string

--Search in this website
function acINSearch(x)
acSetClipboardText("") --clear Clipboard
acSendKeys("%d") --focus on the urlbar
acSendKeys("^c")
acDelay(25)
url = acGetClipboardText()
domain=string.gsub(url,"https?://(.-)%/.*","%1") --Get Domainname
acDelay(25)
newurl="https://www.google.com/search?hl=zh-CN&client=opera&q=site:"..domain.."%20"..x --Search engine, her is for Chinese
acSetClipboardText(newurl)
acSendKeys("^v")
acSendKeys("{DELAY=25}%{ENTER}")
end
acSetClipboardText("")
acSendKeys("^c")
acDelay(50)
text=acGetClipboardText()
if text ~= "" then acINSearch(text)
else inputString= acInputBox("Google Search", "Please enter the string you want to search", "")
if inputString ~= "" then acINSearch(inputString) end
end

Edited by - defpt on 02/18/2013 01:24:06

defpt

18 Posts

Posted - 02/17/2013 :  05:30:00  Show Profile  Reply with Quote
or

How can I use "location.hostname" directly?
Go to Top of Page

defpt

18 Posts

Posted - 02/17/2013 :  09:53:46  Show Profile  Reply with Quote
I can only complete it by string functions. such as:

function acGetDomain()
acSetClipboardText("")
acSendKeys("%d")
acSendKeys("^c")
acDelay(50)
local s = acGetClipboardText()
local i,j=string.find(s,"//.-%/")
i=i+2
j=j-1
return string.sub(s, i, j)
end

Edited by - defpt on 02/17/2013 13:40:35
Go to Top of Page

Rob

USA
2591 Posts

Posted - 02/17/2013 :  09:55:14  Show Profile  Visit Rob's Homepage  Reply with Quote
Unfortunately you cannot access location.hostname since that's within the javascript engine of the browser, not something exposed to other applications.

This script worked for me to navigate to the root of the current website:
acSendKeys("^l") --goto address bar
acDelay(25)
acSendKeys("^c") --copy URL
acDelay(25)
url=acGetClipboardText() --get the URL from the clipboard
new_url=string.gsub(url,"([http://|https://]+[A-Za-z0-9.]*/+).*","%1") --strip out only root address
acSetClipboardText(new_url) --save the new URL to the clipboard
acDelay(25)
acSendKeys("^v") --paste the URL in the address bar
acDelay(25)
acSendKeys("{ENTER}") --send Enter key
Go to Top of Page

defpt

18 Posts

Posted - 02/17/2013 :  14:13:55  Show Profile  Reply with Quote
Thank you very much anyway. :-)กก
I think this and the above are the same principle. I would have thought that, S+ can directly access location.hostname :-P
After learning your string.gsub usage, my function to improve:

acSetClipboardText("")
acSendKeys("%d")
acSendKeys("^c")
acDelay(25)
local url = acGetClipboardText()
acDelay(25)
local domain=string.gsub(url,"https?://(.-)%/.*","%1")

Edited by - defpt on 02/17/2013 14:30:19
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000