Changeset 24714 for lang/javascript
- Timestamp:
- 11/24/08 04:58:47 (4 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
lang/javascript/vimperator-plugins/trunk/stella.js
r24713 r24714 30 30 *********************************************************************************/ 31 31 32 const ID_PREFIX = 'ank-nico-status-'; 33 32 const ID_PREFIX = 'anekos-stela-'; 33 34 // }}} 34 35 35 36 /********************************************************************************* … … 69 70 Player.ST_OTHER = 'other'; 70 71 71 // rwx で機能の有無を表す 72 // rwxt で機能の有無を表す 73 // r = read 74 // w = write 75 // x = function 76 // t = toggle 72 77 Player.prototype = { 73 78 functions: { … … 81 86 }, 82 87 88 icon: null, 89 83 90 initialize: function () void null, 84 85 icon: null,86 91 87 92 get currentTime () undefined, … … 97 102 is: function (state) (this.state == state), 98 103 99 has: function (name, ms) !Array.some(ms, function (m) this.functions[name].indexOf(m) < 0), 104 has: function (name, ms) 105 let (f = this.functions[name]) 106 (f && !Array.some(ms, function (m) f.indexOf(m) < 0)), 100 107 101 108 playOrPause: function () { … … 134 141 }; 135 142 136 137 /********************************************************************************* 138 * YouTubePlayer {{{ 143 // }}} 144 145 /********************************************************************************* 146 * YouTubePlayer {{{ 139 147 *********************************************************************************/ 140 148 … … 152 160 play: 'x', 153 161 pause: 'x', 154 muted: 'rw ',162 muted: 'rwt', 155 163 repeating: 'rw', 156 164 }, 165 166 toggles: ['muted'], 157 167 158 168 icon: 'http://www.youtube.com/favicon.ico', … … 213 223 play: 'x', 214 224 pause: 'x', 215 muted: 'rw ',216 repeating: 'rw ',217 comment: 'rw '225 muted: 'rwt', 226 repeating: 'rwt', 227 comment: 'rwt' 218 228 }, 219 229 … … 272 282 273 283 /********************************************************************************* 274 * ContextMenu 284 * ContextMenu {{{ 275 285 *********************************************************************************/ 276 286 … … 334 344 335 345 /********************************************************************************* 336 * NicoStatusLine{{{337 *********************************************************************************/ 338 339 function NicoStatusLine() {346 * Stella {{{ 347 *********************************************************************************/ 348 349 function Stella () { 340 350 this.initialize.apply(this, arguments); 341 351 } 342 352 343 NicoStatusLine.MAIN_PANEL_ID = ID_PREFIX + 'panel',344 NicoStatusLine.MAIN_MENU_ID = ID_PREFIX + 'main-menu',345 NicoStatusLine.VOLUME_MENU_ID = ID_PREFIX + 'volume-menu',346 347 NicoStatusLine.prototype = {353 Stella.MAIN_PANEL_ID = ID_PREFIX + 'panel', 354 Stella.MAIN_MENU_ID = ID_PREFIX + 'main-menu', 355 Stella.VOLUME_MENU_ID = ID_PREFIX + 'volume-menu', 356 357 Stella.prototype = { 348 358 // new 時に呼ばれる 349 359 initialize: function () { … … 406 416 } 407 417 418 function createLabel (store, name, l, r) { 419 let label = store[name] = document.createElement('label'); 420 label.setAttribute('value', '-'); 421 label.style.marginLeft = (l || 0) + 'px'; 422 label.style.marginRight = (r || 0) + 'px'; 423 label.__defineGetter__('text', function () this.getAttribute('value')); 424 label.__defineSetter__('text', function (v) this.setAttribute('value', v)); 425 setClickEvent(name, label); 426 } 427 408 428 let panel = this.panel = document.createElement('statusbarpanel'); 409 429 panel.setAttribute('id', this.panelId); … … 418 438 419 439 let labels = this.labels = {}; 420 ['main', 'volume', 'comment', 'repeat'].forEach(function (name, index) { 421 let label = labels[name] = document.createElement('label'); 422 label.setAttribute('value', '-'); 423 label.style.marginLeft = (index < 2 ? 2 : 0) + 'px'; 424 (index < 3) && (label.style.marginRight = '0px'); 425 setClickEvent(name, label); 426 }); 440 let toggles = this.toggles = {}; 441 createLabel(labels, 'main', 2, 2); 442 createLabel(labels, 'volume', 0, 2); 443 for each (let player in this.players) { 444 for (let func in player.functions) { 445 if (player.has(func, 't')) 446 (func in labels) || createLabel(toggles, func); 447 } 448 } 427 449 428 450 panel.appendChild(hbox); 429 451 hbox.appendChild(icon); 430 452 [hbox.appendChild(label) for each (label in labels)]; 453 [hbox.appendChild(toggle) for each (toggle in toggles)]; 431 454 432 455 let menu = this.mainMenu = buildContextMenu({ 433 id: NicoStatusLine.MAIN_MENU_ID,456 id: Stella.MAIN_MENU_ID, 434 457 parent: panel, 435 458 set: hbox, … … 438 461 }); 439 462 440 let volMenu = this.volumeMenu = buildContextMenu({441 id: NicoStatusLine.VOLUME_MENU_ID,442 parent: panel,443 set: labels.volume,444 tree: ContextMenuVolume,445 onAppend: function (elem, menu) setClickEvent(capitalize(menu.name), elem)446 });447 448 labels.volume.setAttribute('context', volMenu.id);449 450 liberator.log(menu.id)451 452 463 let stbar = document.getElementById('status-bar'); 453 464 stbar.insertBefore(panel, document.getElementById('liberator-statusline').nextSibling); … … 460 471 update: function () { 461 472 try { 462 this.setLabelText('main', this.player.statusText); 463 this.setLabelText('comment', this.player.comment ? 'C' : 'c'); 464 this.setLabelText('repeat', this.player.repeating ? 'R' : 'r'); 465 this.setLabelText('volume', this.player.muted ? 'M' : this.player.volume); 473 this.labels.main.text = this.player.statusText; 474 this.labels.volume.text = this.player.volume; 475 this.toggles.comment.text = this.player.comment ? 'C' : 'c'; 476 this.toggles.repeating.text = this.player.repeating ? 'R' : 'r'; 477 this.toggles.muted.text = this.player.muted ? 'M' : 'm'; 466 478 } catch (e) { 467 479 liberator.log(e); … … 472 484 this.hidden = false; 473 485 this.icon.setAttribute('src', this.player.icon); 474 ['comment', 'repeat', 'volume'].forEach(bindr(this, function (name) {475 this. labels[name].hidden = !this.player.functions[name];476 } ));486 for (let name in this.toggles) { 487 this.toggles[name].hidden = !this.player.has(name, 't'); 488 } 477 489 if (!this.timerHandle) { 478 490 this.timerHandle = setInterval(bindr(this, this.update), 500); … … 498 510 onPauseClick: function () this.player.pause(), 499 511 500 on VolumeClick: function (event) (this.player.muted = !this.player.muted),501 502 onSet VolumeClick: function (event) (this.player.volume = event.target.getAttribute('volume')),512 onMutedClick: function (event) (this.player.muted = !this.player.muted), 513 514 onSetMutedClick: function (event) (this.player.volume = event.target.getAttribute('volume')), 503 515 504 516 onCommentClick: function () (this.player.comment = !this.player.comment), 505 517 506 onRepeat Click: function () (this.player.repeating = !this.player.repeating),518 onRepeatingClick: function () (this.player.repeating = !this.player.repeating), 507 519 508 520 onMainClick: function (event) { … … 545 557 if (nsl) { 546 558 nsl.finalize(); 547 liberator.plugins.nico_statusline = new NicoStatusLine();559 liberator.plugins.nico_statusline = new Stella(); 548 560 } else { 549 561 window.addEventListener( … … 551 563 function () { 552 564 window.removeEventListener('DOMContentLoaded', arguments.callee, false); 553 liberator.plugins.nico_statusline = new NicoStatusLine();565 liberator.plugins.nico_statusline = new Stella(); 554 566 }, 555 567 false
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)