Changeset 25781 for lang/javascript/vimperator-plugins
- Timestamp:
- 12/03/08 19:08:23 (5 weeks ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/stella.js
r25172 r25781 3 3 // @description-ja ステータスラインに動画の再生時間などを表示する。 4 4 // @license Creative Commons Attribution-Share Alike 3.0 Unported 5 // @version 0.0 65 // @version 0.07 6 6 // @author anekos (anekos@snca.net) 7 7 // @minVersion 2.0pre … … 13 13 // 14 14 // TODO 15 // user command16 // :fetchvideo17 15 // Icons 18 16 // Other video hosting websites 17 // auto fullscreen 19 18 // 20 // Link s:19 // Link: 21 20 // http://d.hatena.ne.jp/nokturnalmortum/ 21 // 22 // Refs: 23 // http://yuichis.homeip.net/nicodai.user.html 24 // http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/nicontroller.js 25 // http://coderepos.org/share/browser/lang/javascript/vimperator-plugins/trunk/youtubeamp.js 26 // Thanks! 22 27 // 23 28 // License: … … 33 38 const ID_PREFIX = 'anekos-stela-'; 34 39 const InVimperator = !!(liberator && modules && modules.liberator); 40 const DOUBLE_CLICK_INTERVAL = 300; 35 41 36 42 // }}} … … 121 127 : '??:??'); 122 128 123 function setWithBackup (target, values) { 124 let backup = target.__stella_backup = {}; 129 function storeStyle (target, values) { 130 let [style, cstyle] = [target.style, content.getComputedStyle(target, '')]; 131 let backup = style.__stella_backup = {}; 125 132 for (let [name, value] in Iterator(values)) { 126 backup[name] = target[name];127 target[name] = value;133 backup[name] = cstyle[name]; 134 style[name] = value; 128 135 } 129 liberator.log(target.__stella_backup)130 } 131 132 function restoreFromBackup (target, doDelete) {133 if (! target.__stella_backup)136 } 137 138 function restoreStyle (target, doDelete) { 139 let style = target.style; 140 if (!style.__stella_backup) 134 141 return; 135 for (let [name, value] in Iterator(target.__stella_backup)) 136 target[name] = value; 142 let backup = style.__stella_backup; 143 for (let name in Iterator(backup)) 144 style[name] = backup[name]; 137 145 if (doDelete) 138 delete target.__stella_backup; 146 delete style.__stella_backup; 147 } 148 149 function getElementByIdEx (id) 150 let (p = content.document.getElementById(id)) 151 (p && (p.wrappedJSObject || p)); 152 153 function fixDoubleClick (obj, click, dblClick) { 154 let clicked = 0; 155 let original = {click: obj[click], dblClick: obj[dblClick]}; 156 liberator.log(original); 157 obj[click] = function () { 158 let self = this, args = arguments; 159 let _clicked = ++clicked; 160 setTimeout(function () { 161 if (_clicked == clicked--) 162 original.click.apply(self, args); 163 else 164 clicked = 0; 165 }, DOUBLE_CLICK_INTERVAL); 166 }; 167 obj[dblClick] = function () { 168 clicked = 0; 169 original.dblClick.apply(this, arguments); 170 }; 139 171 } 140 172 … … 194 226 initialize: function () void null, 195 227 228 finalize: function () { 229 // 念のためフルスクリーンは解除しておく 230 if (this.has('fullscreen', 'rwt') && this.isValid && this.fullscreen) 231 this.fullscreen = false; 232 }, 233 196 234 is: function (state) (this.state == state), 197 235 … … 223 261 get statusText () this.timeCodes, 224 262 263 get storage () 264 (content.document.__stella_storage || (content.document.__stella_storage = {})), 265 225 266 get timeCodes () (toTimeCode(this.currentTime) + '/' + toTimeCode(this.totalTime)), 226 267 227 268 get title () undefined, 269 270 get isValid () (~buffer.URL.indexOf('http://www.nicovideo.jp/watch/')), 228 271 229 272 get volume () undefined, … … 318 361 if (this.fullscreen) { 319 362 liberator.log('full') 320 s etWithBackup(this.player.style, {363 storeStyle(this.player, { 321 364 position: 'fixed', 322 365 left: '0px', … … 327 370 } else { 328 371 liberator.log('normal') 329 restore FromBackup(this.player.style);372 restoreStyle(this.player); 330 373 } 331 374 }, … … 359 402 get totalTime () parseInt(this.player.getDuration()), 360 403 404 get isValid () buffer.URL.match(/^http:\/\/(?:[^.]+\.)?youtube\.com\/watch/), 405 361 406 get volume () parseInt(this.player.getVolume()), 362 407 set volume (value) (this.player.setVolume(value), value), … … 377 422 } 378 423 424 // Normal / Fullscreen 425 NicoPlayer.Variables = [ 426 ['videowindow._xscale', 100, null], 427 ['videowindow._yscale', 100, null], 428 ['videowindow._x', 6, 0], 429 ['videowindow._y', 65, 0], 430 ['controller._x', 6, -1000], 431 ['inputArea._x', 4, -1000], 432 ['controller._visible', 1, 1], 433 ['inputArea._visible', 1, 1], 434 ['waku._visible', 1, 0], 435 ['tabmenu._visible', 1, 0], 436 ['videowindow.video_mc.video.smoothing', null, 1], 437 ['videowindow.video_mc.video.deblocking', null, 5] 438 ]; 439 379 440 NicoPlayer.prototype = { 380 441 __proto__: Player.prototype, 381 442 382 443 functions: { 444 comment: 'rwt', 383 445 currentTime: 'rw', 446 fetch: 'x', 447 fileURL: '', 448 fullscreen: 'rwt', 449 id: 'r', 450 muted: 'rwt', 451 pause: 'x', 452 play: 'x', 453 playEx: 'x', 454 playOrPause: 'x', 455 repeating: 'rwt', 456 title: 'r', 384 457 totalTime: 'r', 385 volume: 'rw', 386 play: 'x', 387 playOrPause: 'x', 388 playEx: 'x', 389 pause: 'x', 390 muted: 'rwt', 391 repeating: 'rwt', 392 comment: 'rwt', 393 title: 'r', 394 fileURL: '', 395 id: 'r', 396 fetch: 'x', 397 title: 'r' 458 volume: 'rw' 398 459 }, 399 460 … … 403 464 set comment (value) (this.player.ext_setCommentVisible(value), value), 404 465 466 get playerContainer () getElementByIdEx('flvplayer_container'), 467 405 468 get currentTime () parseInt(this.player.ext_getPlayheadTime()), 406 469 set currentTime (value) (this.player.ext_setPlayheadTime(value), value), 407 470 408 471 get fileExtension () '.flv', 472 473 get fullscreen () !!this.storage.fullscreen, 474 set fullscreen (value) { 475 let self = this; 476 value = !!value; 477 478 if (this.storage.fullscreen === value) 479 return; 480 481 this.storage.fullscreen = value; 482 483 let variablesSetter = function () { 484 NicoPlayer.Variables.forEach(function ([name, normal, full]) { 485 let v = value ? full : normal; 486 if (v !== null) 487 self.player.SetVariable(name, v); 488 }); 489 }; 490 491 let doc = content.document.wrappedJSObject; 492 let win = content.wrappedJSObject; 493 let player = getElementByIdEx('flvplayer'); 494 495 win.toggleMaximizePlayer(); 496 497 if(value) { 498 let f = function () { 499 let viewer = {w: 544, h: 384}; 500 let screen = { 501 w: content.innerWidth, 502 h: content.innerHeight 503 }; 504 let scale = { 505 w: Math.max(1, screen.w / viewer.w), 506 h: Math.max(1, screen.h / viewer.h) 507 }; 508 scale.v = Math.min(scale.w, scale.h); 509 storeStyle(doc.body, { 510 backgroundImage: 'url()', 511 backgroundRepeat: '', 512 backgroundColor: 'black' 513 }); 514 player.SetVariable('videowindow.video_mc.video.smoothing' , 1); 515 player.SetVariable('videowindow.video_mc.video.deblocking', 5); 516 storeStyle( 517 player, 518 (scale.w >= scale.h) ? { 519 width: Math.floor(viewer.w * scale.h) + 'px', 520 height: screen.h + 'px', 521 marginLeft: ((screen.w - viewer.w * scale.h) / 2) + 'px', 522 marginTop: '0px' 523 } : { 524 width: screen.w + 'px', 525 height: Math.floor(viewer.h * scale.w) + 'px', 526 marginLeft: '0px', 527 marginTop: ((screen.h - viewer.h * scale.w) / 2) + 'px' 528 } 529 ); 530 player.SetVariable('videowindow._xscale', 100 * scale.v); 531 player.SetVariable('videowindow._yscale', 100 * scale.v); 532 variablesSetter(); 533 }; 534 f(); 535 win.onresize = function () 536 (InVimperator && liberator.mode === modes.COMMAND_LINE) || setTimeout(f, 1000); 537 } else { 538 restoreStyle(doc.body); 539 //restoreStyle(player); 540 player.style.marginLeft = ''; 541 player.style.marginTop = ''; 542 variablesSetter(); 543 delete win.onresize; 544 } 545 win.scrollTo(0, 0); 546 }, 409 547 410 548 get id () … … 415 553 set muted (value) (this.player.ext_setMute(value), value), 416 554 417 get player () 418 let (p = content.document.getElementById('flvplayer')) 419 (p && (p.wrappedJSObject || p)), 555 get player () getElementByIdEx('flvplayer'), 420 556 421 557 get repeating () this.player.ext_isRepeat(), … … 444 580 445 581 fetch: function (filepath) { 446 liberator.log(this.id)447 582 let onComplete = function (xhr) { 448 583 let res = xhr.responseText; … … 483 618 'comment', 484 619 'repeat', 620 'fullscreen', 485 621 { 486 622 name: 'volume-root', … … 593 729 this.disable(); 594 730 this.progressListener.uninstall(); 731 for each (let player in this.players) 732 player.finalize(); 595 733 window.removeEventListener('resize', this.__onResize, false); 596 734 }, … … 599 737 set hidden (v) (this.panel.hidden = v), 600 738 601 get valid () (this.where),739 get isValid () (this.where), 602 740 603 741 get player () this.players[this.where], … … 608 746 set statusBarVisible (value) (this.statusBar.setAttribute('moz-collapsed', !value), value), 609 747 610 get where () ( 611 (~buffer.URL.indexOf('http://www.nicovideo.jp/watch/') && 'niconico') 612 || 613 (buffer.URL.match(/^http:\/\/(?:[^.]+\.)?youtube\.com\/watch/) && 'youtube') 614 ), 615 748 get where () { 749 for (let [name, player] in Iterator(this.players)) 750 if (player.isValid) 751 return name; 752 }, 616 753 617 754 addUserCommands: function () { … … 624 761 ? funcS 625 762 : function (arg, bang) { 626 if (!stella. valid)763 if (!stella.isValid) 627 764 raise('Stella: Current page is not supported'); 628 765 let p = stella.player; … … 685 822 icon.style.marginRight = '4px'; 686 823 setClickEvent('icon', icon); 824 icon.addEventListener('dblclick', bindr(this, this.onIconDblClick), false); 687 825 688 826 let labels = this.labels = {}; … … 760 898 }, 761 899 900 onFullscreenClick: function () this.player.toggle('fullscreen'), 901 762 902 onIconClick: function () this.player.playOrPause(), 763 903 904 onIconDblClick: function () this.player.toggle('fullscreen'), 905 764 906 onLocationChange: function () { 765 if (this.__valid !== this. valid) {766 (this.__valid = this. valid) ? this.enable() : this.disable();907 if (this.__valid !== this.isValid) { 908 (this.__valid = this.isValid) ? this.enable() : this.disable(); 767 909 } 768 910 }, … … 780 922 }, 781 923 782 onMutedClick: function (event) (this.player.toggle('muted')),924 onMutedClick: function (event) this.player.toggle('muted'), 783 925 784 926 onPauseClick: function () this.player.pause(), … … 786 928 onPlayClick: function () this.player.play(), 787 929 788 onRepeatingClick: function () (this.player.toggle('repeating')),930 onRepeatingClick: function () this.player.toggle('repeating'), 789 931 790 932 onResize: function () { … … 795 937 }, 796 938 797 onSet MutedClick: function (event) (this.player.volume = event.target.getAttribute('volume'))939 onSetVolumeClick: function (event) (this.player.volume = event.target.getAttribute('volume')) 798 940 }; 941 942 fixDoubleClick(Stella.prototype, 'onIconClick', 'onIconDblClick'); 799 943 800 944 // }}} … … 804 948 *********************************************************************************/ 805 949 806 let (nsl = liberator.plugins.nico_statusline) { 950 if (InVimperator) { 951 let estella = liberator.plugins.stella; 952 807 953 let install = function () { 808 let stella = liberator.plugins. nico_statusline= new Stella();954 let stella = liberator.plugins.stella = new Stella(); 809 955 stella.addUserCommands(); 810 956 liberator.log('Stella: installed.') 811 957 } 812 if (nsl) { 813 nsl.finalize(); 958 959 // すでにインストール済みの場合は、一度ファイナライズする 960 // (デバッグ時に前のパネルが残ってしまうため) 961 if (estella) { 962 estella.finalize(); 814 963 install(); 815 964 } else { … … 823 972 ); 824 973 } 974 } else { 975 /* do something */ 825 976 } 826 977
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)