如果有剪贴板的每一行都可以用AutoHotkey(Chrome)在同一个窗口中以url的形式打开,但要延迟,如何在各个标签页中打开?

问题描述 投票:1回答:1

我想在Google Images中进行多次搜索。我知道有这样的东西

clipboard := StrReplace(clipboard, "+", "%2B")

但怎么可能呢?下面是一次性搜索的相关代码。

url_encoding(str)
{
  f = %A_FormatInteger%
  SetFormat, Integer, Hex
  if RegExMatch(str, "^\w+:/{0,2}", pr)
    StringTrimLeft, str, str, StrLen(pr)
  StringReplace, str, str, `%, `%25, All
  Loop
    if RegExMatch(str, "i)[^\w\.~%/:]", char)
      StringReplace, str, str, %char%, % "%" . SubStr(Asc(char),3), All
    else break
  SetFormat, Integer, %f%
  return, pr . str
}


F3::
image_search:
a = `%
old_clipboard := ClipboardAll
clipboard := url_encoding(clipboard)
Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2" --force-wave-audio --incognito --new-window https://www.google.com/search?tbm=isch&as_q=%clipboard%, , Max
clipboard := old_clipboard
return

从%clipboard%到%A_LoopField%的变化,导致该 https:/www.google.comimghp?tbm=isch&as_q=。 是在搜索abc时打开的。于是我添加了解析Loop。

F3::
image_search:
a = `%
old_clipboard := ClipboardAll
Loop, parse, clipboard, `n, `r
{
  clipboard := url_encoding(clipboard)
  Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2" --force-wave-audio --incognito --new-window https://www.google.com/search?tbm=isch&as_q=%A_LoopField%, , Max
}
clipboard := old_clipboard
return

当我打开

abc
123

的搜索查询都在一个新的窗口中打开。但这些查询应该只在一个新窗口中打开。我们的目标是排除空行(也有空格)以及搜索查询前后的空格。一旦这样做了,就可以使用url_encoding来执行正确的搜索。在所有这些情况下,刚才提到的代码都没有工作。例如,如果

 abc & def       


123 % 456   

在剪贴板中,一个新的隐身窗口应该会显示出

abc & def

在表1中和

123 % 456

在标签2中。

regex url macros autohotkey clipboard
1个回答
0
投票

url_encoding()添加的换行符为

%D%A

因为他们没有被排除在外。

解决办法

url_encoding(str)
{
  f = %A_FormatInteger%
  SetFormat, Integer, Hex
  if RegExMatch(str, "^\w+:/{0,2}", pr)
    StringTrimLeft, str, str, StrLen(pr)
    StringReplace, str, str, `%, `%25, All
  Loop
    if RegExMatch(str, "i)[^\w\.~%/:\r\n]", char)
      StringReplace, str, str, %char%, % "%" . SubStr(Asc(char),3), All
    else break
  SetFormat, Integer, %f%
  return, pr . str
}


F3::
image_search:
old_clipboard := ClipboardAll
clipboard := RegExReplace(clipboard, "`am)^\s+")
clipboard := RegExReplace(clipboard, "`am)\s+$")
clipboard := url_encoding(clipboard)
Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2" --force-wave-audio --incognito --new-window, , Max
Sleep, 1000
Loop, parse, clipboard, `n, `r
{
  Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" --profile-directory="Profile 2" --force-wave-audio --incognito https://www.google.com/search?tbm=isch&as_q=%A_LoopField%, , Max
  Sleep, 500
}
clipboard := old_clipboard
return
© www.soinside.com 2019 - 2024. All rights reserved.