1 |
<!DOCTYPE HTML> |
2 |
<html lang=ja> |
3 |
<head> |
4 |
<title>$B@8$-$?(B URL $B2r7h1\Mw4o(B</title> |
5 |
<link rel=author href="http://suika.fam.cx/~wakaba/who?" title=Wakaba lang=ja> |
6 |
<style> |
7 |
h1 { |
8 |
font-size: 100%; |
9 |
} |
10 |
textarea { |
11 |
width: 90%; |
12 |
height: 3em; |
13 |
} |
14 |
iframe { |
15 |
visibility: hidden; |
16 |
width: 0; |
17 |
height: 0; |
18 |
} |
19 |
var { |
20 |
color: orange; |
21 |
} |
22 |
</style> |
23 |
<script> |
24 |
document.createElement ('output'); |
25 |
|
26 |
var updateTimer = 0; |
27 |
function update () { |
28 |
if (updateTimer) { |
29 |
clearTimeout (updateTimer); |
30 |
} |
31 |
updateTimer = setTimeout (realUpdate, 100); |
32 |
} // update |
33 |
|
34 |
function htescape (s) { |
35 |
return s.replace (/&/g, '&') |
36 |
.replace (/</g, '<') |
37 |
.replace (/>/g, '>') |
38 |
.replace (/"/g, '"'); |
39 |
} // htescape |
40 |
|
41 |
function htescape2 (s) { |
42 |
return s.replace (/&/g, '&') |
43 |
.replace (/</g, '<') |
44 |
.replace (/>/g, '>') |
45 |
.replace (/"/g, '"') |
46 |
.replace (/[\u0000-\u0020\u007F-\u00A0]/g, function (t) { |
47 |
return '<var>&#x' + t.charCodeAt (0).toString (16).toUpperCase () + ';</var>'; |
48 |
}); |
49 |
} // htescape2 |
50 |
|
51 |
function realUpdate () { |
52 |
var baseURL = document.getElementById ('base-url').value; |
53 |
var resolvedURL = document.getElementById ('resolved-url').value; |
54 |
|
55 |
var pl = document.getElementById ('permalink'); |
56 |
pl.href = location.pathname + '?' + encodeURIComponent (baseURL) + ';' + |
57 |
encodeURIComponent (resolvedURL); |
58 |
|
59 |
var iframe = document.getElementsByTagName ('iframe')[0]; |
60 |
var doc = iframe.contentWindow.document; |
61 |
doc.open (); |
62 |
doc.write ('<!DOCTYPE HTML>'); |
63 |
doc.write ('<base href="' + htescape (baseURL) + '">'); |
64 |
doc.write ('<a href="' + htescape (resolvedURL) + '">xx</a>'); |
65 |
doc.close (); |
66 |
|
67 |
var aEl = doc.getElementsByTagName ('a')[0]; |
68 |
var resultURL = aEl.href; |
69 |
var output = document.getElementById ('output-url'); |
70 |
output.innerHTML = ''; |
71 |
if (typeof (resultURL) == 'undefined') { |
72 |
output.innerHTML = '(<code>undefined</code>)'; |
73 |
} else if (resultURL === null) { |
74 |
output.innerHTML = '(<code>null</code>)'; |
75 |
} else if (resultURL === '') { |
76 |
output.innerHTML = '($B6uJ8;zNs(B $B!=(B URL $B2r7h<:GT(B?)'; |
77 |
} else { |
78 |
output.innerHTML = '<code>' + htescape2 ('' + resultURL) + |
79 |
'</code> of type <code>' + htescape (typeof (resultURL)) + '</code>'; |
80 |
} |
81 |
|
82 |
var resultBaseURL = aEl.baseURI; |
83 |
var output = document.getElementById ('output-base-url'); |
84 |
output.innerHTML = ''; |
85 |
if (typeof (resultBaseURL) == 'undefined') { |
86 |
output.innerHTML = '(<code>undefined</code>)'; |
87 |
} else if (resultBaseURL === null) { |
88 |
output.innerHTML = '(<code>null</code>)'; |
89 |
} else if (resultBaseURL === '') { |
90 |
output.innerHTML = '($B6uJ8;zNs(B)'; |
91 |
} else { |
92 |
output.innerHTML = '<code>' + htescape2 ('' + resultBaseURL) + |
93 |
'</code> of type <code>' + htescape (typeof (resultBaseURL)) + '</code>'; |
94 |
} |
95 |
} // realUpdate |
96 |
|
97 |
window.onload = function () { |
98 |
if (location.search) { |
99 |
var q = location.search.substring (1).split (/;/); |
100 |
if (q[0] != null) { |
101 |
document.getElementById ('base-url').value = decodeURIComponent (q[0]); |
102 |
} |
103 |
if (q[1] != null) { |
104 |
document.getElementById ('resolved-url').value = decodeURIComponent (q[1]); |
105 |
} |
106 |
} |
107 |
|
108 |
update (); |
109 |
}; // window.onload |
110 |
</script> |
111 |
</head> |
112 |
<body> |
113 |
<h1>$B@8$-$?(B URL $B2r7h1\Mw4o(B |
114 |
(<a rel=bookmark id=permalink href>$B915W%j%s%/(B</a>)</h1> |
115 |
|
116 |
<dl> |
117 |
<dt><label for=resolved-url>$B2r7h$9$k(B URL</label>: |
118 |
<dd><textarea id=resolved-url oninput="update()" onchange="update()" onkeypress="update()"></textarea> |
119 |
<dt><label for=base-url>$B4pDl(B URL</label>: |
120 |
<dd><textarea id=base-url oninput="update()" onchange="update()" onkeypress="update()"></textarea> |
121 |
</dl> |
122 |
<hr> |
123 |
<dl> |
124 |
<dt>$B7k2L(B (<code>base href</code> $B$H(B <code>HTMLAnchorElement.href</code> |
125 |
$B$r;HMQ(B): |
126 |
<dd><output id=output-url></output> |
127 |
<dt>$B<B8z4pDl(B URL (<code>Node.baseURI</code> $B$K$h$k(B) |
128 |
<dd><output id=output-base-url></output> |
129 |
</dl> |
130 |
|
131 |
<iframe></iframe> |
132 |
|
133 |
</body> |
134 |
</html> |