minor embedable content update
This commit is contained in:
parent
198e80ad81
commit
a077c816e2
2 changed files with 33 additions and 22 deletions
1
.vscode/settings.json
vendored
1
.vscode/settings.json
vendored
|
|
@ -37,6 +37,7 @@
|
|||
"libcurl",
|
||||
"libx",
|
||||
"matroska",
|
||||
"mbed",
|
||||
"Microformat",
|
||||
"microformats",
|
||||
"mkvtoolsnix",
|
||||
|
|
|
|||
|
|
@ -2,57 +2,62 @@ const sources = [
|
|||
{
|
||||
name: 'youtube',
|
||||
url: 'https://www.youtube-nocookie.com/embed/',
|
||||
regex: /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:shorts\/|[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,
|
||||
regex: /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:shorts\/|[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)(?<id>[a-zA-Z0-9_-]{11})/,
|
||||
},
|
||||
{
|
||||
name: "instagram",
|
||||
name: "instagram_post",
|
||||
url: "https://www.instagram.com/p/",
|
||||
regex: /https?:\/\/(?:www\.)?instagram\.com\/p\/([^/?#&]+)/,
|
||||
regex: /https?:\/\/(?:www\.)?instagram\.com\/p\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "instagram_story",
|
||||
url: "https://www.instagram.com/stories/highlights/",
|
||||
regex: /https?:\/\/(?:www\.)?instagram\.com\/stories\/highlights\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "twitter",
|
||||
url: "https://twitter.com/i/status/",
|
||||
regex: /https?:\/\/(?:www\.)?twitter\.com\/i\/status\/([^/?#&]+)/,
|
||||
regex: /https?:\/\/(?:www\.)?(twitter\.com|x\.com)\/.+?\/status\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "facebook",
|
||||
url: "https://www.facebook.com/plugins/post.php?href=",
|
||||
regex: /https?:\/\/(?:www\.)?facebook\.com\/(?:[^/?#&]+)\/posts\/([^/?#&]+)/,
|
||||
regex: /https?:\/\/(?:www\.)?facebook\.com\/(?:[^/?#&]+)\/posts\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "tiktok",
|
||||
url: "https://www.tiktok.com/embed/",
|
||||
regex: /https?:\/\/(?:www\.)?tiktok\.com\/(?:[^/?#&]+)\/video\/([^/?#&]+)/,
|
||||
regex: /https?:\/\/(?:www\.)?tiktok\.com\/(?:[^/?#&]+)\/video\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "vimeo",
|
||||
url: "https://player.vimeo.com/video/",
|
||||
regex: /https?:\/\/(?:www\.)?vimeo\.com\/(?:[^/?#&]+)\/([^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "soundcloud",
|
||||
url: "https://w.soundcloud.com/player/?url=",
|
||||
regex: /https?:\/\/(?:www\.)?soundcloud\.com\/(?:[^/?#&]+)\/([^/?#&]+)/,
|
||||
regex: /https?:\/\/(?:www\.)?vimeo\.com(?:\/[^/?#&]+)?\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "spotify",
|
||||
url: "https://open.spotify.com/embed/",
|
||||
regex: /https?:\/\/(?:open\.)?spotify\.com\/(?:[^/?#&]+)\/([^/?#&]+)/,
|
||||
regex: /https?:\/\/(?:open\.)?spotify\.com\/(?:[^/?#&]+)\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "twitch",
|
||||
url: "https://player.twitch.tv/?channel=",
|
||||
regex: /https?:\/\/(?:www\.)?twitch\.tv\/(?:[^/?#&]+)\/([^/?#&]+)/,
|
||||
name: "twitch_vod",
|
||||
url: "https://player.twitch.tv/?parent={origin}&video=",
|
||||
regex: /https?:\/\/(?:www\.)?twitch\.tv\/(?:[^/?#&]+)\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "mixcloud",
|
||||
url: "https://www.mixcloud.com/widget/iframe/",
|
||||
regex: /https?:\/\/(?:www\.)?mixcloud\.com\/(?:[^/?#&]+)\/([^/?#&]+)/,
|
||||
name: "twitch_clip",
|
||||
url: "https://clips.twitch.tv/embed?parent={origin}&clip=",
|
||||
regex: /https?:\/\/(?:www\.)?twitch\.tv\/(?:[^/?#&]+)\/clip\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "twitch_channel",
|
||||
url: "https://player.twitch.tv/?parent={origin}&channel=",
|
||||
regex: /https?:\/\/(?:www\.)?twitch\.tv\/(?<id>[^/?#&]+)/,
|
||||
},
|
||||
{
|
||||
name: "dailymotion",
|
||||
url: "https://www.dailymotion.com/embed/video/",
|
||||
regex: /https?:\/\/(?:www\.)?dailymotion\.com\/(?:[^/?#&]+)\/video\/([^/?#&]+)/,
|
||||
regex: /^.+dailymotion.com\/(video|hub)\/(?<id>[^_]+)[^#]*(#video=([^_&]+))?/,
|
||||
},
|
||||
]
|
||||
|
||||
|
|
@ -62,8 +67,13 @@ const isEmbedable = url => {
|
|||
|
||||
const getEmbedable = url => {
|
||||
const source = sources.find(source => source.regex.test(url));
|
||||
const id = source.regex.exec(url)[1];
|
||||
return source.url + id;
|
||||
if (!source) {
|
||||
return null;
|
||||
}
|
||||
|
||||
source.url.replace(/\{origin\}/g, window.location.origin);
|
||||
|
||||
return source.url + source.regex.exec(url)['groups'].id;
|
||||
}
|
||||
|
||||
export { isEmbedable, getEmbedable };
|
||||
|
|
|
|||
Loading…
Reference in a new issue