Action

Google it with natural language

Posted by Minja, Last update over 5 years ago - Unlisted

made by @minja
my website: https://github.com/BlackwinMin

Steps

  • script

    var searchQuery = draft.title
    
    //检查日期参数
    var regDate = /\s[y|m|w|d|h|n][0-9]+/
    if (regDate.exec(searchQuery)){
    	var dateQuery = "&tbs=qdr:" + regDate.exec(searchQuery).join().substring(1)
    }
    else {
    	var dateQuery = ""
    }
    
    //检查日期范围参数
    var regDaterange = /\s[0-9]{4}-[0-9]{2}-[0-9]{2}/g
    if (searchQuery.match(regDaterange)){
    	var daterangeQuerytemparray = searchQuery.match(regDaterange)
    	var daterangeQuerytempstart = daterangeQuerytemparray[0].substring(1)
    	var daterangeQuerytempend = daterangeQuerytemparray[1].substring(1)
    	var daterangeQuery = "after:" + daterangeQuerytempstart + " before:" + daterangeQuerytempend
    }
    else {
    	var daterangeQuery = ""
    }
    
    //检查语言参数
    var regLanguageCN = /\s中文/
    var regLanguageEN = /\s英文/
    if (searchQuery.match(regLanguageCN)){
    	var langQuery = "&lr=lang_zh-CN"
    }
    else if (searchQuery.match(regLanguageEN)){
    	var langQuery = "&lr=lang_en"
    }
    else {
    	var langQuery = ""
    }
    
    var pureQuery = searchQuery.replace(regDate,'').replace(regDaterange, '').replace(regLanguageCN,'').replace(regLanguageEN,'')
    
    var searchURL = "https://www.google.hk/search?q=" + daterangeQuery + pureQuery + dateQuery + langQuery
    let encodeURI_url = encodeURI(searchURL)
    
    draft.setTemplateTag("jsResult",encodeURI_url)
  • url

    template
    [[jsResult]]
    useSafari
    true
    encodeTags
    false

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.