-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from sktbrd/master
Skatehive Ipfs Iframe REGEX add
- Loading branch information
Showing
2 changed files
with
81 additions
and
73 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,160 +1,167 @@ | ||
import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX, BRIGHTEON_REGEX, VIMEO_EMBED_REGEX, SPEAK_EMBED_REGEX, VIMM_EMBED_REGEX, D_TUBE_EMBED_REGEX, SPOTIFY_EMBED_REGEX, SOUNDCLOUD_EMBED_REGEX, TWITCH_EMBED_REGEX, YOUTUBE_EMBED_REGEX, BRAND_NEW_TUBE_REGEX, LOOM_EMBED_REGEX, AUREAL_EMBED_REGEX } from '../consts' | ||
import { ARCH_REGEX, DAPPLR_REGEX, LBRY_REGEX, TRUVVL_REGEX, ODYSEE_REGEX, SKATEHIVE_IPFS_REGEX, BITCHUTE_REGEX, RUMBLE_REGEX, BRIGHTEON_REGEX, VIMEO_EMBED_REGEX, SPEAK_EMBED_REGEX, VIMM_EMBED_REGEX, D_TUBE_EMBED_REGEX, SPOTIFY_EMBED_REGEX, SOUNDCLOUD_EMBED_REGEX, TWITCH_EMBED_REGEX, YOUTUBE_EMBED_REGEX, BRAND_NEW_TUBE_REGEX, LOOM_EMBED_REGEX, AUREAL_EMBED_REGEX } from '../consts' | ||
|
||
export function iframe(el: HTMLElement): void { | ||
const src = el.getAttribute('src') | ||
const src = el.getAttribute('src'); | ||
if (!src) { | ||
el.parentNode.removeChild(el) | ||
return | ||
el.parentNode.removeChild(el); | ||
return; | ||
} | ||
|
||
// Youtube | ||
if (src.match(YOUTUBE_EMBED_REGEX)) { | ||
// strip query string (yt: autoplay=1,controls=0,showinfo=0, etc) | ||
const s = src.replace(/\?.+$/, '') | ||
el.setAttribute('src', s) | ||
return | ||
const s = src.replace(/\?.+$/, ''); | ||
el.setAttribute('src', s); | ||
return; | ||
} | ||
|
||
if (src.match(BITCHUTE_REGEX)) { | ||
return | ||
return; | ||
} | ||
|
||
// Vimeo | ||
const m = src.match(VIMEO_EMBED_REGEX) | ||
const m = src.match(VIMEO_EMBED_REGEX); | ||
if (m && m.length === 2) { | ||
const s = `https://player.vimeo.com/video/${m[1]}` | ||
el.setAttribute('src', s) | ||
return | ||
const s = `https://player.vimeo.com/video/${m[1]}`; | ||
el.setAttribute('src', s); | ||
return; | ||
} | ||
|
||
// Twitch | ||
if (src.match(TWITCH_EMBED_REGEX)) { | ||
const parentDomain = 'ecency.com' | ||
const s = `${src}&parent=${parentDomain}&autoplay=false` | ||
el.setAttribute('src', s) | ||
return | ||
const parentDomain = 'ecency.com'; | ||
const s = `${src}&parent=${parentDomain}&autoplay=false`; | ||
el.setAttribute('src', s); | ||
return; | ||
} | ||
|
||
// 3Speak | ||
if (src.match(SPEAK_EMBED_REGEX)) { | ||
const s = `${src}&autoplay=true` | ||
el.setAttribute('src', s) | ||
return | ||
const s = `${src}&autoplay=true`; | ||
el.setAttribute('src', s); | ||
return; | ||
} | ||
|
||
// Spotify | ||
if (src.match(SPOTIFY_EMBED_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups') | ||
el.setAttribute('frameborder', '0') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups'); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// Soundcloud | ||
if (src.match(SOUNDCLOUD_EMBED_REGEX)) { | ||
const match = src.match(/url=(.+?)&/) | ||
const match = src.match(/url=(.+?)&/); | ||
if (match && match.length === 2) { | ||
const s = `https://w.soundcloud.com/player/?url=${match[1]}&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true` | ||
el.setAttribute('src', s) | ||
return | ||
const s = `https://w.soundcloud.com/player/?url=${match[1]}&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&visual=true`; | ||
el.setAttribute('src', s); | ||
return; | ||
} | ||
} | ||
|
||
// Dtube | ||
if (src.match(D_TUBE_EMBED_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin') | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('allowfullscreen', 'true') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin'); | ||
el.setAttribute('frameborder', '0'); | ||
el.setAttribute('allowfullscreen', 'true'); | ||
return; | ||
} | ||
|
||
// VIMM | ||
if (src.match(VIMM_EMBED_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups') | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('allowfullscreen', 'true') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups'); | ||
el.setAttribute('frameborder', '0'); | ||
el.setAttribute('allowfullscreen', 'true'); | ||
return; | ||
} | ||
|
||
// Dapplr | ||
if (src.match(DAPPLR_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin') | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('allowfullscreen', 'true') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin'); | ||
el.setAttribute('frameborder', '0'); | ||
el.setAttribute('allowfullscreen', 'true'); | ||
return; | ||
} | ||
|
||
// Truvvl | ||
if (src.match(TRUVVL_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups') | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('class', 'portrait-embed') | ||
el.setAttribute('allowfullscreen', 'true') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('sandbox', 'allow-scripts allow-same-origin allow-popups'); | ||
el.setAttribute('frameborder', '0'); | ||
el.setAttribute('class', 'portrait-embed'); | ||
el.setAttribute('allowfullscreen', 'true'); | ||
return; | ||
} | ||
|
||
// LBRY.tv | ||
if (src.match(LBRY_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// ODYSEE | ||
if (src.match(ODYSEE_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// IPFS Skatehive | ||
if (src.match(SKATEHIVE_IPFS_REGEX)) { | ||
el.setAttribute('src', src); | ||
el.setAttribute('allowfullscreen', 'true'); | ||
return; | ||
} | ||
|
||
// archive.org | ||
if (src.match(ARCH_REGEX)) { | ||
el.setAttribute('src', src) | ||
return | ||
el.setAttribute('src', src); | ||
return; | ||
} | ||
|
||
// Rumble | ||
if (src.match(RUMBLE_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// Brigtheon | ||
if (src.match(BRIGHTEON_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
return | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// Brandnew Tube | ||
if (src.match(BRAND_NEW_TUBE_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// Loom | ||
if (src.match(LOOM_EMBED_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
// Aureal | ||
if (src.match(AUREAL_EMBED_REGEX)) { | ||
el.setAttribute('src', src) | ||
el.setAttribute('frameborder', '0') | ||
el.setAttribute('src', src); | ||
el.setAttribute('frameborder', '0'); | ||
return; | ||
} | ||
|
||
const replaceNode = el.ownerDocument.createElement('div') | ||
replaceNode.setAttribute('class', 'unsupported-iframe') | ||
replaceNode.textContent = `(Unsupported ${src})` | ||
el.parentNode.insertBefore(replaceNode, el) | ||
el.parentNode.removeChild(el) | ||
const replaceNode = el.ownerDocument.createElement('div'); | ||
replaceNode.setAttribute('class', 'unsupported-iframe'); | ||
replaceNode.textContent = `(Unsupported ${src})`; | ||
el.parentNode.insertBefore(replaceNode, el); | ||
el.parentNode.removeChild(el); | ||
} |