[script] Noembed Embed



  • Hello, I see that you guys use magickblock plugin, maybe i'll test it later but I am sharing a script I wrote to automarically embedding noembed supported sites.

    As I don't have patience to maintain a plugin, I just put this in ACP / Appearance / Custom HTML & CSS / Custom Headers.

    <script>
    
    $(document).ready(function(){
        $('head').append('<link rel="stylesheet" type="text/css" href="https://noembed.com/noembed.css">');
        
        setProviders();
    
        $(window).ajaxComplete(function(){
            $("div.post-content > p > a:not(.embedded)").addClass("embedded").each(function(){
                noembed(this.href, this.closest("div.post-content"));
            });    
        });
    
    
    });
    
    function setProviders()
    {
        //window.embedProviders = new RegExp();
    	providersArray = [];
    	patternsArray = [];	
    	
    	$.ajax({
    	    url: "https://noembed.com/providers",
    	    type: "get",
    	    success: function(data){
    		    providersArray = JSON.parse(data);
    		    
    	        while(providersArray.length)
    	        {
    	            patternsArray.push( providersArray.pop()['patterns'] );
    	        }
    
    	        window.embedProviders = new RegExp(patternsArray.join('|'), 'i');
    	    },
    	    datatype: "json"
    	});
    }
    
    function testurl(url)
    {
    	return function(){window.embedProviders.test(url)};
    }
    
    function noembed(myhref,mydiv)
    {
    
    	if(testurl(myhref)) {
    		$.ajax({
    			url: "https://noembed.com/embed",
    	    	type: "get",
    			data: {url: myhref},
    			dataType: "json",
    			success: function(data){ $(mydiv).append(data['html']); }
    		});
    	}
    	
    }
    
    </script>
    

    Noembed is an open source perl (plack) app, one can host it's own and it seems the app acts as a hub to the embed.


Log in to reply
 

Looks like your connection to NodeBB was lost, please wait while we try to reconnect.