Skip to content

Commit 74ee1ee

Browse files
authored
Update HyperSearch.ahk
Improved import functions to convert illegal characters and block javascript functions as well as view items not in the Chrome "Bookmarks bar"
1 parent 333d893 commit 74ee1ee

File tree

1 file changed

+93
-5
lines changed

1 file changed

+93
-5
lines changed

HyperSearch.ahk

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,7 @@ return
886886

887887
ImportChrome:
888888
replace:=0
889+
otherChk:=0
889890
search:=StrSplit(UsrIn,">",,2)
890891
MsgBox, 3, Import options, How would you like to import?`nYes: Append to current links`nNo: Replace all links with bookmarks
891892
IfMsgBox, No
@@ -930,8 +931,13 @@ ImportChrome:
930931
numTabs := round(numTabs/4)
931932

932933
if (head == "H3") { ; New category
933-
RegExMatch(currentLine, "O)<H3 .*>(.*?)</H3>", thisCat)
934-
fullArray[catIndex,1]:=thisCat[1]
934+
RegExMatch(currentLine, "O)<H3 .*>(.*?)</H3>", catScan)
935+
thisCat:=catScan[1]
936+
if (thisCat == "Bookmarks bar") {
937+
;MsgBox, Ding
938+
thisCat := " Bookmarks bar"
939+
}
940+
fullArray[catIndex,1]:=thisCat
935941
nxtTab:=numTabs+1
936942
i:=A_Index+2
937943
subTabs:=numTabs+1
@@ -966,19 +972,86 @@ ImportChrome:
966972
RegExMatch(subLine, "O)<A HREF=""(.*?)""", subLink)
967973
RegExMatch(subLine, "O)<A .*>(.*?)</A>", subLabel)
968974
;MsgBox % "Current label: " . thisLabel[1] . "`nCurrent link: " . thisLink[1]
975+
;checkString:=subLabel[1]
969976
if (subLabel[1]!="") {
970-
labelReplace := StrReplace(subLabel[1], "|", "-")
977+
GoSub, CleanLabels
971978
} else {
972-
labelReplace := subLink[1]
979+
labelReplace := subLink[1]
980+
}
981+
checkLink:=subLink[1]
982+
;MsgBox % RegExMatch(checkLink, "javascript.*")
983+
if (RegExMatch(checkLink, "javascript.*") != 0) {
984+
;MsgBox, Ding
985+
checkLink := " "
973986
}
974987

975-
fullArray[catIndex,2] .= "[" . LabelReplace . "](" . subLink[1] . ")"
988+
fullArray[catIndex,2] .= "[" . labelReplace . "](" . checkLink . ")"
976989
}
977990
}
978991
i++
979992
}
980993
catIndex++
994+
} else if (head == "A " && numTabs == 1) {
995+
if (otherChk==0) {
996+
fullArray[catIndex,1]:=" Other bookmarks"
997+
otherChk:=1
998+
otherCat:=catIndex
999+
}
1000+
RegExMatch(currentLine, "O)<A HREF=""(.*?)""", subLink)
1001+
RegExMatch(currentLine, "O)<A .*>(.*?)</A>", subLabel)
1002+
;MsgBox % "Current label: " . thisLabel[1] . "`nCurrent link: " . thisLink[1]
1003+
;checkString:=subLabel[1]
1004+
if (subLabel[1]!="") {
1005+
GoSub, CleanLabels
1006+
} else {
1007+
labelReplace := subLink[1]
1008+
}
1009+
checkLink:=subLink[1]
1010+
;MsgBox % RegExMatch(checkLink, "javascript.*")
1011+
if (RegExMatch(checkLink, "javascript.*") != 0) {
1012+
;MsgBox, Ding
1013+
checkLink := " "
1014+
}
1015+
1016+
fullArray[otherCat,2] .= "[" . LabelReplace . "](" . checkLink . ")"
1017+
;catIndex++
1018+
nxtTab:=1
1019+
i:=A_Index+1
1020+
subTabs:=numTabs+1
1021+
while subTabs > numTabs ;&& i != bkmkLines.maxIndex()
1022+
{
1023+
;MsgBox % "Loop start`n" . subTabs . " > " . numTabs . "`n" . currentLine
1024+
subLine:=bkmkLines[i]
1025+
;MsgBox % subLine
1026+
subTabs:=0
1027+
subCharPos:=6
1028+
;MsgBox % subLine
1029+
Loop, Parse, subLine
1030+
{
1031+
if (A_LoopField == A_Space) {
1032+
subTabs++
1033+
subCharPos++
1034+
} else
1035+
break
1036+
}
1037+
subTabs := round(subTabs/4)
1038+
;MsgBox % subLine . " : " . subTabs
1039+
subHead:=SubStr(subLine,subCharPos,2)
1040+
;MsgBox % subTabs . " = " . nxtTab . "`n" . subLine . "`n" . currentLine
1041+
if (subTabs == nxtTab) {
1042+
;MsgBox % subHead
1043+
if (subHead=="H3") {
1044+
;MsgBox % subTabs . " : " . nxtTab
1045+
RegExMatch(subLine, "O)<H3 .*>(.*?)</H3>", subCat)
1046+
;MsgBox % thisCat[1] . " : " . numTabs . "`n" . subCat[1] . " : " . subTabs
1047+
fullArray[otherCat,2] .= "[<" . subCat[1] . ">](*)"
1048+
}
1049+
}
1050+
i++
1051+
}
1052+
catIndex++
9811053
}
1054+
9821055
}
9831056

9841057
if (replace==1)
@@ -1006,6 +1079,21 @@ ImportChrome:
10061079
fullArray := []
10071080
return
10081081

1082+
CleanLabels:
1083+
labelReplace := StrReplace(subLabel[1], "|", "-")
1084+
labelReplace := StrReplace(labelReplace, ")", "-")
1085+
labelReplace := StrReplace(labelReplace, "(", "-")
1086+
labelReplace := StrReplace(labelReplace, "[", "-")
1087+
labelReplace := StrReplace(labelReplace, "]", "-")
1088+
labelReplace := StrReplace(labelReplace, "`%5C", "\")
1089+
labelReplace := StrReplace(labelReplace, "+", A_Space)
1090+
labelReplace := StrReplace(labelReplace, "`%25", "`%")
1091+
labelReplace := StrReplace(labelReplace, "&amp;", "&")
1092+
labelReplace := StrReplace(labelReplace, "&gt;", ">")
1093+
labelReplace := StrReplace(labelReplace, "&#39;", "``")
1094+
labelReplace := StrReplace(labelReplace, "&#150;", "-")
1095+
return
1096+
10091097
ImportCSV:
10101098
replace:=0
10111099
search:=StrSplit(UsrIn,">",,2)

0 commit comments

Comments
 (0)