buonasera a tutti
sto modificando un plug-in
vorrei che all apertura di chrome mi partisse in automatico la radio, senza dover schiacciare il tasto play
// Click Events
$('stop').onclick = function() { bgp.radio.stop(); };
$('togglePlay').onclick= function() {
var state = bgp.radio.state;
bgp.radio.togglePause();
nel codice ho questo pezzo di codice per la la gestione eventi
credo sia se clicchi su toggleplay....parti
volevo chiedervi
// Click Events
$('stop').onclick = function() { bgp.radio.stop(); };
$('togglePlay').autostart = function() {
var state = bgp.radio.state;
bgp.radio.togglePause();
se sostituissi .autostart al post .onclick sarebbe corretto e funzionerebbe ?
EDIT: evidentemente no, visto che non funziona...
questo è il codice base... un aiutino...un idea
graziecodice:var volume; var bgp = chrome.extension.getBackgroundPage(); var db = bgp.db; var eventHandlers = []; bgp.popupOpened(); window.addEventListener('load', init); window.addEventListener('unload', unload); eventHandlers.log = function(data) { /*console.log("Background: " + data.message);*/ }; function init() { eventHandlers.stateChange = stateChanged; eventHandlers.channelChange = channelChanged; initializeUI(); } function unload() { bgp.popupClosed(); } function mouseWheel(e) { if (e.wheelDelta > 0) bgp.radio.volume += 3; else bgp.radio.volume -= 3; volume.setValue(bgp.radio.volume, true); } var initializeUI = function() { if (localStorage.pluginInstalled == 'false') { $('no-plugin').style.display = 'block'; return; } else if (localStorage.pluginInstalled == 'true' && !bgp.player.isInstalled()) bgp.recheckPlayerExists(); // Volume slider volume = new Slider($('volume')); volume.onchange = function(percent, el) { bgp.radio.volume = percent; }; volume.setValue(bgp.radio.volume, true); $('controllers').addEventListener('mousewheel', mouseWheel); $$('header').addEventListener('mousewheel', mouseWheel); stateChanged({ state: bgp.radio.state }); channelChanged({ channel: bgp.radio.channel, track: bgp.player.getTrackName() }); var data = db.getCategories(); if (data.length == 0) toggleDiv('empty', true); jstProcess(new JsEvalContext(data), $('template-channels')); collapsible('#channels h2', 'ul'); // Click Events $('stop').onclick = function() { bgp.radio.stop(); }; $('togglePlay').onclick= function() { var state = bgp.radio.state; bgp.radio.togglePause(); }; $('show-channels').onclick = function() { if ($('channels').style.height != '240px') { $('channels').style.height = '240px'; this.innerHTML = 'Hide Stations'; } else { $('channels').style.height = '0px'; this.innerHTML = 'Show Stations'; } }; //$('open-options').onclick = function() { openSingleWindow('options.html'); }; var channelLinks = document.querySelectorAll('#channels a'); for (var i in channelLinks) { channelLinks[i].onclick = function(e) { channelChanged({ channel: db.getChannel(this.getAttribute('data-id')) }); bgp.radio.playChannel(this.getAttribute('data-id')); }; }; }; // Event handlers var stateChanged = function(data) { if (data.state != null) $('status').innerHTML = data.state; var btn = $('togglePlay'); btn.className = btn.className.replace(/(play)|(pause)/, ''); if (data.state == 'Playing') { btn.className += ' pause'; btn.title = 'Pause'; } else { btn.className += ' play'; btn.title = 'Play'; } }; var channelChanged = function(data) { if (data.channel) { var elStation = $('station'); if (data.track && bgp.radio.state == 'Playing') { elStation.onclick = function() { Clipboard.copy(this.innerText); this.style.textDecoration = 'underline'; setTimeout(function() { elStation.style.textDecoration = 'none'; }, 120); }; elStation.onmouseover = function() { this.style.cursor = 'pointer'; this.title = 'Click to copy: "' + data.track + '"'; this.innerText = data.track; }; elStation.onmouseout = function() { this.innerText = data.channel.name; this.title = data.channel.name; }; } else { elStation.onclick = null; elStation.onmouseover = null; elStation.onmouseout = null; } elStation.innerText = data.channel.name; elStation.title = data.channel.name; } }; chrome.extension.onRequest.addListener(function(request, sender, sendResponse) { if (request.event) { //console.warn('Event Fired: ' + request.event, request.data); var func = eventHandlers[request.event]; if (func != null && typeof(func) == 'function') func(request.data); } }); function checkPlayerAgain() { if (bgp.recheckPlayerExists()) { $('no-plugin').style.display = 'none'; initializeUI(); } } function playChannel(id) { bgp.radio.playChannel(id); return false; } function playNextChannel() { var nextChannel = db.getNextChannel(bgp.currentChannel); bgp.radio.playChannel(nextChannel.id); } function playPreviousChannel() { var nextChannel = db.getNextChannel(bgp.currentChannel); bgp.radio.playChannel(nextChannel.id); }

Rispondi quotando