Just make a bookmarklet
I love to make random snippets on random web pages using only the console.
But sometimes, there's too much code to organize, or you would like to keep it for later use.
My solution is to use a bookmarklet for this kind of scripts.
Here's my bk's template :
javascript: (function() {
var script = document.createElement('script'),
head = document.getElementsByTagName('head')[0],
done = false,
abla = setTimeout(function(){
alert('Something went wrong, try a non https:// page.');
}, 2000);
script.src = [YOUR_SCRIPT_URL]+ (+new Date());
script.onload=script.onreadystatechange = function(){
clearTimeout(abla);
if ( !done &&
(!this.readyState ||
this.readyState == 'loaded' ||
this.readyState == 'complete')
) {
done=true;
script.onload = script.onreadystatechange = null;
head.removeChild(script);
};
};
head.appendChild(script);
})();
Don't forget, do not mix https:// page with your http:// script.
It will not run.
Also, you don't have to upload your script on a server, you can link it via your local IP.
It's magic and handy.
Written by Yoann Moinet
Related protips
1 Response
For a bookmaklet I'd rather do something smaller than that, even if that doesn't throw an alert :
javascript:(function(d,u,s){s=d.createElement("script"),s.src=u+"?"+(+new Date()),d.body.appendChild(s)})(document,"//domain.com/your/url")
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Snippet
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#