Skip to content

Commit

Permalink
Merge pull request #44 from sktbrd/master
Browse files Browse the repository at this point in the history
Skatehive Ipfs Iframe REGEX add
  • Loading branch information
feruzm authored Mar 22, 2024
2 parents 57a4c47 + f43d3ae commit a24b40a
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 73 deletions.
1 change: 1 addition & 0 deletions src/consts/regexes.const.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const DAPPLR_REGEX = /^(https?:)?\/\/[a-z]*\.dapplr.in\/file\/dapplr-vide
export const TRUVVL_REGEX = /^https?:\/\/embed.truvvl.com\/(@[\w.\d-]+)\/(.*)/i
export const LBRY_REGEX = /^(https?:)?\/\/lbry.tv\/\$\/embed\/.*/i
export const ODYSEE_REGEX = /^(https?:)?\/\/odysee.com\/\$\/embed\/.*/i
export const SKATEHIVE_IPFS_REGEX = /^https?:\/\/ipfs\.skatehive\.app\/ipfs\/([^/?#]+)/i
export const ARCH_REGEX = /^(https?:)?\/\/archive.org\/embed\/.*/i
export const SPEAK_REGEX = /(?:https?:\/\/(?:3speak.([a-z]+)\/watch\?v=)|(?:3speak.([a-z]+)\/embed\?v=))([A-Za-z0-9\_\-\.\/]+)(&.*)?/i
export const SPEAK_EMBED_REGEX = /^(https?:)?\/\/3speak.([a-z]+)\/embed\?.*/i
Expand Down
153 changes: 80 additions & 73 deletions src/methods/iframe.method.ts
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);
}

0 comments on commit a24b40a

Please sign in to comment.