55 lines
1.5 KiB
JavaScript
55 lines
1.5 KiB
JavaScript
function getCurrentTabUrl(callback) {
|
|
var queryInfo = {
|
|
active: true,
|
|
currentWindow: true
|
|
};
|
|
console.info('xD');
|
|
chrome.tabs.query(queryInfo, function(tabs) {
|
|
var tab = tabs[0];
|
|
var url = tab.url;
|
|
callback(url);
|
|
});
|
|
}
|
|
|
|
function updateStatus(text, status) {
|
|
document.getElementById('status').textContent = text;
|
|
document.getElementById('status').setAttribute('class', status);
|
|
}
|
|
|
|
function pushToQ3kled(action, targetURL, callback, errorCallback) {
|
|
var requestUrl = 'http://led.waw.hackerspace.pl/api/1/webled/playlist/play/' + action +
|
|
'?uri=' + encodeURIComponent(targetURL);
|
|
var x = new XMLHttpRequest();
|
|
x.open('GET', requestUrl);
|
|
x.responseType = 'json';
|
|
x.onload = function() {
|
|
// Parse and process the response from Google Image Search.
|
|
var response = x.response;
|
|
if(!response.okay)
|
|
updateStatus(response.error, 'error');
|
|
else
|
|
updateStatus('OK', 'success');
|
|
};
|
|
x.onerror = function() {
|
|
updateStatus('Network error.', 'error');
|
|
};
|
|
x.send();
|
|
|
|
updateStatus('Loading ...', 'progress');
|
|
}
|
|
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
getCurrentTabUrl(function(url) {
|
|
document.getElementById('targetURL').textContent = url;
|
|
|
|
document.getElementById('append').addEventListener('click', function() {
|
|
pushToQ3kled('append', url);
|
|
});
|
|
|
|
document.getElementById('now').addEventListener('click', function() {
|
|
pushToQ3kled('now', url);
|
|
});
|
|
});
|
|
});
|
|
|