1 function handleToolbarPlay()
3 browser.tabs.query({currentWindow: true, active: true}).then(
5 playUrl(tabs.shift().url);
10 function handleMenuClick(event)
12 if ('mediaType' in event && event.mediaType == "video") {
13 playUrl(event.srcUrl);
14 } else if ('linkUrl' in event) {
15 playUrl(event.linkUrl);
17 console.error('No idea what to play here', event);
23 browser.browserAction.setBadgeText({text: '⧗'});
24 browser.browserAction.setBadgeTextColor({color: 'white'});
25 browser.browserAction.setBadgeBackgroundColor({color: 'orange'});
27 browser.storage.sync.get('proxyUrl').then((res) => {
28 var proxyUrl = res.proxyUrl;
29 console.log(url, proxyUrl);
36 'Content-Type': 'text/plain'
41 ).then(function (response) {
42 console.log(response.ok);
44 videoPlayOk(response);
46 videoPlayError(response);
48 }).catch(function (error) {
49 //e.g. Network error (when no network available)
50 showError(error.message);
55 function videoPlayOk(response)
57 browser.notifications.create(
61 title: 'Play video on Dreambox',
62 message: 'Video is playing now',
67 browser.browserAction.setBadgeText({text: '🗸'});
68 browser.browserAction.setBadgeTextColor({color: 'white'});
69 browser.browserAction.setBadgeBackgroundColor({color: 'green'});
70 setBadgeRemovalTimeout();
73 function videoPlayError(response)
75 response.text().then(function (text) {
80 function showError(message)
82 console.log("Play error: ", message);
84 browser.notifications.create(
88 title: 'Error playing video',
94 browser.browserAction.setBadgeText({text: 'x'});
95 browser.browserAction.setBadgeTextColor({color: 'white'});
96 browser.browserAction.setBadgeBackgroundColor({color: 'red'});
97 setBadgeRemovalTimeout();
100 function setBadgeRemovalTimeout()
104 browser.browserAction.setBadgeText({text:""});
111 browser.browserAction.onClicked.addListener(handleToolbarPlay);
114 browser.menus.create({
115 id: "play-video-on-dreambox-link",
116 title: "Play linked video on dreambox",
118 onclick: handleMenuClick,
124 browser.menus.create({
125 id: "play-video-on-dreambox-video",
126 title: "Play this video on dreambox",
128 onclick: handleMenuClick,