What Nice Alert does is basically:
var w = window;
if (!w.alert.is_nice) {
w.alert = function alert(msg) {/*etc*}
}
Here is a solution like browser extension and Userscript. An extension has more permissions and runs everywhere. Used as Userscript works on many websites, but not others (like Github), but I don’t know exactly why.
To make a custom extension in Chrome or Opera, these would be the files:
manifest.json
{
"name": "(SOPT) Console functions",
"manifest_version": 2,
"version": "0.1",
"content_scripts": [{
"matches": ["http://*/*","https://*/*"],
"js": ["console.js"],
"run_at": "document_start"
}]
}
console.js
Attention to the use of the object arguments
that the functions receive.
function main() {
var w = window;
if (!w.log) {
w.log = function log() {
for( var i=0; i<arguments.length;i++)
console.log( arguments[i] );
}
}
}
if (!document.xmlVersion) {
var script = document.createElement('script');
script.appendChild(document.createTextNode('('+ main +')();'));
document.documentElement.appendChild(script);
}
You can also use a Usercript running in Chrome and Firefox, just paste the following header followed by the code console.js
above:
// ==UserScript==
// @name (SOPT) Console functions
// @namespace userscripts.pt.stackoverflow.com
// @version 0.1
// @match http*://*/*
// ==/UserScript==
Upshot:
References: