fbpx

GR EN FR DE ES CN
IL AL BG TR UA GE

Menu
Login

Новости по Email

Не пропусти другие интересные статьи, подпишись:

Я согласен с Политика конфиденциальности

Новостные ленты

Партнеры сайта

jQuery(document).ready(function() { var $element = jQuery('.single-article'); var text = $element.html(); // Regular expressions to match social media links var twitterLinkRegex = /https?:\/\/(?:www\.)?twitter\.com\/(\w+)\/status\/(\d+)/g; var facebookLinkRegex = /https?:\/\/(?:www\.)?facebook\.com\/(?:[^\/]+)\/(?:posts|photos|videos)\/(\d+)|https?:\/\/(?:www\.)?facebook\.com\/permalink.php\?story_fbid=(\d+)/g; var instagramLinkRegex = /https?:\/\/(?:www\.)?instagram\.com\/p\/([\w-]+)/g; var youtubeLinkRegex = /https?:\/\/(?:www\.)?youtube\.com\/(?:watch\?v=([\w-]+)|shorts\/([\w-]+))/g; // Function to fetch oEmbed code function fetchOEmbed(url, callback) { var oEmbedUrl; if (twitterLinkRegex.test(url)) { oEmbedUrl = 'https://publish.twitter.com/oembed?url=' + encodeURIComponent(url); } else if (facebookLinkRegex.test(url)) { oEmbedUrl = 'https://www.facebook.com/plugins/post/oembed.json/?url=' + encodeURIComponent(url); } else if (instagramLinkRegex.test(url)) { oEmbedUrl = 'https://api.instagram.com/oembed/?url=' + encodeURIComponent(url); } else if (youtubeLinkRegex.test(url)) { oEmbedUrl = 'https://www.youtube.com/oembed?url=' + encodeURIComponent(url) + '&format=json'; } if (oEmbedUrl) { jQuery.getJSON(oEmbedUrl, function(data) { callback(data.html); }); } } // Replace social media links with oEmbed code function replaceLinks() { var match; var updatedText = text; // Replace Twitter links while ((match = twitterLinkRegex.exec(text)) !== null) { var url = match[0]; fetchOEmbed(url, function(embedCode) { updatedText = updatedText.replace(url, embedCode); $element.html(updatedText); }); } // Replace Facebook links while ((match = facebookLinkRegex.exec(text)) !== null) { var url = match[0]; fetchOEmbed(url, function(embedCode) { updatedText = updatedText.replace(url, embedCode); $element.html(updatedText); }); } // Replace Instagram links while ((match = instagramLinkRegex.exec(text)) !== null) { var url = match[0]; fetchOEmbed(url, function(embedCode) { updatedText = updatedText.replace(url, embedCode); $element.html(updatedText); }); } // Replace YouTube links while ((match = youtubeLinkRegex.exec(text)) !== null) { var url = match[0]; fetchOEmbed(url, function(embedCode) { updatedText = updatedText.replace(url, embedCode); $element.html(updatedText); }); } } // Start replacing links replaceLinks(); });