Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- topicsFile := "topics.txt"
- lastTopicFile := "last_topic.txt"
- topics := []
- ^!s:: { ; Ctrl + Alt + S
- inputObj := MultilineInput("Batch Topic Search", "Enter one query per line:")
- if !inputObj || inputObj.queries = ""
- return
- WinActivate("ahk_exe msedge.exe")
- queries := StrSplit(inputObj.queries, "`n")
- topic := inputObj.topicCode
- for query in queries {
- cleanQuery := Trim(query)
- if cleanQuery = ""
- continue
- Run("msedge.exe --new-tab edge://newtab/") ; Launch Edge or open a new tab
- WinWaitActive("ahk_exe msedge.exe", , 5)
- Sleep(300) ; Wait a bit to ensure tab is ready
- Send(cleanQuery . " " topic)
- Sleep(50)
- Send("{Enter}")
- Sleep(50)
- }
- total := queries.Length
- if total > 1 {
- Sleep(100)
- Loop total - 2 {
- Send("^+{Tab}") ; Ctrl+Shift+Tab to move left
- Sleep(50)
- }
- }
- }
- LoadTopics(default := "Blender") {
- global topicsFile
- if !FileExist(topicsFile) {
- SaveTopics(default)
- return default
- }
- content := FileRead(topicsFile)
- return StrSplit(Trim(content), "|")
- }
- SaveTopics(topicList) {
- global topicsFile
- File := FileOpen(topicsFile, "w", "UTF-8")
- joinedTopics := ""
- for i, topic in topicList {
- joinedTopics .= topic . (i = topicList.Length ? "" : "|")
- }
- if File {
- File.Write(joinedTopics)
- File.Close()
- }
- }
- SaveLastTopic(topic) {
- File := FileOpen(lastTopicFile, "w", "UTF-8")
- if File {
- File.Write(topic)
- File.Close()
- }
- }
- LoadLastTopic(default := "Blender") {
- if FileExist("last_topic.txt") {
- topic := Trim(FileRead("last_topic.txt"))
- return topic != "" ? topic : default
- }
- return default
- }
- MultilineInput(title := "Input", prompt := "Enter text:") {
- global topics := LoadTopics()
- ih := InputHook("L1 V", "{Enter}{Escape}")
- ih.KeyOpt("{Enter}", "N") ; Don’t auto-complete on Enter
- ih.KeyOpt("{Escape}", "N") ; Don’t auto-complete on Escape
- result := ""
- topic := ""
- myGui := Gui("+AlwaysOnTop +ToolWindow", title)
- myGui.SetFont("s10")
- myGui.Add("Text",, prompt)
- edit := myGui.Add("Edit", "r10 w400 vInputEdit WantTab") ; WantTab allows Tab chars
- myGui.Add("Text",, "Topic:")
- defaultTopic := LoadLastTopic()
- defaultIndex := 1
- for i, topic in topics {
- if (topic = defaultTopic) {
- defaultIndex := i
- break
- }
- }
- ddl := myGui.Add("DropDownList", "vTopicDDL Choose" defaultIndex, topics)
- removeBtn := myGui.Add("Button", "x+10 yp w150", "Remove Selected")
- myGui.Add("Text", "XM", "New Topic:")
- newTopicInput := myGui.Add("Edit", "x+10 yp w200 vNewTopicInput")
- addBtn := myGui.Add("Button", "x+10 yp w80", "Add Topic")
- addBtn.OnEvent("Click", AddNewTopic)
- AddNewTopic(btn, info) {
- newTopic := Trim(newTopicInput.Value)
- if newTopic = ""
- return
- for topic in topics
- if newTopic = topic
- return
- topics.Push(newTopic)
- SaveTopics(topics)
- ddl.Delete()
- ddl.Add(topics)
- ddl.Value := topics.Length ; Select the new one
- newTopicInput.Value := "" ; Clear the input box
- }
- removeBtn.OnEvent("Click", RemoveTopic)
- RemoveTopic(btn, info) {
- if topics.Length = 0 {
- return
- }
- topics.RemoveAt(ddl.Value)
- SaveTopics(topics)
- ddl.Delete()
- ddl.Add(topics)
- if topics.Length = 0 {
- return
- }
- ddl.Value := 1
- }
- myGui.Show()
- Loop {
- ih.Start()
- ih.Wait()
- if ih.EndKey = "Escape" {
- result := ""
- break
- } else if ih.EndKey = "Enter" {
- if !GetKeyState("Shift", "P") {
- result := edit.Value
- selectedTopic := ddl.Text
- break
- }
- }
- }
- selectedTopic := ddl.Text
- SaveLastTopic(selectedTopic)
- myGui.Hide()
- myGui.Destroy()
- return { queries: result, topicCode: selectedTopic}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement