Embedded Youtube Extractor

Code looks for embedded youtube videos and converts them into the highlighted URL. This is applicable if you want to use Evernote and yet save what Youtube video was on the page. It injects jQuery at the beginning to make my "job" easier. If this code doesn't work immediately, execute itnagain. It can be used as bookmarklet if you prefix it with "javascript:".

by dzejkej

JavaScript

(function () {


    // look for all iframes embeding youtube and convert those iframes into a "highlighted" text showing the source address
    function convertFrames() {
        $("*[src*='youtube.com']").each(function (index, element) {
            var $element = $(element);

            var address = $element.attr('src');
            $element.replaceWith("<span style='background-color:yellow;font-weight:bold'>" + address + "</span>");
        });
    }

    // load the jQuery on the page to make our life easier
    function loadJQuery() {
        var head = document.getElementsByTagName('head')[0];
        var script = document.createElement('script');

        var done = false;
        script.onload = script.onreadystatechange = (function () {
            if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
                done = true;
                script.onload = script.onreadystatechange = null;
                head.removeChild(script);
                convertFrames();
            }
        });

        script.src = '//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js';
        head.appendChild(script);
    }

    // if jQuery is not loaded on the page - load it
    if (typeof jQuery == 'undefined') {
        loadJQuery();
    } else {
        convertFrames();
    }
})();