Difference between revisions of "Javascript"
From MohidWiki
(→Replace html markup in html characters) |
(→User scripts) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
==[[Bookmarklets]]== | ==[[Bookmarklets]]== | ||
[[Bookmarklets]] are little javascript one-liners that aim to compose a more or less complex [http://en.wikipedia.org/wiki/Url url]. | [[Bookmarklets]] are little javascript one-liners that aim to compose a more or less complex [http://en.wikipedia.org/wiki/Url url]. | ||
+ | |||
+ | ==User scripts== | ||
+ | User scripts are cool javascripts scripts that are injected ad-hoc in the desired web-pages by the browser. They allow to add extra functionalities that weren't previously thought by the web-page owners/designers. | ||
+ | |||
+ | ===[[Firefox]] (Greasemonkey)=== | ||
+ | User scripts for [[Firefox]] are also called greasmonkey scripts and they require the greasemonkey extension for firefox to be installed. They require to be named '''foo.user.js''', otherwise firefox doesn't installs them. To install them, simply open the greasemonkey script from your firefox browser. | ||
+ | |||
+ | ====Sample==== | ||
+ | //#deliciousmp3.user.js | ||
+ | // ==UserScript== | ||
+ | // @name del.icio.us mp3 | ||
+ | // @namespace | ||
+ | // @description add del.icio.us mp3 player to links | ||
+ | // @include http://* | ||
+ | // @exclude http://*.icio.us/* | ||
+ | // ==/UserScript== | ||
+ | var head,script | ||
+ | head = document.getElementsByTagName('head')[0]; | ||
+ | if (!head) { return; } | ||
+ | script = document.createElement('script'); | ||
+ | script.type = 'text/javascript'; | ||
+ | script.src = 'http://del.icio.us/js/playtagger' | ||
+ | head.appendChild(script); | ||
+ | |||
+ | ===Opera (user scripts)=== | ||
+ | User scripts for Opera are similar to greasemonkey scripts. But they require to be named strictly '''foo.js'''. Thus, a greasemonkey script needs to have the '''user.''' removed from its name, in order to work in Opera. To install them simply copy them into the user scripts folder in your Opera profile folder. | ||
+ | |||
+ | ====Sample==== | ||
+ | Same script as for firefox, but with some slight modifications... | ||
+ | //#deliciousmp3.js | ||
+ | // ==UserScript== | ||
+ | // @name del.icio.us mp3 | ||
+ | // @namespace | ||
+ | // @description add del.icio.us mp3 player to links | ||
+ | // @include http://* | ||
+ | // @exclude http://*.icio.us/* | ||
+ | // ==/UserScript== | ||
+ | var head,script; | ||
+ | head = document.getElementsByTagName('head')[0]; | ||
+ | if (head){ | ||
+ | script = document.createElement('script'); | ||
+ | script.type = 'text/javascript'; | ||
+ | script.src = 'http://del.icio.us/js/playtagger'; | ||
+ | head.appendChild(script); | ||
+ | } | ||
==Examples== | ==Examples== | ||
===Del.icio.us mp3 player user script=== | ===Del.icio.us mp3 player user script=== | ||
− | This one should work for | + | This one should work for Opera 9.X (save it as '''deliciousmp3.js'''). |
− | '''deliciousmp3 | ||
// ==UserScript== | // ==UserScript== | ||
Line 33: | Line 77: | ||
*[http://en.wikipedia.org/wiki/Javascript Javascript Wikipedia], | *[http://en.wikipedia.org/wiki/Javascript Javascript Wikipedia], | ||
*[http://en.wikipedia.org/wiki/Bookmarklet Bookmarklet Wikipedia], | *[http://en.wikipedia.org/wiki/Bookmarklet Bookmarklet Wikipedia], | ||
− | *[http://en.wikipedia.org/wiki/Greasemonkey Greasemonkey Wikipedia]. | + | *[http://en.wikipedia.org/wiki/Greasemonkey Greasemonkey Wikipedia], |
+ | *[http://userscripts.org/ Greasemonkey scripts largest repo]. | ||
[[Category:Technology]] | [[Category:Technology]] |
Latest revision as of 20:33, 19 February 2009
Javascript is a client-side scripting language. Its main differences relative to server-sided languages is that it is run by the client machine instead of the server machine. This can be useful in order to unload the server machine. Combined with XML technology it forms the core-technology of the AJAX programming philosophy.
Contents
Replace html markup in html characters
Here's how to replace html markup in html characters
divtag.replace(/<([^<>]*)>/g,"<$1>")
Bookmarklets
Bookmarklets are little javascript one-liners that aim to compose a more or less complex url.
User scripts
User scripts are cool javascripts scripts that are injected ad-hoc in the desired web-pages by the browser. They allow to add extra functionalities that weren't previously thought by the web-page owners/designers.
Firefox (Greasemonkey)
User scripts for Firefox are also called greasmonkey scripts and they require the greasemonkey extension for firefox to be installed. They require to be named foo.user.js, otherwise firefox doesn't installs them. To install them, simply open the greasemonkey script from your firefox browser.
Sample
//#deliciousmp3.user.js // ==UserScript== // @name del.icio.us mp3 // @namespace // @description add del.icio.us mp3 player to links // @include http://* // @exclude http://*.icio.us/* // ==/UserScript== var head,script head = document.getElementsByTagName('head')[0]; if (!head) { return; } script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'http://del.icio.us/js/playtagger' head.appendChild(script);
Opera (user scripts)
User scripts for Opera are similar to greasemonkey scripts. But they require to be named strictly foo.js. Thus, a greasemonkey script needs to have the user. removed from its name, in order to work in Opera. To install them simply copy them into the user scripts folder in your Opera profile folder.
Sample
Same script as for firefox, but with some slight modifications...
//#deliciousmp3.js // ==UserScript== // @name del.icio.us mp3 // @namespace // @description add del.icio.us mp3 player to links // @include http://* // @exclude http://*.icio.us/* // ==/UserScript== var head,script; head = document.getElementsByTagName('head')[0]; if (head){ script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'http://del.icio.us/js/playtagger'; head.appendChild(script); }
Examples
Del.icio.us mp3 player user script
This one should work for Opera 9.X (save it as deliciousmp3.js).
// ==UserScript== // @name del.icio.us mp3 // @namespace // @description add del.icio.us mp3 player to links // @include http://* // @exclude http://*.icio.us/* // ==/UserScript== var head,script; head = document.getElementsByTagName('head')[0]; if (head){ script = document.createElement('script'); script.type = 'text/javascript'; script.src = 'http://del.icio.us/js/playtagger' head.appendChild(script); }