Skip to content

Instantly share code, notes, and snippets.

@blacklight
Created July 1, 2020 19:06
Show Gist options
  • Save blacklight/ee270be39660406972532e9640508246 to your computer and use it in GitHub Desktop.
Save blacklight/ee270be39660406972532e9640508246 to your computer and use it in GitHub Desktop.
async (app, host, browser, tab, target, ...args) => {
let url = null;
const baseURL = await app.getURL();
if (target) {
switch (target.tagName.toLowerCase()) {
case 'img':
url = target.attributes.src.value;
break;
case 'a':
url = target.attributes.href.value;
}
if (!url && url.length) {
const src = target.querySelector('source,img');
const link = target.querySelector('a');
if (src) {
url = src.attributes.src.value;
} else if (link) {
url = src.attributes.href.value;
} else {
url = null;
}
}
}
if (!url) {
if (tab) {
url = tab.url;
} else {
url = baseURL;
}
}
if (!url.match('^https?://[^/]+') && !url.startsWith('magnet:?')) {
url = baseURL.match('(^https?://[^/]+)')[1] + (url || '');
}
await app.run({
name: 'media.chromecast.play',
args: {
resource: url,
}
}, host);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment