Add Link To IMDb Code

Add Link To IMDb Code Like "tt1234567"; Better With Add IMDb Rating Script

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 or Violentmonkey 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.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

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         Add Link To IMDb Code
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  Add Link To IMDb Code Like "tt1234567"; Better With Add IMDb Rating Script
// @author       Mumumi
// @include      *
// @exclude      *greasyfork.org*
// @grant        none
// @run-at       document-end
// ==/UserScript==

function GetByXPath(xpath){
    try {
        return document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
    } catch (e) {
        console.log('ASget'+e);
    }
    return false;
}

//window.onload = function() {
    var imdbslist = ["IMDb", "IMDB", "imdb", "Imdb", "iMdb", "imDb", "imdB", "IMdb", "ImDb", "ImdB", "iMDb", "iMdB", "imDB", "IMdB", "ImDB", "iMDB"];
    for (var i in imdbslist) {
        try {
            var elem = GetByXPath('(//*[contains(.,"'+imdbslist[i]+'") and ./*[not(contains(.,"'+imdbslist[i]+'"))]])[last()]').snapshotItem(0);
            var html = elem.innerHTML;
            elem.innerHTML = html.replace(/([^/])(tt\d{7})/i,"$1<a href=\"http://www.imdb.com/title/$2/\">$2</a>");
        } catch (e) {
            console.log('ASget'+e);
        }
    }
//};