目次
テキストブラウズ
[編集]
text_browse.vbs
1 | Dim uri
2 | uri = Editor.GetSelectedString(0)
3 | If uri = "" Then
4 | uri = "http://www.yahoo.co.jp/"
5 | Else
6 | If Left(uri, 7) <> "http://" And InStr(uri, "/") > 0 Then
7 | Editor.GoFileTop()
8 | Editor.GoLineEnd_Sel(0)
9 | uri = Right(uri, Len(uri) - InStr(uri, "/"))
10 | uri = Editor.GetSelectedString(0) & uri
11 | End If
12 | End If
13 |
14 | Editor.SelectAll()
15 | Editor.InsText(uri & " を読み込み中...")
16 | Editor.GoFileTop()
17 | Editor.ReDraw()
18 |
19 | Dim ie
20 | Set ie = CreateObject("InternetExplorer.Application")
21 |
22 | If Not ie Is Nothing Then
23 | ie.Visible = False
24 | ie.Navigate(uri)
25 |
26 | Do While ie.Busy
27 | Loop
28 |
29 | Dim body
30 |
31 | body = uri & vbCrLf
32 | body = body & ie.document.title & vbCrLf
33 | body = body & "------------------------------------------------------------" & vbCrLf
34 | body = body & get_html(ie.Document.Body.childNodes, "")
35 |
36 | Editor.SelectAll()
37 | Editor.InsText(body)
38 | Editor.GoFileTop()
39 | Editor.ReDraw()
40 |
41 | ie.Quit()
42 | End If
43 |
44 | Function get_html(ByVal document, ByVal margin)
45 | Dim v
46 |
47 | For Each v In document
48 |
49 | Select Case TypeName(v)
50 | Case "HTMLBRElement":
51 | get_html = get_html & vbCrLf & margin
52 | Case "DispHTMLDOMTextNode":
53 | Dim dv, prev_dv
54 | dv = Trim(v.data)
55 | Do
56 | prev_dv = dv
57 | dv = Replace(dv, " ", " ")
58 | Loop While dv <> prev_dv
59 |
60 | If dv <> "" Then get_html = get_html & dv
61 | Case "HTMLAnchorElement":
62 | get_html = get_html & get_html(v.childNodes, margin)
63 | get_html = get_html & "<""" & v.href & """>"
64 | Case Else:
65 | Dim indent
66 | indent = ""
67 |
68 | Select Case v.tagName
69 | Case "P", "DIV", "TABLE", "TR", _
70 | "H1", "H2", "H3", "H4", "H5", "H6", "H7", _
71 | "UL", "OL", _
72 | "SELECT", "TEXTAREA":
73 | indent = Space(2)
74 | get_html = get_html & vbCrLf & margin & indent
75 | Case "TD", "LI", "OPTION":
76 | get_html = get_html & vbCrLf & margin
77 | End Select
78 |
79 | get_html = get_html & get_html(v.childNodes, margin & indent)
80 |
81 | If indent <> "" Then get_html = get_html & vbCrLf & margin
82 | End Select
83 | Next
84 | End Function