Vectorspace's Greasemonkey Scripts



 
Excuse the low quality site - I'll build a better one one of these days... :)
I am Vectorspace: Electronic Engineer, Firefox fan and Moderator on the Mozillazine forums. And, I've decided to learn JavaScript. Learning by doing is the best way to learn, so I'm learning by writing Greasemonkey scripts.
Greasemonkey is an extension for the browser Mozilla Firefox. It lets you to add bits of JavaScript (known as "user scripts") to any webpage to change and customise it's behavior. It allows you the user to modify the behaviour of any web page in any way, either by downloading scripts from the internet or by writing them yourself. Below are the Greasemonkey scripts I have written and am working on.


 

Greasemonkey Scripts

To install any of these scripts, first install the Greasemonkey extension (I'm going to assume that you already use Mozilla Firefox). If you have the extension installed, click on the link to the script to view it, then click Tools > Install This User Script...
More information (and likely better instructions) can be found on the Greasmeonkey Homepage.

PvPonline Archive Bookmarker 3.0

Current Version - 3.0 (29/11/2007)
Script: pvparchivebookmarker30.user.js
Userscripts.org page: http://userscripts.org/scripts/show/1835
For PvPonline.com - Adds the ability to mark your place when reading through the archives.

Changes from version 2.0 - updated for the Nov 2007 redesign of the PVP website..

Changes from version 1.0 - completely re-written for the re-designed PvPonline website, and now uses script preferences instead of a cookie to store the page.

PvPonline is a webcomic drawn by Scott Kurtz, which following the antics of the staff at a gaming magazine. This script adds two links to PvPonline.com's navigation bar:

added nav bar links

Clicking 'Save Placemark' will save the address of the comic you are viewing. When you next visit the site, you can simply click 'Goto Placemark' to go back to the placemarked comic and continue where you left off - useful if you are reading through the archives.
Links are visible on the homepage and any comic in the archive.
The function of this script was inspired by the website for the webcomic Scary Go Round, which has a similar function built-in.

Tech stuff:
  • Works on http://pvponline.com and http://www.pvponline.com.
  • Stores the archive url of the comic page in an internal setting.
  • For comic pages that do not show the full archive url (like the front page), it stores the url of the previous comic - retrieved from the previous comic link. When you go to the placemark, the script internally downloads that page, locates the url of its 'next comic' link and loads that.
  • New in 2.1: After storing the url of the previous comic, it will attempt to internally load the previous comic page immediately, so it can retrieve and store the correct link. This way loading the saved placemark is always instant as the script does not need to retrieve another page first. As it stores the previous comic url before attempting this, if the browser is closed before it can store the correct url, it can still load the placemark using the previous url as it did before.

The Mows Archive Bookmarker 1.0

Note: Since the Mows website was redesigned to be 100% Flash driven, these scripts no longer work.

Script: mowsarchivebookmarker10.user.js
For mows.com - Adds the ability to mark your place when reading through the archives.

The Mows is a webcomic about the daily life of three housecats, and is drawn by Jay Dyke. This script adds two links below the comic:

PVP Archive Bookmarker 1

Clicking 'Tag This Comic' will 'tag' the comic you are viewing. When you next visit the site, you can simply click 'Goto Tag' to go back to the tagged comic and continue where you left off - useful if you are reading through the archives.
Tag This Comic is visible on any comic page. Goto Tag is only visible if a tag is detected.
An archive page for the latest comic does not exist, so tagging the latest comic will always point to the latest comic - rather than to the comic which was latest at the time, which is how the PvP bookmarker works.

Tech stuff:
  • A port of the PvP Archive Bookmarker script.
  • Works on http://mows.com and http://www.mows.com, but each will use its own tag - create a tag on one and it will not be visible on the other.
  • Cookie name is mows.comarchivebookmarker1663179 and the expiry time is set to 10 years.
  • Works by simply saving the url of the current page in a cookie. Goto Tag will retrieve the address and take you to it.
The Mows Archive Bookmarker 1.0.1 beta: Adds the ability to tag the latest comic. Do not use this script at the same time as version 1.0. If you tag the latest comic with 1.0 the tag will always point to the latest comic, rather than to the comic that was the latest when the tag was made. 1.0.1 beta generates the archive url for the latest comic, assuming that the number of the latest comic will be the number of the previous comic plus one. It gets the url of the previous comic from the 'Previous' link and increments the comic number by one.
Issues:
  • The archive url for the newest comic does not exist until it has been replaced with a newer comic. Therefore, if you tag the newest comic and then click Goto Tag, you will either get an error page or it will be redirected to an archive page with a similar filename - and this will continue until a newer comic is added.
  • 1.0.1 beta asusmes that each new comic is numbered incrementally. If this is not the case (and the number of the newest comic will not be one greater than the number of the previous comic) the the tag will always point to an error page/redirect.
1.0.1 beta script: mowsarchivebookmarker101.user.js
Do not use this script at the same time as version 1.0, and read the above issues before using.
 

Works In Progress

Below is a list of scripts I am writing or am planning to write.

I.E. Media Mimic 0.8.6b

Current Version - 0.8.6b (05/09/2006)
Status: Continuous development.
Script: iemediamimic086b.user.js
Userscripts.org page: http://userscripts.org/scripts/show/4278
This script is still under testing so it may be buggy, and is assumed to be Windows-only (I don't have Linux or a Mac to test it on  personally). Please report any bugs or issues in the testing thread over at the mozillazine forums, or by e-mailing me through the Contact section, and please read the known issues before using.

For any site - This script attempts to mimic the way Internet Explorer handles embedded audio/video embedded in web pages. When activated by the user, it modifies all embedded audio/video clips in a web page (if the file type being played is in an internal list) so that they play in Firefox more like how they play in Internet Explorer. WMP ActiveX objects and bgsound objects are also converted. If the script cannot convert based on the file extension, it will look at the MIME Type in the type attribute.

To convert a page, click "Tools" > "User Script Commands" > "IE Media Mimic: Convert Page", ot hit Ctrl+Shift+C. The page will refresh and then convert. The page will refresh, so anything you have typed into the page may be gone.

To perform a Quick Convert (converts without refreshing), click "Tools" > "User Script Commands" > "IE Media Mimic: Quick Page", ot hit Ctrl+Shift+C. The page will convert instantly. Some pages cannot be fully converted by Quick Convert. For such pages, an error box will appear after conversion, offering to perform a full convert.

To change the Script's options, click "Tools" > "User Script Commands" > "IE Media Mimic: Settings"

Menu Items:
menu-image

settings-image Settings Window

Basic Settings:
  • Reset to default button - reset basic settings to defaults.
  • Convert BGSound tags - determines if BGSound (The IE-only background sound tags) are converted.
  • Convert WMP ActiveX Objects - determines if WIndows Media Player ActiveX objects are converted.
    • even if file type is not in file types list - The script is usually restricted to converting medis whose file type is in a specified list. This determines if all WMP ActiveX objects are converted, even if the file type is not in the list.
  • Convert pages automatically - determines if the script must be activated manually, or if all pages will convert automatically once it has loaded.
  • Show Alert on Quick Convert Failure - enables/diables the error message displayed when Quick Convert fails.
  • Show Advanced Settings - unhides the advanced settings.
Advanced Settings:
  • The lists of File Types and MIME Types the script will convert, sorted into video types and audio types.
  • Only the active list is visible. To show a different list, click it's radio button: 
  • Add - add a type to the current list
  • Remove Selected - remove selected type(s) from the current list.
  • Reset to Default - reset current list to default.

New in 0.8.6b:
  • Minor big fix in settings window code.
New in 0.8.6a:
  • Minor big fix (possibly introduced in FF1.5.0.4 & BonEcho) when converting media with widths/heights specified as percentages.
New in 0.8.6:
  • Original settings code replaced with a trye, xhtml-crafted settings window.
  • Script now works on command (menu item or keyboard shortcut) instead of automatically (can be set back to automatic in options):
    • Convert Page (Ctrl+Shift+C) - refreshes the page, script converts on refresh.
    • Quick Page (Ctrl+Shift+Q) - page converts instantly, without refreshing. Can not fully convert some pages (frames from different domains), for such pages an alert will appear offering to perform a full convert (alert is disableable in options)
  • Now correctly converts media with width and/or height specified as a percentage.
  • Major re-write of initialisation and and conversion triggering code to support manually-triggerable conversions.
  • Removal of experimental code from 0.8.3.
  • Added about menu item.

Details:

It was written assuming the converted media would be played with the WMP plugin, which of course is Windows-only. I don't know what affect it would have on other platforms, but I'd welcome feedback on what it does if run on those platforms.

When Internet Explorer happens upon a video clip or audio file embedded in a web page, it will play it with Windows Media Player if it can - which it can unless it is a proprietary format like Quicktime or Real Player. It decides if it can based on the file extension.
Firefox will look at the MIME type for the file and look through its plugins for a plugin that lists that MIME type. If it doesn't find one it throws a missing plugin alert.

The Windows Media Player plugin (all browsers except for Internet Explorer use this to play Windows media) only lists the proprietary Microsoft formats (.asf, .asx, .wm, .wma, .wax, .wmv, and .wvx), and Quicktime and Real Player only list their proprietary formats too. So for any other format (.mpg, .wav, .midi, and .mp3, to name a few, very common formats), Firefox will throw up a missing plugin alert even though it already has all the media player plugins.

It is possible to configure the Quicktime plugin to play these formats, but few people know this.

In addition, many instances of embedded media are only tested in Internet Explorer, so many use parameters that the WMP plugin doesn't understand (e.g. loop, uimode, hidden), or specify values for those parameters that the WMP plugin doesn't understand (true/false as opposed to 1/0).

When triggered by the user (or automatically on page load, if set to) this script will look for every media file embedded in a web page and if the file type is in a predefined list, it will modify the way it is embedded so that it will open with the Windows Media Player plugin. Then, it will modify/change the parameters so that they will work with the WMP plugin like they would in IE.

Also converts bgsound and ActiveX objects to make them playable in Firefox. If it cannot convert an object based on the file type, it will use the MIME Type instead.

Known Issues:
  • Firefox may still show a Missing Plugin alert, even though the media plays with this script. This is because the script is only applied once the page has fully downloaded, by which time Firefox has already tried to find a plugin once.
  • By trying to mimic IE, this script may break embedded media coded to standard and/or specifically for Firefox. You should not convert such pages. If you have the script set to convert automatically, you should manually add such sites to the Excluded Pages list for the script.
  • Manually converting a page may not work properly if another page is loading at the same time. Quick Convert does not have this problem
  • Quick Convert cannot fully convert pages with frames, if one or more of the frames is from a different domain.
  • If IE renders a piece of embedded media with no width or height specified, it will use the width and height of the controls and the video file resolution (if it is a video file). The WMP plugin does not have this function. This script tries to mimic by setting the width to 280 (if absent) and the height to the controls height of 44 (if present) plus the status bar height of 43 (if present) plus 3/4 of the width (if the file/MIME type is considered to be a video type).
  • I determine if a file is a video file based on the file extension and MIME type, but it is not an ideal soltuion so it may incorrectly mark an audio file as video and vice versa. To change a type from video to audio or vice versa, remove it from the one list and add it to the other.
  • Under Firefox 1.5.x.x, you may find that the menu entries in Tools > User Script Commands may be duplicated as you navigate from page to page. This is due to a bug in Greasemonkey caused by Firefox 1.5's new fast back/forward cache. Just refresh the page and the duplicates will be removed.
  • JavaScript controls cannot be duplicated - if the player is controlled by JavaScript when viewed in IE, those controls cannot be made to function in Firefox even if the script converts the player properly.

Technical Details:

It works by finding the file extension of the file to be played. If that file extension is in an internal list of media file types, the script will alter the player to make it open with the WMP plugin. It will then, assuming the player was tested only in IE, modify the player parameters so they behave in Firefox more like they would in IE. If it cannot convert by the file extension, it looks at the type attribute for the MIME Type.
A Missing Plugin Alert may still be seen, but that is unavoidable.
  • Current functionality:
    • Examins all bgsound tags and replaces them with embed, and adds the attributes width="0" height="0" autostart="1" to mimic bgsound's behaviour. All other attributes are copied across as-is, and tag will be converted along with every other embed.
    • Examines all embed and object tags (including any bgsounds converted to embeds) and gets the source url. Extracts the file extension and compares against an internal list of file extensions. If the extension is found it converts the tag. If it could not convert based on the file extension it looks at the type attribute and compares that against another list.
    • Conversion involves adding type="application/x-mplayer2" to make the tag open with the WMP plugin. If a non-WMP ActiveX classID is found, the object statement will not be converted.
    • ActiveX objects are converted by changing the <param name="url" value="..."> parameter to <param name="filename" value="...">, and by removing the classid and codebase attributes as well as adding the new type and converting the parameters.
    • If the ActiveX object has Javascript controls, then those controls will not function once the object has been converted (the WMP plugin cannot be controlled by JavaScript).
    • The follwing attributes are converted/replaced to make them compatable with the WMP plugin:
      • All true/false parameters (bar loop and playcount, which are allowed true/false values) are set to 1/0
      • loop="-1" and loop="infinite" with playcount="true"
      • loop="false" with playcount="1"
      • loop="0" removed
      • all other loop values straight to playcount
      • If both loop and playcount are present, loop always takes precedence over playcount.
      • hidden="1" with width="0" height="0"
      • uiMode="full" uiMode="mini" uiMode="hidden" with showstatusbar="1" showcontrols="1"
      • uiMode="none" with showstatusbar="0" showcontrols="0"
    • If the width is not present, the width is increased to 280 (minimum width for WMP controls).
    • If the height is not present, the height is increased by 44 (if showcontrols is not set to false) plus 27 (if the status bar is present) plus 3/4 of the width (if it is a video).
    • The media is considered a video if the file type is considered a video file type, or if the MIME type contains the word "video".
    • Bgsound and ActiveX conversion can be disabled by setting the global variables convAx (ActiveX) and convBg (BGsound) to 0.
  • File extensions converted: mp3, m3u, mp4, mpeg, mpg, mid, midi, smf, wav, aiff, aif, avi, asf, asx, wm, wma, wax, wmv, wvx.
  • MIME types converted: audio/mpeg, audio/x-mpeg, audio/mp3, audio/x-mp3, audio/mpeg3, audio/x-mpeg3, audio/x-mpegurl, audio/mpegurl, audio/mp4, audio/mid, audio/x-midi, audio/midi, audio/x-wav,audio/wav, audio/aiff, audio/x-aiff, audio/x-ms-wma, audio/x-ms-wax, video/mp4, video/mpeg, video/x-mpeg, video/x-msvideo, video/msvideo, video/avi, application/asx, application/x-mplayer2, video/x-ms-asf-plugin, video/x-ms-asf, video/x-ms-wm, video/x-ms-wmv, video/x-ms-wvx.
This script simply modifies the extsting code on the page - if this script makes your page work, your page can be made to work without it. I will not have this script being used as an excuse for web developers not to embed media to standards, or to not update existing pages to standards - it is intended only to improve Firefox's abiltiy to play embedded media on sites that have not yet been updated to standard. If this is the case and you want help modifying your page, ask in the Web Development forum on the Mozillazine forums.


Contact

Feedback? Suggestions? E-mail me at vs_greasemonkey@ntlworld.com
Any e-mail sent to this address that is not related to my Greasemonkey scripts will be ignored.

Links

Userscripts.org: http://userscripts.org/
Greasemonkey script archive.
My Userscripts.org page: http://userscripts.org/people/1225

Jim Robert's Greasemonkey Scripts: http://userscripts.org/people/566
Jim helped me get started with Greasemonkey (mostly by letting me examine his scripts) and was until recently a fellow Mozillazine forums mod. He has some more great Greasemonkey scripts, which I'll try and find links to.

Dive Into Greasemonkey: http://diveintogreasemonkey.org/toc/
Free online book about Greasemonkey programming. Excellent beginners guide(I wish I had found it eariler - it would have made writing these scripts much easier!).

Greasemonkey Homepage: http://greasemonkey.mozdev.org/

Get Firefox!Get Thunderbird!Document made with Nvu

Valid HTML 4.01 Transitional