Skip to content

Instantly share code, notes, and snippets.

@stuncloud
Last active December 1, 2019 03:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stuncloud/8e1dbd0e8a1a2e3ac060d651e35823a6 to your computer and use it in GitHub Desktop.
Save stuncloud/8e1dbd0e8a1a2e3ac060d651e35823a6 to your computer and use it in GitHub Desktop.
Chromeのブックマークをpopupmenuにする
module BookMarkToPupup
hashtbl url
dim delimiter = chr(11)
function GetUrl(title)
if pos("{", title) = 1 then
title = betweenstr(title, "{")
endif
if pos("}", title, -1) = length(title) then
title = betweenstr(title, , "}", -1)
endif
result = url[title]
fend
function Generate(bookmarkdoc)
url = HASH_REMOVEALL
htmlfile = createoleobj("htmlfile")
htmlfile.write(bookmarkdoc)
topdl = htmlfile.documentElement.document.getElementsByTagName("dl").item(0)
menustr = EMPTY
parser(menustr, topdl)
result = split(menustr, delimiter, TRUE, FALSE)
fend
procedure parser(var str, dl, depth = 0)
tmp = EMPTY
for elem in dl.childNodes()
if length(tmp) then
tmp = tmp + delimiter
endif
select elem.tagName
case "dt"
select elem.firstChild.TagName
case "h3"
tmp = tmp + elem.firstChild.innerText
dl2 = elem.getElementsByTagName("dl")
if dl2.length then
parser(tmp, dl2.item(0), depth + 1)
endif
case "a"
tmp = tmp + elem.firstChild.innerText
url[elem.firstChild.innerText] = elem.firstChild.href
selend
case "dl"
selend
next
if depth then
str = str + delimiter + "{" + tmp + "}"
else
str = str + delimiter + tmp
endif
fend
endmodule
fid = fopen("bookmarks_20xx_xx_xx.html", F_READ)
html = fget(fid, F_ALLTEXT)
fclose(fid)
// popupmenu用の配列を返す
menu = BookMarkToPupup.Generate(html)
i = popupmenu(menu)
if i > -1 then
// 配列の要素をBookMarkToPupup.GetUrlに渡すと対応するURLを返す
input(menu[i], BookMarkToPupup.GetUrl(menu[i]))
endif
// 注意
// BookMarkToPupup.GetUrlはブックマークタイトルが同じでURLが違うものがあるとどちらかのURLしか返せません
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment