generate functionTue, 13 Dec 2022

tiymce, find youtube url, replace it with embed iframe

function tiymce() { var iframe = /<iframe.*<\/iframe>/gi; var youtube = /(http:\/\/www\.youtube\.com\/embed\/.*)/gi; var url = /(https?:\/\/(?:www\.|(?!www))[^\s\.]+\.[^\s]{2,}|www\.[^\s]+\.[^\s]{2,})\/?/gi; var content = tiymce.getContent(); var matches = content.match(iframe) || content.match(youtube) || content.match(url); if (matches) { var link = matches[0].match(url); if (link) { link = link[0].match(youtube); if (link) { link = link[0].replace('embed/', '').replace('www.', ''); } else { link = matches[0].match(url)[0]; } url = '<a href="' + link + '

Javascript
Generate More

Questions about programming?Chat with your personal AI assistant