What Nice Alert does is basically:
var w = window;
if (!w.alert.is_nice) {
w.alert = function alert(msg) {/*etc*}
}
They follow a solution like browser extension and as Userscript. An extension has more permissions and runs everywhere. Used as Userscript works on many websites, but not others (like Github), but I do not 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
Warning for using 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 that runs on 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==
Result :
References: