Facebook URL Cleaner

By Jordon Kalilich Last update Oct 26, 2009 — Installed 3,396 times. Daily Installs: 5, 4, 4, 3, 3, 2, 4, 2, 6, 3, 2, 5, 1, 7, 6, 8, 6, 2, 63, 188, 72, 46, 31, 31, 16, 22, 22, 23, 23, 18, 21, 11

There are 2 previous versions of this script.

// ==UserScript==
// @name          Facebook URL Cleaner
// @version       5
// @date          2009-10-25
// @description   Cleans Facebook URLs that don't actually take you to a new page.
// @namespace     http://www.theworldofstuff.com/greasemonkey/
// @copyright     Copyright 2008-2009 Jordon Kalilich (http://www.theworldofstuff.com/)
// @license       GNU GPL version 3 or later; http://www.gnu.org/copyleft/gpl.html
// @require       http://usocheckup.dune.net/29910.js?maxage=5
// @include       http*://*.facebook.com/*
// ==/UserScript==

// to enable when browsing photo galleries, change the following value to true:
var enableInGalleries = false;

var reg = /^(https?:\/\/([-a-z0-9]+\.)*facebook\.com)\/[^#]+#(\/.+)/i;

function checkURL(event) {
   if (reg.test(location.href)) {
      if (!(/photo\.php.*#.*photo\.php/i.test(location.href)) || enableInGalleries) { // thanks, discrete structures
         document.removeEventListener('DOMNodeInserted', checkURL, true); // we need to remove the event listener or we might cause an infinite loop apparently
         location.replace(location.href.replace(reg, '$1$3'));
      }
   }
}

if (top.location == location && /\.facebook\.com$/i.test(location.hostname)) {
   document.addEventListener('DOMNodeInserted', checkURL, true);
}