How to fiddle on any web page

Second Attempt

As you see, it’s very rough.. full of errors. All the errors but one are related to the fact that the page is using relative URLs. So let’s try to fix that now.

My second attempt (open in jsFiddle):

$(function() {
    $.proxyGet('', function(data) {
        function convert_relative_urls_to_absolute() {
            data = data
                .replace(/ href="(?!(https?|#))/g,             ' href="')
                .replace(/ src="(?!https?)/g,                   ' src="')
                .replace(/ data-ajaxurl="(?!https?)/g, ' data-ajaxurl="');
    }, 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:""+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(/
/gi,"n"):null},filter:null};c=$.extend(d,c||{});var e=c.url.replace("--URL--",encodeURIComponent(a))+"&callback=?";$.getJSON(e,function(a){$.isFunction(b)&&($.isFunction(c.cleanup)&&(a=c.cleanup(a),$.isFunction(c.filter)&&(a=c.filter(a))),b(a))})};

var my_proxy = {
    url: '',
    cleanup: function (data) {
        data = data.result;
        return (data ? data : null);

produced this result:

Screen Shot 2014-06-05 at 10.31.05

2 Replies to “How to fiddle on any web page”

  1. Well, all of the above is true and should work not only in jsFiddle but also in any other Online JavaScript IDE [1]. But if you have Google Chrome, forget about all those tricks and use its Custom JavaScript Snippets [2] feature instead. It just works. It’s like having the power you get when developing extensions right from the console.


Leave a Reply

Your email address will not be published. Required fields are marked *