Show
Ignore:
Timestamp:
07/30/08 16:17:46 (4 months ago)
Author:
kotas
Message:
  • More accurate inspection for the end of playing video.
  • Added "full-screen" feature.
  • Fixed failure on getting relative videos.
  • Published the playlist controller in the global namespace.
Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/userscripts/niconicoplaylist.user.js

    r16421 r16865  
    1111 
    1212        var NicoNicoPlaylist = { 
    13                 version: "1.10", 
     13                version: "1.11", 
    1414                getUserAgent: function () { 
    1515                        return "NicoNicoPlaylist/" + NicoNicoPlaylist.version + " Greasemonkey"; 
     
    4242                WATCH_URL:           "http://www.nicovideo.jp/watch/", 
    4343                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                } 
    4465        }; 
    4566 
     
    81102                                                if (!tags) return false; 
    82103                                                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); 
    84108                                                        if (!m) continue; 
    85109                                                        var videoId = m[1]; 
    86110 
    87                                                         m = tags[i].match(/<title>(.+?)<\/title>/); 
     111                                                        m = tags[i].match(/<title>([^<]+)<\/title>/); 
    88112                                                        if (!m) continue; 
    89113                                                        var title = m[1]; 
     
    194218                        this.random = GM_getValue("random_" + this.playlist.id) || false; 
    195219                        this.loop = GM_getValue("loop_" + this.playlist.id) || false; 
     220                        this.fullScreen = GM_getValue("fullScreen_" + this.playlist.id) || false; 
    196221                        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; 
    198225                        this.update(); 
    199226                }, 
     
    208235                isWatchPage: function () { 
    209236                        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(); 
    210251                }, 
    211252                pushThisVideo: function () { 
     
    217258                                if (!a || !a.tagName || a.tagName.toUpperCase() != "A") return; 
    218259                                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); 
    223261                        } 
    224262                }, 
    225263                pushAllVideos: function () { 
    226264                        var as = document.getElementsByTagName("a"); 
     265                        var videos = []; 
    227266                        for (var i = 0, len = as.length; i < len; i++) { 
    228267                                var a = as[i]; 
     
    230269                                var m; 
    231270                                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 }); 
    235273                                        } 
    236274                                } 
     
    242280                                var thisVideo = new Video(videoId); 
    243281                                thisVideo.getRelatedVideos(function (videoId, title) { 
    244                                         var video = new Video(videoId, title); 
    245                                         self.playlist.push(video); 
     282                                        videos.push({ id: videoId, title: title }); 
    246283                                }, function () { 
    247                                         self.playlist.save(); 
    248                                         self.update(); 
     284                                        self.pushVideos(videos); 
    249285                                }); 
    250286                        } else { 
    251                                 this.playlist.save(); 
    252                                 this.update(); 
     287                                this.pushVideos(videos); 
    253288                        } 
    254289                }, 
     
    299334                        GM_setValue("pinned_" + this.playlist.id, this.pinned); 
    300335 
    301                         if (this.hidingTimer) { 
    302                                 clearTimeout(this.hidingTimer); 
    303                                 this.hidingTimer = null; 
     336                        if (this.closeTimer) { 
     337                                clearTimeout(this.closeTimer); 
     338                                this.closeTimer = null; 
    304339                        } 
    305340                }, 
     
    311346                        this.loop = loop; 
    312347                        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                        } 
    313378                }, 
    314379                update: function () { 
     
    320385                                box = document.createElement("div"); 
    321386                                box.id = "playlistcontroller_" + this.playlist.id; 
    322                                 box.className = "playlist-controller hiding"; 
    323  
    324                                 Util.observe(box, "mouseover", 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(); 
    329394                                        } 
    330395                                }); 
    331396                                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(); 
    339400                                }); 
    340401                                document.body.appendChild(box); 
     
    350411                                box.innerHTML = ""; 
    351412                        } 
     413                        this.container = box; 
    352414 
    353415                        var header = document.createElement("div"); 
     
    359421                                title: "プレイリストを閉じる", 
    360422                                className: "playlist-window-button playlist-window-button-close", 
    361                                 click: function () { box.className = "playlist-controller hiding"; } 
     423                                click: function () { self.close(); } 
    362424                        }); 
    363425                        this.__addLinkButton(header, { 
     
    506568 
    507569                        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, { 
    508577                                id: "playlist-" + this.playlist.id + "-checkbox-random", 
    509578                                caption: "ランダム", 
     
    626695        var playlist = new PlayList(); 
    627696        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                }); 
    642720        } 
    643721 
     
    656734                        overflow: hidden; 
    657735                } 
    658                 .playlist-controller.hiding { 
     736                .playlist-controller.closed { 
    659737                        left: -395px; 
    660738                }