April 7, 2021

Quick Google Site Search in the Browser

I have extended the NWS PowerTool Quick Search feature: you can now in a browser quickly fire a Google search that restricts the results to the current site.

Screencast

Usage

Once the NWS PowerTool is running, you can trigger the QuickSearch feature when a browser window is active by using the hotkey Win+F (F like Find)
Alternatively you can only remember Win+F1 to open the NWS PowerTool Browser action menu.

Implementation

This is implemented in the NWS.ahk file.

The key code part is in the QuickSearch function:

QuickSearch(){

sUrl := GetActiveBrowserUrl()
If !sUrl { ; empty
    MsgBox Cannot get URL ; DBG
    return
}
If Connections_IsUrl(sUrl) 
    ConnectionsSearch(sUrl)
Else If Blogger_IsUrl(sURL) 
    Blogger_Search(sURL)
Else If Confluence_IsUrl(sUrl) 
    Confluence_Search(sUrl)
Else If Jira_IsUrl(sUrl)
    Jira_Search(sUrl)
Else {
    sPat = google.com/search\?q=site:([^`%]*)`%20 ; Chrome strips https://www. for google
    sPat := StrReplace(sPat,".","\.")
    If RegExMatch(sUrl,sPat . "(.*)", sMatch) { ; https://www.google.com/search?q=site:https://scaledagileframework.com%20pipeline
        sDefSearch := StrReplace(sMatch2,"%20"," ")
        sRootUrl := sMatch1
        ;SendInput ^w ; close current search window
    } Else {
        RegExMatch(sUrl,"https?://[^/]*",sRootUrl)
    }
    InputBox, sSearch , Google Site Search, Enter search string:,,640,125,,,,, %sDefSearch%
    if ErrorLevel
        return
    sSearch := Trim(sSearch)
    
    sSearchUrl = https://www.google.com/search?q=site:%sRootUrl% %sSearch%
    SendInput ^t^l ; close current search window
    Clip_Paste(sSearchUrl)
    SendInput {Enter}
    SendInput ^{Tab}
    Sleep 500
    SendInput ^w
    Run, "%sSearchUrl%"
}   
} ; eofun

See also

How to Search Any Site from Chrome’s Address Bar

NWS PowerTool Homepage 

No comments:

Post a Comment