User
User

Reputation: 53

Auto hotkey script to open all the links of the questions form up to down on Math stackexchange

I'm trying to write an Auto hotkey script in order to open all the questions of a specific page of the Mathematics Stack Exchange site. It seems easy at first but I have some problems with doing that:

First I wanted to go on the upmost of the page by clicking on the up arrow:

^q::
click,1444,85,80
return

After this I planned to move the mouse by same distance then after clicking by middle button of the mouse it opens all the links on new tab, but the problem is that the distance between links of each question is not the same Hence I can't write the script that moves the mouse with the same distance (or scrolling with the same amount) vertically and click the middle button.

Also I tried to move between the links of questions by Tab button and open the links in new tabs by pressing Ctrl+Enter. but it also fails because by pressing the Tab it moves between all the links (containing Tags of each question) and because any question can have different number of Tags my scripts will fail with this method too.

So can you please help me to do that. Thanks in advance!


I forgot to mention that I chose lots of ignored tags on the site. (I hide the questions with those tags but if we want to get all the links of the questions on a page it may get the links of those questions too).

It is a huge list of those tags, Just in case if you need the list, ask me to add them in my post.

Upvotes: 1

Views: 148

Answers (1)

User
User

Reputation: 53

I asked my question on AutoHotkey site Here. And user @teadrinker wrote a perfect script that solved my problem:

^q::
ignored =
(
;Here is big list of my ignored tag
)
objIgnored := {}
Loop, parse, ignored, `n, `r
   objIgnored[A_LoopField] := ""

url := "https://math.stackexchange.com/questions"

Whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
Whr.Open("GET", url, false)
Whr.Send()
status := Whr.status
if (status != 200)
   throw "HttpRequest error, status: " . status

Arr := Whr.responseBody
pData := NumGet(ComObjValue(arr) + 8 + A_PtrSize)
length := arr.MaxIndex() + 1
html := StrGet(pData, length, "UTF-8")

Doc := ComObjCreate("htmlfile")
Doc.write("<meta http-equiv=""X-UA-Compatible"" content=""IE=9"">")
Doc.write(html)

summary := Doc.querySelectorAll("div.summary")
links := ""
Loop % summary.length {
   tags := summary[A_Index - 1].querySelectorAll("div.tags > a.post-tag")
   Loop % tags.length
      if objIgnored.HasKey( tags[A_Index - 1].innerText )
         continue 2
   Run, % link := StrReplace(summary[A_Index - 1].querySelector("a.question-hyperlink").href, "about:", "https://math.stackexchange.com",, 1)
   links .= link . "`n"
}
MsgBox, 4096,, % links ; this line to check which links were found and opened
Return

Upvotes: 1

Related Questions