-rw-r--r-- | content/util.js | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/content/util.js b/content/util.js index 5af0978..c4af09e 100644 --- a/content/util.js +++ b/content/util.js | |||
@@ -1,61 +1,70 @@ | |||
1 | /* | 1 | /* |
2 | * convert unicode string to utf-8 representation. | 2 | * convert unicode string to utf-8 representation. |
3 | * needed for correct md5 hash calculation. | 3 | * needed for correct md5 hash calculation. |
4 | */ | 4 | */ |
5 | function toutf8(ucode) { | 5 | function toutf8(ucode) { |
6 | var rv = ''; | 6 | var rv = ''; |
7 | for(var i=0;i<ucode.length;++i) { | 7 | for(var i=0;i<ucode.length;++i) { |
8 | var cc = ucode.charCodeAt(i); | 8 | var cc = ucode.charCodeAt(i); |
9 | if(cc<=0x7F) | 9 | if(cc<=0x7F) |
10 | rv += ucode.charAt(i); | 10 | rv += ucode.charAt(i); |
11 | else if(cc<=0x7ff) | 11 | else if(cc<=0x7ff) |
12 | rv += String.fromCharCode( | 12 | rv += String.fromCharCode( |
13 | 0xc0|((cc>> 6)&0x1f), | 13 | 0xc0|((cc>> 6)&0x1f), |
14 | 0x80|( cc &0x3f) ); | 14 | 0x80|( cc &0x3f) ); |
15 | else if(cc<=0xffff) | 15 | else if(cc<=0xffff) |
16 | rv += String.fromCharCode( | 16 | rv += String.fromCharCode( |
17 | 0xe0|((cc>>12)&0x0f), | 17 | 0xe0|((cc>>12)&0x0f), |
18 | 0x80|((cc>> 6)&0x3f), | 18 | 0x80|((cc>> 6)&0x3f), |
19 | 0x80|( cc &0x3f) ); | 19 | 0x80|( cc &0x3f) ); |
20 | else if(cc<=0x1fffff) | 20 | else if(cc<=0x1fffff) |
21 | rv += String.fromCharCode( | 21 | rv += String.fromCharCode( |
22 | 0xf0|((cc>>18)&0x07), | 22 | 0xf0|((cc>>18)&0x07), |
23 | 0x80|((cc>>12)&0x3f), | 23 | 0x80|((cc>>12)&0x3f), |
24 | 0x80|((cc>> 6)&0x3f), | 24 | 0x80|((cc>> 6)&0x3f), |
25 | 0x80|( cc &0x3f) ); | 25 | 0x80|( cc &0x3f) ); |
26 | else if(cc<=0x03ffffff) | 26 | else if(cc<=0x03ffffff) |
27 | rv += String.fromCharCode( | 27 | rv += String.fromCharCode( |
28 | 0xf8|((cc>>24)&0x03), | 28 | 0xf8|((cc>>24)&0x03), |
29 | 0x80|((cc>>18)&0x3f), | 29 | 0x80|((cc>>18)&0x3f), |
30 | 0x80|((cc>>12)&0x3f), | 30 | 0x80|((cc>>12)&0x3f), |
31 | 0x80|((cc>> 6)&0x3f), | 31 | 0x80|((cc>> 6)&0x3f), |
32 | 0x80|( cc &0x3f) ); | 32 | 0x80|( cc &0x3f) ); |
33 | else if(cc<=0x7fffffff) | 33 | else if(cc<=0x7fffffff) |
34 | rv += String.fromCharCode( | 34 | rv += String.fromCharCode( |
35 | 0xfc|((cc>>30)&0x01), | 35 | 0xfc|((cc>>30)&0x01), |
36 | 0x80|((cc>>24)&0x3f), | 36 | 0x80|((cc>>24)&0x3f), |
37 | 0x80|((cc>>18)&0x3f), | 37 | 0x80|((cc>>18)&0x3f), |
38 | 0x80|((cc>>12)&0x3f), | 38 | 0x80|((cc>>12)&0x3f), |
39 | 0x80|((cc>> 6)&0x3f), | 39 | 0x80|((cc>> 6)&0x3f), |
40 | 0x80|( cc &0x3f) ); | 40 | 0x80|( cc &0x3f) ); |
41 | } | 41 | } |
42 | return rv; | 42 | return rv; |
43 | } | 43 | } |
44 | 44 | ||
45 | /* | 45 | /* |
46 | * extract xpath-specified string value | 46 | * extract xpath-specified string value |
47 | */ | 47 | */ |
48 | function xp_str(xp,x) { | 48 | function xp_str(xp,x) { |
49 | var rv = x.evaluate( | 49 | var rv = x.evaluate( |
50 | xp, x, null, XPathResult.STRING_TYPE, null ); | 50 | xp, x, null, XPathResult.STRING_TYPE, null ); |
51 | return rv.stringValue; | 51 | return rv.stringValue; |
52 | } | 52 | } |
53 | /* | 53 | /* |
54 | * extract xpath-specified node | 54 | * extract xpath-specified node |
55 | */ | 55 | */ |
56 | function xp_node(xp,x) { | 56 | function xp_node(xp,x) { |
57 | var rv = x.evaluate( | 57 | var rv = x.evaluate( |
58 | xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); | 58 | xp, x, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ); |
59 | return rv.singleNodeValue; | 59 | return rv.singleNodeValue; |
60 | } | 60 | } |
61 | 61 | ||
62 | /* | ||
63 | * pull in elements into documents as a member variables | ||
64 | */ | ||
65 | function pull_elements(th,d,els) { | ||
66 | for(var e in els) { | ||
67 | var en=els[e]; | ||
68 | th[en] = d.getElementById(en); | ||
69 | } | ||
70 | } | ||