Dive Into Greasemonkey

Teaching an old web new tricks

List of tips


Whenever you see a tip or warning throughout this book, you can click on the tip icon to jump to the list of all tips.

  1. Many user scripts are available at the Greasemonkey script repository, although there is no requirement to list your scripts there. You may host (and users may install) your script from anywhere. You don't even need a web server; you can install a user script from a local file. 1.3. Installing a user script

  2. You can specify the items of your user script metadata in any order. I like @name, @namespace, @description, @include, and finally @exclude, but there is nothing special about this order. 2.2. Describing your user script with metadata

  3. When you click Edit in the “Manage User Scripts” dialog, you are “live” editing a copy of your script that is buried deep inside your Firefox profile directory. I've gotten into the habit, once I've finished a “live” editing session, of going back to my text editor one last time and selecting FileSave as..., and saving the user script in another directory. While it's not necessary (Greasemonkey only pays attention to the copy in your profile directory), I prefer to keep the “master copy” of my scripts in another directory with the rest of my work. 2.4. Editing your user script

  4. In JavaScript Console, you can right-click (Mac users control-click) on any line and select Copy to copy it to the clipboard. 3.2. Logging with GM_log

  5. Once you have a reference to an element (like thisElement), you can use thisElement.nodeName to determine its HTML tag name. If the page is served as text/html, the tag name is always returned as uppercase, regardless of how it was specified in the original page. However, if the page is served as application/xhtml+xml, the tag name is always lowercase. I always use thisElement.nodeName.toUpperCase() and forget about it. 4.6. Doing something for every element with a certain attribute

  6. Inserting new content before someExistingElement.nextSibling will work even if someExistingElement is the last child of its parent (i.e. it has no next sibling). In this case, someExistingElement.nextSibling will return null, and the insertBefore function will simply append the new content after all other siblings. (If this doesn't make any sense to you, don't worry about it. The point is that this example will always work, even when it seems like it shouldn't.) 4.8. Inserting content after an element

  7. If all you want to do is remove ads, it's probably easier to install AdBlock and import an up-to-date filter list than to write your own user script. 4.9. Removing an element

  8. Use the data: URI kitchen to construct your own data: URLs. 4.12. Adding images without hitting a central server

  9. You can use the addGlobalStyle function to style elements that you insert into a page, or elements that were part of the original page. However, if you are styling existing elements, you should use the ! important keyword for each rule you define to ensure your styles override the rules defined by the original page. 4.13. Adding CSS styles

  10. Zapping and replacing document.body.innerHTML does not change everything about the page. Anything defined in the <head> of the original page will still be in effect, including the page title, CSS styles, and scripts. You can modify or remove these separately. 4.16. Post-processing a page after it renders

  11. A submit event fires when a user submits a form in the usual way, i.e. by clicking the form's Submit button or hitting ENTER within a form. However, the submit event does not fire when the form is submitted via a script calling aForm.submit(). Therefore you need to do two things to capture a form submission: add an event listener to capture to submit event, and modify the prototype of the HTMLFormElement class to redirect the submit() method to your custom function. 4.22. Overriding a built-in Javascript method

  12. You can see all the stored configuration values by visiting about:config and filtering on greasemonkey.scriptvals. GM_getValue

  13. Whenever you see a list of “further reading” links throughout this book, you can click on the “Further reading” header to jump to the list of all further reading links. List of “further reading” links

  14. Whenever you see a tip or warning throughout this book, you can click on the tip icon to jump to the list of all tips. List of tips

  15. Whenever you see a video link throughout this book, you can click on the icon to jump to the list of all videos. List of procedures

← List of “further reading” links
List of examples →