disco-attempt-5

by Andrea Ercolino

HTML

<script src="http://cdnjs.cloudflare.com/ajax/libs/yepnope/1.5.4/yepnope.min.js"></script>

JavaScript

$(function() {
    
    $.proxyGet('http://disco-tools.eu/disco2_portal/terms.php', function(data) {
        
        convert_relative_urls_to_absolute();
        var remote_scripts = remove_scripts();
        $('body').append(data);
        remote_scripts.shift();  // ignore jQuery
        yepnope({load: remote_scripts});
        remove_noise();
        
        //---
        
        function remove_noise() {
            $('.mainNavi, .subNavi, #SpalteMitte, #SpalteRechts, .searchWrapper, .footer, .bannerWrapper, .contentHeader').remove();
        }
        
        function remove_scripts() {
            var remote_scripts = [];
            data = data.replace(/<script\b[^>]*><\/script>|<script\b[^>]*\/>/g, function(all) {
                var url = all.match(/\bsrc[^=]*=[^"]*"([^"]+)"/i)[1];
                if (url) {
                    remote_scripts.push(url);
                }
                return '';
            });
            return remote_scripts;
        }
        
        function convert_relative_urls_to_absolute() {
            data = data
                .replace(/ href="(?!(https?|#))/g,             ' href="http://disco-tools.eu/disco2_portal/')
                .replace(/ src="(?!https?)/g,                   ' src="http://disco-tools.eu/disco2_portal/')
                .replace(/ data-ajaxurl="(?!https?)/g, ' data-ajaxurl="http://disco-tools.eu/disco2_portal/');
        }
                
    }, my_proxy);

});


$.proxyGet=function(a,b,c){if(null!==a&&!/^(https?:|\/\/)/.test(a))throw new SyntaxError("Expected a URL.");a&&0===a.indexOf("//")&&(a=window.location.protocol+a);var d={url:"http://query.yahooapis.com/v1/public/yql?q="+encodeURIComponent('select * from html where url="--URL--" and compat="html5" and xpath="*"')+"&format=xml",cleanup:function(a){return(a=a.results&&a.results[0])?a=a.replace(/&#xD;/gi,"\r").replace(/&#xA;/gi,"\n"):null},filter:null};c=$.extend(d,c||{});var...