We Recommend

Pro JavaScript Techniques Pro JavaScript Techniques
Pro JavaScript Techniques is the ultimate JavaScript book for the modern web developer. It provides everything you need to know about modern JavaScript, and shows what JavaScript can do for your web sites. This book doesn't waste any time looking at things you already know, like basic syntax and structures.


Posted By

hxseven on 08/14/06


Tagged


Versions (?)


Who likes this?

4 people have marked this snippet as a favorite

nano
fantomex
letosword
wizard04


Greasemonkey template


Published in: JavaScript 


A simple template for Greasemonkey scripts, ready to copy and paste :-)

(Name the file example.user.js so that Greasemonkey recognizes it)

  1. // ==UserScript==
  2. // @name Greasemonkey Script Name
  3. // @author Your name
  4. // @namespace http://www.example.url/to/your-web-site/
  5. // @description Put a good description in here
  6. // @license Creative Commons Attribution License
  7. // @version 0.1
  8. // @include http://www.example.org/*
  9. // @include http://www.jonasjohn.de/*
  10. // @released 2006-04-17
  11. // @updated 2006-04-19
  12. // @compatible Greasemonkey
  13. // ==/UserScript==
  14.  
  15. /*
  16.  * This file is a Greasemonkey user script. To install it, you need
  17.  * the Firefox plugin "Greasemonkey" (URL: http://greasemonkey.mozdev.org/)
  18.  * After you installed the extension, restart Firefox and revisit
  19.  * this script. Now you will see a new menu item "Install User Script"
  20.  * in your tools menu.
  21.  *
  22.  * To uninstall this script, go to your "Tools" menu and select
  23.  * "Manage User Scripts", then select this script from the list
  24.  * and click uninstall :-)
  25.  *
  26.  * Creative Commons Attribution License (--> or Public Domain)
  27.  * http://creativecommons.org/licenses/by/2.5/
  28. */
  29.  
  30. (function(){
  31.  
  32. //object constructor
  33. function example(){
  34.  
  35. // modify the stylesheet
  36. this.append_stylesheet('body,div { border: 1px solid red; }');
  37.  
  38. };
  39.  
  40. //create a stylesheet
  41. example.prototype.append_stylesheet = function(css){
  42.  
  43. var styletag = document.createElement("style");
  44. styletag.setAttribute('type', 'text/css');
  45. styletag.setAttribute('media', 'screen');
  46. styletag.appendChild(document.createTextNode(css));
  47.  
  48. document.getElementsByTagName('head')[0].appendChild(styletag);
  49.  
  50. };
  51.  
  52. //instantiate and run
  53. var example = new example();
  54.  
  55.  
  56. })();
  57.  
  58. // you can completely copy this template, including
  59. // the install description, have fun! :-)

Report this snippet 

Comments

RSS Icon Subscribe to comments
Posted By: kif on August 16, 2006

Function "GMaddStyle" can be used in Greasemonkey instead of this.appendstylesheet.

You need to login to post a comment.