Changeset 26067
- Timestamp:
- 12/07/08 23:02:17 (5 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/stella.js
r25993 r26067 29 29 // http://creativecommons.org/licenses/by-sa/3.0/ 30 30 31 var PLUGIN_INFO = 32 <VimperatorPlugin> 33 <name>{NAME}</name> 34 <description>Show the time of movie on status line</description> 35 <description lang="ja">{"ステータスラインに動画の再生時間などを表示する。"}</description> 36 <version>0.08</version> 37 <detail><![CDATA[ 38 :stfetch 39 :stfullscreen 40 :stpause 41 :stplay 42 :strelations 43 :strepeat 44 :stseek 45 :stvolume 46 ]]></detail> 47 </VimperatorPlugin>; 31 48 32 49 (function () { … … 202 219 Player.ST_OTHER = 'other'; 203 220 204 Player.URL_TAG = 'tag'; 205 Player.URL_ID = 'id'; 206 Player.URL_SEARCH = 'search'; 221 Player.REL_TAG = 'tag'; 222 Player.REL_ID = 'id'; 223 Player.REL_SEARCH = 'search'; 224 Player.REL_URL = 'url'; 207 225 208 226 Player.RELATIONS = { 209 URL_TAG: 'relatedTags',210 URL_ID: 'relatedIDs'227 REL_TAG: 'relatedTags', 228 REL_ID: 'relatedIDs' 211 229 }; 212 230 … … 278 296 let result = []; 279 297 for (let [type, name] in Iterator(Player.RELATIONS)) { 280 if (this.has(name, 'r')) 281 result = result.concat(this[name].map(function (it) ({type: Player[type], value: it}))); 298 if (this.has(name, 'r')) { 299 try{ 300 result = this[name].map(function (it) ({type: Player[type], value: it})).concat(result); 301 } catch (e){ 302 liberator.log(name) 303 } 304 } 282 305 } 283 306 return result; … … 345 368 346 369 turnUpDownVolume: function (v) 347 this.volume = Math.min(Math.max(this.volume + v, 0), this.maxVolume)370 this.volume = Math.min(Math.max(this.volume + parseInt(v), 0), this.maxVolume) 348 371 }; 349 372 … … 415 438 get state () { 416 439 switch (this.player.getPlayerState()) { 417 case 'ended':440 case 0: 418 441 return Player.ST_ENDED; 419 case 'playing':442 case 1: 420 443 return Player.ST_PLAYING; 421 case 'paused':444 case 2: 422 445 return Player.ST_PAUSED; 423 case 'buffering': 424 case 'video cued': 425 case 'unstarted': 446 case 3: 447 // buffering 448 case 5: 449 //video cued 450 case -1: 451 //unstarted 426 452 default: 427 453 return Player.ST_OTHER; … … 437 463 438 464 get volume () parseInt(this.player.getVolume()), 439 set volume (value) (this.player.setVolume(value), value),465 set volume (value) (this.player.setVolume(value), this.volume), 440 466 441 467 play: function () this.player.playVideo(), … … 480 506 fullscreen: 'rwt', 481 507 id: 'r', 508 makeURL: 'x', 482 509 muted: 'rwt', 483 510 pause: 'x', … … 599 626 get relatedIDs () { 600 627 if (this.__rid_last_url == currentURL()) 601 return this.__rid_cache ;628 return this.__rid_cache || []; 602 629 this.__rid_last_url = currentURL(); 603 630 let videos = []; … … 613 640 if (c.nodeName != '#text') 614 641 video[c.nodeName] = c.textContent; 615 videos.push(video); 642 videos.push({ 643 title: video.title, 644 id: video.url.replace(/^.+watch\//, ''), 645 raw: video 646 }); 616 647 } 617 648 return this.__rid_cache = videos; … … 645 676 646 677 get volume () parseInt(this.player.ext_getVolume()), 647 set volume (value) (this.player.ext_setVolume(value), value),678 set volume (value) (this.player.ext_setVolume(value), this.volume), 648 679 649 680 fetch: function (filepath) { … … 659 690 makeURL: function (value, type) { 660 691 switch (type) { 661 case Player. URL_ID:692 case Player.REL_ID: 662 693 return 'http://www.nicovideo.jp/watch/' + value; 663 case Player. URL_TAG:694 case Player.REL_TAG: 664 695 return 'http://www.nicovideo.jp/tag/' + encodeURIComponent(value); 665 case Player. URL_SEARCH:696 case Player.REL_SEARCH: 666 697 return 'http://www.nicovideo.jp/search/' + encodeURIComponent(value); 667 698 } 699 return value; 668 700 }, 669 701 … … 840 872 841 873 addUserCommands: function () { 842 let stella = this; 874 let self = this; 875 843 876 function add (cmdName, funcS, funcB) { 844 877 commands.addUserCommand( 845 878 ['st' + cmdName], 846 cmdName + ' - Stella',879 cmdName.replace(/[\[\]]/g, '') + ' - Stella', 847 880 (funcS instanceof Function) 848 881 ? funcS 849 882 : function (arg, bang) { 850 if (!s tella.isValid)883 if (!self.isValid) 851 884 raise('Stella: Current page is not supported'); 852 let p = s tella.player;885 let p = self.player; 853 886 let func = bang ? funcB : funcS; 854 887 if (p.has(func, 'rwt')) … … 858 891 else if (p.has(func, 'x')) 859 892 p[func].apply(p, arg); 860 s tella.update();893 self.update(); 861 894 }, 862 895 {argCount: '*', bang: !!funcB}, … … 865 898 } 866 899 867 add('play', 'playOrPause'); 868 add('pause', 'pause'); 869 add('mute', 'muted'); 870 add('repeat', 'repeating'); 871 add('comment', 'comment'); 872 add('volume', 'volume', 'turnUpDownVolume'); 873 add('seek', 'seek', 'seekRelative'); 874 add('fetch', 'fetch'); 875 add('fullscreen', 'fullscreen'); 900 add('pl[ay]', 'playOrPause', 'play'); 901 add('pa[use]', 'pause'); 902 add('mu[te]', 'muted'); 903 add('re[peat]', 'repeating'); 904 add('co[mment]', 'comment'); 905 add('vo[lume]', 'volume', 'turnUpDownVolume'); 906 add('se[ek]', 'seek', 'seekRelative'); 907 add('fe[tch]', 'fetch'); 908 add('fu[llscreen]', 'fullscreen'); 909 910 commands.addUserCommand( 911 ['strel[ations]'], 912 'relations - Stella', 913 function (args) { 914 let arg = args.string; 915 let url = (function () { 916 if (self.player.has('makeURL', 'x')) { 917 if (arg.match(/^[#\uff03]/)) 918 return self.player.makeURL(arg.slice(1), Player.REL_ID); 919 if (arg.match(/^[:\uff1a]/)) 920 return self.player.makeURL(arg.slice(1), Player.REL_TAG); 921 if (arg.indexOf('http://') == -1) 922 return self.player.makeURL(encodeURIComponent(arg), Player.REL_TAG); 923 } 924 return arg; 925 })(); 926 liberator.open(url, arg.bang ? liberator.NEW_TAB : liberator.CURRENT_TAB); 927 }, 928 { 929 argCount: '*', 930 completer: function (context, args) { 931 if (!self.isValid) 932 raise('Stella: Current page is not supported'); 933 if (!self.player.has('relations', 'r')) 934 return; 935 context.title = ['Tag/ID', 'Description']; 936 context.completions = self.player.relations.map(function (rel) { 937 switch (rel.type) { 938 case Player.REL_ID: 939 return ['#' + rel.value.id, rel.value.title]; 940 case Player.REL_TAG: 941 return [':' + rel.value, 'Tag']; 942 case Player.REL_URL: 943 return [rel.value.url, rel.value.title]; 944 } 945 }); 946 } 947 }, 948 true 949 ); 876 950 }, 877 951 … … 883 957 ['click', 'popupshowing'].forEach(function (eventName) { 884 958 let onEvent = self['on' + capitalize(name) + capitalize(eventName)]; 885 //onEvent && liberator.log('on' + capitalize(name) + capitalize(eventName))886 959 onEvent && elem.addEventListener(eventName, function (event) { 887 960 if (eventName != 'click' || event.button == 0) { … … 943 1016 944 1017 let relmenu = document.getElementById('anekos-stela-relations-menupopup'); 945 liberator.log(relmenu)946 1018 }, 947 1019
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)