JS:WordPress AutoSave

I use WordPress 2.0.2 that doesn’t have the AutoSave feature yet. And I hear that the built-in autosave feature annoys some people. And I have a ThinkPad laptop with the ‘Back’ and ‘Forward’ buttons around the directional arrows. That’s why I created this Greasemonkey script.

On every unload on a post.php page it takes the value of the content field and saves it via the Greasemonkey provided GM_setValue with a key that is constructed from a predefined string (‘fcc.wp.’), the domain of the blog (eg. ‘friedcellcollective.net’), the path to the wp-admin folder, with / replaced by a . (eg ‘.outbreak’), the post id and finally a predefined ‘.value’. With some additional dividing dots this makes it ‘fcc.wp.friedcellcollective.net.outbreak.119.value’ for this page.

On every load of the post.php the value of the corresponding key is retrieved with the GM_getValue. If it’s not null and not equal to the content already in the content field it asks whether you want to replace the saved value of the content with what you have saved in Greasemonkey. Be aware that if you don’t do it first time you’re screwed – when you leave the page the content of the field will be overwritten by your current value. To circumvent this you could open the same post in another tab/window without closing the first one or kill the browser in a way that wouldn’t execute the unload event.

It already saved me quite some lost words in the last few posts I’ve written. Since not everybody is keen to have the whole Greasemonkey installed I also compiled it into an extension (with the Greasemonkey compiler).

The files are available here:

The script is tested with WordPress 2.0.2. The requirements are:

  • a field with id=”content” that has the content of the post
  • a hidden field with name=”post_ID” that holds the post’s id
  • the file has to be called post.php (Add-on only – you can change the file with the Greasemonkey script)

One Response to “JS:WordPress AutoSave”

Leave a Reply