Archive for the hacks Tag

Hack: del.icio.us tags for the current URL Greasemonkey user script

Thursday, February 14th, 2008

A few days ago, Chris Heilmann posted JavaScript on his blog for obtaining the del.icio.us tags for the current URL (Retrieving del.icio.us tags for the current URL with JavaScript).

I don’t use del.icio.us but I know that a lot of other people do … so being able to see the tags that del.icio.us users have assigned to pages that I visit seemed like an interesting proposition, so I made a note to try greasing his script. I didn’t have a chance to try until last night, but I got it going.

Here’s a screenshot of Wolfram Mathworld with the list of del.icio.us tags in the box at center-top:

Screenshot of del.icio.us tags for Wolfram Mathworld.

Here’s the user script: gm-deliciousinfo.user.js

Again, the idea and the implementation is Chris Heilmann’s. I just converted his script into a Greasemonkey user script. I’m not going to be developing this any further myself but, if you take it for a spin, I hope that you get as much of a kick out of it as I did.

Note: I needed to use unsafeWindow in the user script and, by default, it’s set to trigger on any URL (@include *). By all accounts, this is not particularly safe.

Hack: Modifying Tabinta to insert spaces instead of a tab character

Friday, February 1st, 2008

I recently began using Bálint Endrey’s very helpful Tabinta Firefox add-on. From the addons.mozilla.org page for the extension:

Tabinta lets you insert tab characters in multi-line text input fields. The name itself is a shorthand for “Tab in Textarea”.

The default tab key behavior in Mozilla/Firefox textareas is to go to the next form field. This extension is for people who prefer inserting actual tab characters into these fields.

I prefer to use spaces for indentation rather than tab characters and posted a thread (Spaces instead of tabs) asking whether he’d considered adding an option for a configurable number of spaces to be inserted when the tab key was pressed instead of a tab character. He hadn’t yet replied (this is not a complaint at all - I don’t really check forums on sites where some of my code is hosted/distributed from very often - we all lead busy lives - etc.), so I decided to crack the XPI open and see if I could make a change.

The XPI is just a ZIP archive, so I extracted it. Inside the chrome/ subdirectory, there’s another archive, tabinta.jar. I extracted that and looked inside. content/tabinta contained a file that looked promising, tabintaOverlay.js (that’s chrome/content/tabinta/tabintaOverlay.js).

It contained the function insertTab:

    insertTab: function(element) {
        tabinta_insertText(element, "\t");
    },

All I had to do was replace the \t with four spaces, recreate the JAR, clean up the un-archived files from the JAR, recreate the XPI, and then uninstall the original version of the add-on and install my modified version and …. voila! Four spaces instead of a tab character when I press the Tab key inside of TEXTAREAs.

Hack: Making private Wordpress entries private (for Wordpress v. 2.3.x)

Wednesday, January 30th, 2008

Private entries in Wordpress are private in the same sense that an unlisted telephone number is private. If someone else knows, or can guess, the URL, then they can view the entry.

Below, between the dashed-line comments, is a conditional snippet (for wp-includes/query.php) that will prevent private entries from being visible to the general public.


function &get_posts() {
        [...]
	} elseif ( !$this->is_singular ) {
		$where .= " AND (post_status = 'publish'";

		if ( is_admin() )
			$where .= " OR post_status = 'future' OR post_status = 'draft' OR post_status = 'pending'";

		if ( is_user_logged_in() ) {
			$where .= current_user_can( "read_private_{$post_type}s" ) ? " OR post_status = 'private'" : " OR post_author = $user_ID AND post_status = 'private'";
		}

		$where .= ')';
	}

	//---------------------------
        if ($user_ID < 1) {
            $where .= " AND post_status != 'private'";
        }
	//---------------------------

	// Apply filters on where and join prior to paging so that any
	// manipulations to them are reflected in the paging by day queries.
	$where = apply_filters('posts_where', $where);
	$join = apply_filters('posts_join', $join);

	[...]