Home RSS feed

User JavaScript to change links to use port forwarding

My university subscribes to many online scientific magazines, such as ACM and IEEE Xplore. I wrote this script so that I could access these from any computer using port forwarding (SSH/Putty).

// ==UserScript==
// @name Porter
// @namespace http://www.rictin.com/
// @description Changes certain links (domains) to localhost (port forwarding)
// @include *
// ==/UserScript== 

(function () {

  /* Change this if you want to: */
  var domains = new Array("portal.acm.org", "ieeexplore.ieee.org");
  var targets = new Array("localhost:3871", "localhost:3872");

  var links = document.getElementsByTagName("a");
  for (var j = 0; j < targets.length; j++) {
    var porterR = new RegExp(domains[j], "i");
    for (var i = 0; i < links.length; i++) {
      if (links[i] && links[i].href) {
	links[i].href = links[i].href.replace(porterR, targets[j]);
      }
    }
  }
})();

Tags: javascript

blog comments powered by Disqus