Changeset 16865 for lang/javascript/userscripts
- Timestamp:
- 07/30/08 16:17:46 (4 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/userscripts/niconicoplaylist.user.js
r16421 r16865 11 11 12 12 var NicoNicoPlaylist = { 13 version: "1.1 0",13 version: "1.11", 14 14 getUserAgent: function () { 15 15 return "NicoNicoPlaylist/" + NicoNicoPlaylist.version + " Greasemonkey"; … … 42 42 WATCH_URL: "http://www.nicovideo.jp/watch/", 43 43 GETRELATION_API_URL: "http://www.nicovideo.jp/api/getrelation?page=1&sort=p&order=d&video=" 44 }; 45 46 NicoNico.Player = function () { this.initialize.apply(this, arguments); }; 47 NicoNico.Player.prototype = { 48 initialize: function (id) { 49 this.player = (typeof id != "string") ? id : document.getElementById(id); 50 }, 51 isReady: function () { 52 return (this.player && this.player.ext_getStatus && 53 this.player.ext_getStatus() !== undefined); 54 }, 55 getStatus: function () { 56 return this.player.ext_getStatus(); 57 }, 58 isFullScreen: function () { 59 return (this.player.ext_getVideoSize == "fit"); 60 }, 61 setFullScreen: function (full) { 62 this.player.ext_setVideoSize(full ? "fit" : "normal"); 63 return this; 64 } 44 65 }; 45 66 … … 81 102 if (!tags) return false; 82 103 for (var i = 0, len = tags.length; i < len; i++) { 83 var m = tags[i].match(NicoNico.WATCH_PAGE_REGEXP); 104 var m; 105 m = tags[i].match(/<url>([^<]+)<\/url>/); 106 if (!m) continue; 107 m = m[1].match(NicoNico.WATCH_PAGE_REGEXP); 84 108 if (!m) continue; 85 109 var videoId = m[1]; 86 110 87 m = tags[i].match(/<title>( .+?)<\/title>/);111 m = tags[i].match(/<title>([^<]+)<\/title>/); 88 112 if (!m) continue; 89 113 var title = m[1]; … … 194 218 this.random = GM_getValue("random_" + this.playlist.id) || false; 195 219 this.loop = GM_getValue("loop_" + this.playlist.id) || false; 220 this.fullScreen = GM_getValue("fullScreen_" + this.playlist.id) || false; 196 221 this.pinned = GM_getValue("pinned_" + this.playlist.id) || false; 197 this.hidingTimer = null; 222 this.container = null; 223 this.opened = false; 224 this.closeTimer = null; 198 225 this.update(); 199 226 }, … … 208 235 isWatchPage: function () { 209 236 return this.getPageVideoId() != false; 237 }, 238 pushVideo: function (videoId, title) { 239 var video = new Video(videoId, title); 240 this.playlist.push(video); 241 this.playlist.save(); 242 this.update(); 243 }, 244 pushVideos: function (videos) { 245 for (var i = 0, len = videos.length; i < len; i++) { 246 var video = new Video(videos[i].id, videos[i].title); 247 this.playlist.push(video); 248 } 249 this.playlist.save(); 250 this.update(); 210 251 }, 211 252 pushThisVideo: function () { … … 217 258 if (!a || !a.tagName || a.tagName.toUpperCase() != "A") return; 218 259 var title = a.innerHTML; 219 var video = new Video(videoId, title); 220 this.playlist.push(video); 221 this.playlist.save(); 222 this.update(); 260 this.pushVideo(videoId, title); 223 261 } 224 262 }, 225 263 pushAllVideos: function () { 226 264 var as = document.getElementsByTagName("a"); 265 var videos = []; 227 266 for (var i = 0, len = as.length; i < len; i++) { 228 267 var a = as[i]; … … 230 269 var m; 231 270 if (m = a.href.match(NicoNico.WATCH_PAGE_REGEXP)) { 232 if (/\bvideo\b/.test(a.className)) { 233 var video = new Video(m[1], a.innerHTML); 234 this.playlist.push(video); 271 if (/\bvideo\b(?!.*\bnoadd\b)/.test(a.className)) { 272 videos.push({ id: m[1], title: a.innerHTML }); 235 273 } 236 274 } … … 242 280 var thisVideo = new Video(videoId); 243 281 thisVideo.getRelatedVideos(function (videoId, title) { 244 var video = new Video(videoId, title); 245 self.playlist.push(video); 282 videos.push({ id: videoId, title: title }); 246 283 }, function () { 247 self.playlist.save(); 248 self.update(); 284 self.pushVideos(videos); 249 285 }); 250 286 } else { 251 this.playlist.save(); 252 this.update(); 287 this.pushVideos(videos); 253 288 } 254 289 }, … … 299 334 GM_setValue("pinned_" + this.playlist.id, this.pinned); 300 335 301 if (this. hidingTimer) {302 clearTimeout(this. hidingTimer);303 this. hidingTimer = null;336 if (this.closeTimer) { 337 clearTimeout(this.closeTimer); 338 this.closeTimer = null; 304 339 } 305 340 }, … … 311 346 this.loop = loop; 312 347 GM_setValue("loop_" + this.playlist.id, this.loop); 348 }, 349 setFullScreen: function (fullScreen) { 350 this.fullScreen = fullScreen; 351 GM_setValue("fullScreen_" + this.playlist.id, this.fullScreen); 352 }, 353 open: function () { 354 if (this.container) { 355 this.opened = true; 356 this.container.className = "playlist-controller"; 357 } 358 }, 359 close: function () { 360 if (this.container) { 361 this.opened = false; 362 this.container.className = "playlist-controller closed"; 363 } 364 }, 365 closeLater: function (msec) { 366 var self = this; 367 this.cancelClosing(); 368 this.closeTimer = setTimeout(function () { 369 self.closeTimer = null; 370 self.close(); 371 }, msec || 500); 372 }, 373 cancelClosing: function () { 374 if (this.closeTimer) { 375 clearTimeout(this.closeTimer); 376 this.closeTimer = null; 377 } 313 378 }, 314 379 update: function () { … … 320 385 box = document.createElement("div"); 321 386 box.id = "playlistcontroller_" + this.playlist.id; 322 box.className = "playlist-controller hiding";323 324 Util.observe(box, "mouse over", function () {325 box.className = "playlist-controller";326 if (self.hidingTimer) {327 clearTimeout(self.hidingTimer);328 self. hidingTimer = null;387 box.className = "playlist-controller" + (this.opened ? "" : " closed"); 388 389 Util.observe(box, "mousemove", function (ev) { 390 if (!self.opened) { 391 self.open(); 392 } else { 393 self.cancelClosing(); 329 394 } 330 395 }); 331 396 Util.observe(box, "mouseout", function (ev) { 332 if (self.pinned) return; 333 var el = ev.target || ev.srcElement; 334 if (el != box) return; 335 self.hidingTimer = setTimeout(function () { 336 self.hidingTimer = null; 337 box.className = "playlist-controller hiding"; 338 }, 500); 397 if (!self.opened || self.pinned) return; 398 if (box != ev.target && box != ev.srcElement) return; 399 self.closeLater(); 339 400 }); 340 401 document.body.appendChild(box); … … 350 411 box.innerHTML = ""; 351 412 } 413 this.container = box; 352 414 353 415 var header = document.createElement("div"); … … 359 421 title: "プレイリストを閉じる", 360 422 className: "playlist-window-button playlist-window-button-close", 361 click: function () { box.className = "playlist-controller hiding"; }423 click: function () { self.close(); } 362 424 }); 363 425 this.__addLinkButton(header, { … … 506 568 507 569 this.__addCheckBox(footer, { 570 id: "playlist-" + this.playlist.id + "-checkbox-full", 571 caption: "最大化", 572 className: "playlist-checkbox-full", 573 click: function () { self.setFullScreen(this.checked); }, 574 checked: this.fullScreen 575 }); 576 this.__addCheckBox(footer, { 508 577 id: "playlist-" + this.playlist.id + "-checkbox-random", 509 578 caption: "ランダム", … … 626 695 var playlist = new PlayList(); 627 696 var controller = new PlayListController(playlist); 628 629 var player = document.getElementById('flvplayer'); 630 if (player) { 631 var lastPos = null; 632 var endTimer = setInterval(function () { 633 var total = player.GetVariable("ContentLength"); 634 if (!total) return; 635 var pos = player.GetVariable("LastVpos"); 636 if ((total - pos) <= 5 && lastPos == pos) { 637 clearInterval(endTimer); 638 controller.playNext(); 639 } 640 lastPos = pos; 641 }, 1000); 697 w.gm_playlistController = controller; 698 699 var playerElem = document.getElementById('flvplayer'); 700 if (playerElem) { 701 var player = new NicoNico.Player(playerElem); 702 (function (next) { 703 var t = setInterval(function () { 704 if (player.isReady()) { 705 clearInterval(t); 706 if (controller.fullScreen) { 707 player.setFullScreen(true); 708 } 709 next(); 710 } 711 }, 100); 712 })(function () { 713 var t = setInterval(function() { 714 if (player.getStatus() == "end") { 715 clearInterval(t); 716 controller.playNext(); 717 } 718 }, 1000); 719 }); 642 720 } 643 721 … … 656 734 overflow: hidden; 657 735 } 658 .playlist-controller. hiding{736 .playlist-controller.closed { 659 737 left: -395px; 660 738 }
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)