Changeset 26067

Show
Ignore:
Timestamp:
12/07/08 23:02:17 (5 years ago)
Author:
anekos
Message:

add :strelations
add short command
follow pluginmanager
fix .status

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/javascript/vimperator-plugins/trunk/stella.js

    r25993 r26067  
    2929//    http://creativecommons.org/licenses/by-sa/3.0/ 
    3030 
     31var 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>; 
    3148 
    3249(function () { 
     
    202219  Player.ST_OTHER   = 'other'; 
    203220 
    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'; 
    207225 
    208226  Player.RELATIONS = { 
    209     URL_TAG: 'relatedTags', 
    210     URL_ID: 'relatedIDs' 
     227    REL_TAG: 'relatedTags', 
     228    REL_ID: 'relatedIDs' 
    211229  }; 
    212230 
     
    278296      let result = []; 
    279297      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        } 
    282305      } 
    283306      return result; 
     
    345368 
    346369    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) 
    348371  }; 
    349372 
     
    415438    get state () { 
    416439      switch (this.player.getPlayerState()) { 
    417         case 'ended': 
     440        case 0: 
    418441          return Player.ST_ENDED; 
    419         case 'playing': 
     442        case 1: 
    420443          return Player.ST_PLAYING; 
    421         case 'paused': 
     444        case 2: 
    422445          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 
    426452        default: 
    427453          return Player.ST_OTHER; 
     
    437463 
    438464    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), 
    440466 
    441467    play: function () this.player.playVideo(), 
     
    480506      fullscreen: 'rwt', 
    481507      id: 'r', 
     508      makeURL: 'x', 
    482509      muted: 'rwt', 
    483510      pause: 'x', 
     
    599626    get relatedIDs () { 
    600627      if (this.__rid_last_url == currentURL()) 
    601         return this.__rid_cache; 
     628        return this.__rid_cache || []; 
    602629      this.__rid_last_url = currentURL(); 
    603630      let videos = []; 
     
    613640          if (c.nodeName != '#text') 
    614641            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        }); 
    616647      } 
    617648      return this.__rid_cache = videos; 
     
    645676 
    646677    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), 
    648679 
    649680    fetch: function (filepath) { 
     
    659690    makeURL: function (value, type) { 
    660691      switch (type) { 
    661         case Player.URL_ID: 
     692        case Player.REL_ID: 
    662693          return 'http://www.nicovideo.jp/watch/' + value; 
    663         case Player.URL_TAG: 
     694        case Player.REL_TAG: 
    664695          return 'http://www.nicovideo.jp/tag/' + encodeURIComponent(value); 
    665         case Player.URL_SEARCH: 
     696        case Player.REL_SEARCH: 
    666697          return 'http://www.nicovideo.jp/search/' + encodeURIComponent(value); 
    667698      } 
     699      return value; 
    668700    }, 
    669701 
     
    840872 
    841873    addUserCommands: function () { 
    842       let stella = this; 
     874      let self = this; 
     875 
    843876      function add (cmdName, funcS, funcB) { 
    844877        commands.addUserCommand( 
    845878          ['st' + cmdName], 
    846           cmdName + ' - Stella', 
     879          cmdName.replace(/[\[\]]/g, '') + ' - Stella', 
    847880          (funcS instanceof Function) 
    848881            ? funcS 
    849882            : function (arg, bang) { 
    850                 if (!stella.isValid) 
     883                if (!self.isValid) 
    851884                  raise('Stella: Current page is not supported'); 
    852                 let p = stella.player; 
     885                let p = self.player; 
    853886                let func = bang ? funcB : funcS; 
    854887                if (p.has(func, 'rwt')) 
     
    858891                else if (p.has(func, 'x')) 
    859892                  p[func].apply(p, arg); 
    860                 stella.update(); 
     893                self.update(); 
    861894              }, 
    862895          {argCount: '*', bang: !!funcB}, 
     
    865898      } 
    866899 
    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      ); 
    876950    }, 
    877951 
     
    883957        ['click', 'popupshowing'].forEach(function (eventName) { 
    884958          let onEvent = self['on' + capitalize(name) + capitalize(eventName)]; 
    885           //onEvent && liberator.log('on' + capitalize(name) + capitalize(eventName)) 
    886959          onEvent && elem.addEventListener(eventName, function (event) { 
    887960            if (eventName != 'click' || event.button == 0) { 
     
    9431016 
    9441017      let relmenu = document.getElementById('anekos-stela-relations-menupopup'); 
    945       liberator.log(relmenu) 
    9461018    }, 
    9471019