Get the links posts from topic (Macscripter.net)

This Script will use document 1 of Safari on Macscripter.net.
To build a list of post in current topic list.

Choose from list {Subject:Post number #} to be open in your Script Editor.

EDIT: Made update if ((item i of theLinks) contains “applescript://”) then

set theDocumentLinks to "function documentLinks() {
//
var arr = [], links = document.links;
for(var i = 0; i < links.length; i++) {
	arr.push(links[i].href);
}
return arr
}
//
documentLinks()
"

tell application "Safari"
	set theTitle to (its name in document 1)
	set theTitle to text 15 thru -1 of theTitle & ":" & space
	set theLinks to do JavaScript theDocumentLinks in document 1
end tell

set appleScriptLinks to {}
repeat with i from 1 to (count theLinks)
	if ((item i of theLinks) contains "applescript://") then
		set theItem to item i of theLinks
		copy theItem to end of the appleScriptLinks
	end if
end repeat

set postCount to count appleScriptLinks

set postList to {}
repeat with i from 1 to postCount
	set theText to theTitle & "Post number " & i
	copy theText to end of the postList
end repeat

set theIndex to (choose from list postList) as text
try
repeat with i from 1 to (count theIndex)
	if (theIndex = theTitle & "Post number " & i) then
		set theSource to quoted form of (item i of appleScriptLinks)
	end if
end repeat

do shell script "open -a \"Script Editor\" " & theSource
end try