1 |
wakaba |
1.1 |
javascript: |
2 |
|
|
|
3 |
|
|
if (!self.SAMI) self.SAMI = {}; |
4 |
|
|
if (!SAMI.onLoadFunctions) SAMI.onLoadFunctions = []; |
5 |
|
|
|
6 |
|
|
SAMI.onLoadFunctions.push (function () { |
7 |
|
|
SAMI.Script.loadScripts (new SAMI.List ([ |
8 |
|
|
'http://suika.fam.cx/www/nicocache/bookmarklets/nicocache.js?' + new Date () |
9 |
|
|
]), function () { |
10 |
|
|
var ControlBox = new SAMI.Class (function () { |
11 |
|
|
var article = document.createElement ('article'); |
12 |
|
|
article.innerHTML = '<p style=float:right><button type=button class=nc-close>×</button><p><output class=nc-video-title></output><p><output class=nc-original-cache-directory></output><p style=text-align:right>-> <select class=nc-cache-directories style="min-width: 10em"></select> <button type=button class=nc-cache-directory-change>Change</button><p class=nc-high-status><p class=nc-low-status>'; |
13 |
|
|
article.setAttribute ('style', 'position: fixed; display: block; top: 2em; left: 1em; width: 20em; background-color: white; color: black; border: outset gray 4px; z-index: 10000'); |
14 |
|
|
document.body.appendChild (article); |
15 |
|
|
this.element = article; |
16 |
|
|
|
17 |
|
|
this.getElements ('nc-close').list[0].onclick = function () { |
18 |
|
|
article.parentNode.removeChild (article); |
19 |
|
|
}; // onclick |
20 |
|
|
}, { |
21 |
|
|
getElements: function (key) { |
22 |
|
|
return SAMI.Node.getElementsByClassName (this.element, key); |
23 |
|
|
}, // getElements |
24 |
|
|
|
25 |
|
|
setVideoTitle: function (v) { |
26 |
|
|
this.getElements ('nc-video-title').list[0].textContent = v; |
27 |
|
|
}, // setVideoTitle |
28 |
|
|
setOriginalCacheDirectory: function (v) { |
29 |
|
|
this.getElements ('nc-original-cache-directory').list[0].textContent = v; |
30 |
|
|
}, // setOriginalCacheDirectory |
31 |
|
|
setCacheDirectories: function (l) { |
32 |
|
|
var select = this.getElements ('nc-cache-directories').list[0]; |
33 |
|
|
select.innerHTML = ''; |
34 |
|
|
l.forEach (function (dir) { |
35 |
|
|
var opt = document.createElement ('option'); |
36 |
|
|
opt.textContent = dir; |
37 |
|
|
if (dir == '') { |
38 |
|
|
opt.label = '(root)'; |
39 |
|
|
} |
40 |
|
|
select.appendChild (opt); |
41 |
|
|
}); |
42 |
|
|
|
43 |
|
|
var self = this; |
44 |
|
|
this.getElements ('nc-cache-directory-change').list[0].onclick = function () { |
45 |
|
|
self.changeDirectory (); |
46 |
|
|
}; |
47 |
|
|
}, // setCacheDirectories |
48 |
|
|
|
49 |
|
|
setHighStatus: function (v) { |
50 |
|
|
this.getElements ('nc-high-status').list[0].textContent = 'High: ' + v; |
51 |
|
|
}, // setHighStatus |
52 |
|
|
setLowStatus: function (v) { |
53 |
|
|
this.getElements ('nc-low-status').list[0].textContent = 'Low: ' + v; |
54 |
|
|
}, // setLowStatus |
55 |
|
|
|
56 |
|
|
clearHighStatus: function () { |
57 |
|
|
this.setHighStatus (''); |
58 |
|
|
}, // clearHighStatus |
59 |
|
|
clearLowStatus: function () { |
60 |
|
|
this.setLowStatus (''); |
61 |
|
|
}, // setLowStatus |
62 |
|
|
|
63 |
|
|
changeDirectory: function () { |
64 |
|
|
var newValue = this.getElements ('nc-cache-directories').list[0].value; |
65 |
|
|
this.onchangedirectory (newValue); |
66 |
|
|
} // changeDirectory |
67 |
|
|
}); |
68 |
|
|
|
69 |
|
|
var box = new ControlBox; |
70 |
|
|
|
71 |
|
|
var p = new NicoCache.Page (document); |
72 |
|
|
var id = p.getId (); |
73 |
|
|
if (id) { |
74 |
|
|
var v = new NicoCache.Video (id); |
75 |
|
|
v.withTitle (function (title) { |
76 |
|
|
box.setVideoTitle (title); |
77 |
|
|
}); |
78 |
|
|
v.withDirectory (function (dir) { |
79 |
|
|
box.setOriginalCacheDirectory (dir); |
80 |
|
|
}); |
81 |
|
|
|
82 |
|
|
box.onchangedirectory = function (d) { |
83 |
|
|
box.clearLowStatus (); |
84 |
|
|
box.clearHighStatus (); |
85 |
|
|
v.setDirectory (d, function (isLow, res) { |
86 |
|
|
if (isLow) { |
87 |
|
|
box.setLowStatus (res); |
88 |
|
|
} else { |
89 |
|
|
box.setHighStatus (res); |
90 |
|
|
} |
91 |
|
|
}); |
92 |
|
|
}; // onchangedirectory |
93 |
|
|
} |
94 |
|
|
NicoCache.withDirList (function (dirs) { |
95 |
|
|
box.setCacheDirectories (dirs); |
96 |
|
|
}); |
97 |
|
|
}); |
98 |
|
|
}); |
99 |
|
|
|
100 |
|
|
var script = document.createElement ('script'); |
101 |
|
|
script.src = 'http://suika.fam.cx/www/js/sami/script/sami-core.js'; |
102 |
|
|
document.body.appendChild (script); |
103 |
|
|
|
104 |
|
|
void (0); |
105 |
|
|
|