-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslauncher.js
executable file
·357 lines (321 loc) · 10.5 KB
/
slauncher.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
/* md5.js - MD5 Message-Digest
* Copyright (C) 1999,2002 Masanao Izumo <[email protected]>
* Version: 2.0.0
* LastModified: May 13 2002
*
* This program is free software. You can redistribute it and/or modify
* it without any warranty. This library calculates the MD5 based on RFC1321.
* See RFC1321 for more information and algorism.
*/
/* Interface:
* md5_128bits = MD5_hash(data);
* md5_hexstr = MD5_hexhash(data);
*/
/* ChangeLog
* 2002/05/13: Version 2.0.0 released
* NOTICE: API is changed.
* 2002/04/15: Bug fix about MD5 length.
*/
// md5_T[i] = parseInt(Math.abs(Math.sin(i)) * 4294967296.0);
var MD5_T = new Array(0x00000000, 0xd76aa478, 0xe8c7b756, 0x242070db,
0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613,
0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1,
0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e,
0x49b40821, 0xf61e2562, 0xc040b340, 0x265e5a51,
0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681,
0xe7d3fbc8, 0x21e1cde6, 0xc33707d6, 0xf4d50d87,
0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9,
0x8d2a4c8a, 0xfffa3942, 0x8771f681, 0x6d9d6122,
0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60,
0xbebfbc70, 0x289b7ec6, 0xeaa127fa, 0xd4ef3085,
0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8,
0xc4ac5665, 0xf4292244, 0x432aff97, 0xab9423a7,
0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d,
0x85845dd1, 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314,
0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb,
0xeb86d391);
var MD5_round1 = new Array(new Array( 0, 7, 1), new Array( 1,12, 2),
new Array( 2,17, 3), new Array( 3,22, 4),
new Array( 4, 7, 5), new Array( 5,12, 6),
new Array( 6,17, 7), new Array( 7,22, 8),
new Array( 8, 7, 9), new Array( 9,12,10),
new Array(10,17,11), new Array(11,22,12),
new Array(12, 7,13), new Array(13,12,14),
new Array(14,17,15), new Array(15,22,16));
var MD5_round2 = new Array(new Array( 1, 5,17), new Array( 6, 9,18),
new Array(11,14,19), new Array( 0,20,20),
new Array( 5, 5,21), new Array(10, 9,22),
new Array(15,14,23), new Array( 4,20,24),
new Array( 9, 5,25), new Array(14, 9,26),
new Array( 3,14,27), new Array( 8,20,28),
new Array(13, 5,29), new Array( 2, 9,30),
new Array( 7,14,31), new Array(12,20,32));
var MD5_round3 = new Array(new Array( 5, 4,33), new Array( 8,11,34),
new Array(11,16,35), new Array(14,23,36),
new Array( 1, 4,37), new Array( 4,11,38),
new Array( 7,16,39), new Array(10,23,40),
new Array(13, 4,41), new Array( 0,11,42),
new Array( 3,16,43), new Array( 6,23,44),
new Array( 9, 4,45), new Array(12,11,46),
new Array(15,16,47), new Array( 2,23,48));
var MD5_round4 = new Array(new Array( 0, 6,49), new Array( 7,10,50),
new Array(14,15,51), new Array( 5,21,52),
new Array(12, 6,53), new Array( 3,10,54),
new Array(10,15,55), new Array( 1,21,56),
new Array( 8, 6,57), new Array(15,10,58),
new Array( 6,15,59), new Array(13,21,60),
new Array( 4, 6,61), new Array(11,10,62),
new Array( 2,15,63), new Array( 9,21,64));
function MD5_F(x, y, z) { return (x & y) | (~x & z); }
function MD5_G(x, y, z) { return (x & z) | (y & ~z); }
function MD5_H(x, y, z) { return x ^ y ^ z; }
function MD5_I(x, y, z) { return y ^ (x | ~z); }
var MD5_round = new Array(new Array(MD5_F, MD5_round1),
new Array(MD5_G, MD5_round2),
new Array(MD5_H, MD5_round3),
new Array(MD5_I, MD5_round4));
function MD5_pack(n32) {
return String.fromCharCode(n32 & 0xff) +
String.fromCharCode((n32 >>> 8) & 0xff) +
String.fromCharCode((n32 >>> 16) & 0xff) +
String.fromCharCode((n32 >>> 24) & 0xff);
}
function MD5_unpack(s4) {
return s4.charCodeAt(0) |
(s4.charCodeAt(1) << 8) |
(s4.charCodeAt(2) << 16) |
(s4.charCodeAt(3) << 24);
}
function MD5_number(n) {
while (n < 0)
n += 4294967296;
while (n > 4294967295)
n -= 4294967296;
return n;
}
function MD5_apply_round(x, s, f, abcd, r) {
var a, b, c, d;
var kk, ss, ii;
var t, u;
a = abcd[0];
b = abcd[1];
c = abcd[2];
d = abcd[3];
kk = r[0];
ss = r[1];
ii = r[2];
u = f(s[b], s[c], s[d]);
t = s[a] + u + x[kk] + MD5_T[ii];
t = MD5_number(t);
t = ((t<<ss) | (t>>>(32-ss)));
t += s[b];
s[a] = MD5_number(t);
}
function MD5_hash(data) {
var abcd, x, state, s;
var len, index, padLen, f, r;
var i, j, k;
var tmp;
state = new Array(0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476);
len = data.length;
index = len & 0x3f;
padLen = (index < 56) ? (56 - index) : (120 - index);
if(padLen > 0) {
data += "\x80";
for(i = 0; i < padLen - 1; i++)
data += "\x00";
}
data += MD5_pack(len * 8);
data += MD5_pack(0);
len += padLen + 8;
abcd = new Array(0, 1, 2, 3);
x = new Array(16);
s = new Array(4);
for(k = 0; k < len; k += 64) {
for(i = 0, j = k; i < 16; i++, j += 4) {
x[i] = data.charCodeAt(j) |
(data.charCodeAt(j + 1) << 8) |
(data.charCodeAt(j + 2) << 16) |
(data.charCodeAt(j + 3) << 24);
}
for(i = 0; i < 4; i++)
s[i] = state[i];
for(i = 0; i < 4; i++) {
f = MD5_round[i][0];
r = MD5_round[i][1];
for(j = 0; j < 16; j++) {
MD5_apply_round(x, s, f, abcd, r[j]);
tmp = abcd[0];
abcd[0] = abcd[3];
abcd[3] = abcd[2];
abcd[2] = abcd[1];
abcd[1] = tmp;
}
}
for(i = 0; i < 4; i++) {
state[i] += s[i];
state[i] = MD5_number(state[i]);
}
}
return MD5_pack(state[0]) +
MD5_pack(state[1]) +
MD5_pack(state[2]) +
MD5_pack(state[3]);
}
function MD5_hexhash(data) {
var i, out, c;
var bit128;
bit128 = MD5_hash(data);
out = "";
for(i = 0; i < 16; i++) {
c = bit128.charCodeAt(i);
out += "0123456789abcdef".charAt((c>>4) & 0xf);
out += "0123456789abcdef".charAt(c & 0xf);
}
return out;
}
/* utf.js - UTF-8 <=> UTF-16 convertion
*
* Copyright (C) 1999 Masanao Izumo <[email protected]>
* Version: 1.0
* LastModified: Dec 25 1999
* This library is free. You can redistribute it and/or modify it.
*/
/*
* Interfaces:
* utf8 = utf16to8(utf16);
* utf16 = utf16to8(utf8);
*/
function utf16to8(str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
function utf8to16(str) {
var out, i, len, c;
var char2, char3;
out = "";
len = str.length;
i = 0;
while(i < len) {
c = str.charCodeAt(i++);
switch(c >> 4)
{
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
// 0xxxxxxx
out += str.charAt(i-1);
break;
case 12: case 13:
// 110x xxxx 10xx xxxx
char2 = str.charCodeAt(i++);
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
break;
case 14:
// 1110 xxxx 10xx xxxx 10xx xxxx
char2 = str.charCodeAt(i++);
char3 = str.charCodeAt(i++);
out += String.fromCharCode(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
}
}
return out;
}
/**
* Social Launcher
*/
var slauncher_content;
var slauncher_map = {};
function slauncher_searchtag(json) {
var flag = false;
for (var item,i = 0; item = json[i]; i ++) {
var tlist = item.t;
for (var tag,t = 0; tag = tlist[t]; t ++) {
if (tag.match(/^id:.*/)) {
if (!flag) {
slauncher_content.innerHTML = "<b>Social Launcher</b><br />";
}
flag = true;
var url = "http://feeds.delicious.com/v2/json/tag/" + tag + "?count=50&callback=slauncher_showlink";
var s = document.createElement("script");
s.type = "text/javascript";
s.src = url;
document.body.appendChild(s);
}
}
}
if (!flag) {
slauncher_content.innerHTML = "<b>Social Launcher</b><br />There is no link found.";
}
}
function slauncher_showlink(json) {
// 枠を用意
for (var item,i = 0; item = json[i]; i ++) {
if (slauncher_map[item.u]) {
continue;
}
var base = item.u.match(/^(\w+):\/\/([^\/:]+)(:\d*)?/);
base = RegExp.$2;
var atag = document.createElement("a");
atag.setAttribute("href", item.u);
var img = document.createElement("img");
img.setAttribute("src", "http://" + base + "/favicon.ico");
img.setAttribute("border", "0");
atag.appendChild(img);
atag.appendChild(document.createTextNode(item.d));
slauncher_content.appendChild(atag);
alauncher_content.appendChild(document.createElement("br"));
slauncher_map[item.u] = {}; // 空オブジェクトをセット
}
}
// 起動スクリプト
(function() {
var cid = "socialauncher-content"
slauncher_content = document.getElementById(cid);
if (slauncher_content == null) {
//document.open();
slauncher_content = document.createElement("div");
slauncher_content.style.position = "absolute";
slauncher_content.style.top = "10px";
slauncher_content.style.left = "10px";
slauncher_content.style.backgroundColor = "#ffffff";
slauncher_content.style.color = "#000000";
slauncher_content.style.border = "solid #0000ff";
slauncher_content.style.zIndex = "999";
slauncher_content.style.textAlign = "left";
slauncher_content.id = cid;
slauncher_content.innerHTML = "<b>Social Launcher</b><br />Loading..";
document.body.appendChild(slauncher_content);
// MD5値を用意 (TODO:Canonicalizeが必要)
var target = utf16to8(document.location.href);
var hash = MD5_hexhash(target);
// タグを検索
var url = "http://feeds.delicious.com/v2/json/url/" + hash + "?count=50&callback=slauncher_searchtag";
var s = document.createElement("script");
s.type = "text/javascript";
s.src = url;
document.body.appendChild(s);
} else {
// すでに表示されている場合は隠す
if (slauncher_content.style.display == "none") {
slauncher_content.style.display = "block";
} else {
slauncher_content.style.display = "none";
}
}
})();