Artex / Redirect old links

// ==UserScript==
// @name        Redirect old links
// @namespace   Artex
// @description redirect old developer forum links to a search query of the thread title.
// @include     http://devforum.roblox.com/t/*
// @include     https://devforum.roblox.com/t/*
// @include     devforum.roblox.com/t/*
// @version     1
// @grant       none
// ==/UserScript==

function isOldLink(url) {
  if (url.search("developer.roblox.com/forum/") !== -1) {
    return true;
  } else {
    return false;
  }
}

function redirectLink(a) {
  var href = a.href
  var title = href.match(/\/\d+([0-9,a-z,A-Z, -]+)(?=#?|\?)/)[1];
  title = title.replace(/-/g, " ");
  a.href = "http://devforum.roblox.com/search?q=" + title;
}

function replaceLinks() {
  var links = document.getElementsByTagName("a");
  for (var i = 0; i < links.length; i++) {
    var link = links[i];
    if (isOldLink(link.href)) {
      redirectLink(link);
    }
  }
}

replaceLinks();