Created
July 1, 2020 19:06
-
-
Save blacklight/ee270be39660406972532e9640508246 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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