IMDB ※ Clean Links (Enables History/Visited State)

Clean IMDB links so that any visited page is registered in your browser's history.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         IMDB ※ Clean Links (Enables History/Visited State)
// @namespace    http://tampermonkey.net/
// @version      0.13
// @description  Clean IMDB links so that any visited page is registered in your browser's history.
// @author       Oscar Kameoka — kitsuneDEV — www.kitsune.work
// @include      https://*.imdb.com/*
// @include      http://*.imdb.com/*
// @grant        none
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js
// ==/UserScript==

(function() {
  'use strict';
  //
  // CLEAN EACH LINK
  //
  $(document).ready(function() {
    $('a').each(function() {
      if ($(this).attr('href')) {
        // IGNORE IF LINK IS TO EXTERNAL SITE
        var linkHREF  = $(this).attr('href');
        var linkURL   = linkHREF.split('?');
        var linkClean = linkURL[0];

        // IF LINK IS TO EXTERNAL SKIP IT
        if (linkURL.indexOf('imdb.com') !== -1) {
          $(this).attr('href', linkClean);
        } else {
          // APPEND IMDB DOMAIN TO LINK
          // IF) HREF BEGINS WITH A SLASH
          if (linkClean[0] === '/') {
            $(this).attr('href', 'https://www.imdb.com' + linkClean);
          } else {
            $(this).attr('href', 'https://www.imdb.com/' + linkClean);
          }
        }
        // FOR EXTERNAL WEBSITES (IF: full link AND not IMDB's)
        if (linkURL.indexOf('http')) {
          $(this).attr('href', linkClean);
        }
      }
    });
  });
})();