Letterboxd.com to KG

It adds a link in the right side panel for searching kg for torrents with the respective IMDb code(main film page) or Title(pages such as 'user reviewed film').

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        Letterboxd.com to KG
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js
// @namespace   http://userscripts.org/users/luckyluciano
// @description It adds a link in the right side panel for searching kg for torrents with the respective IMDb code(main film page) or Title(pages such as 'user reviewed film').
// @include     *letterboxd.com/*
// @version     3.1
// @grant       none
// ==/UserScript==


this.$ = this.jQuery = jQuery.noConflict(true);

function encode_utf8(s) {
  return unescape(encodeURIComponent(s));
}

function addLinkIMDB() {
      
     
             //IMDb search
           var imdbUrl = $(".text-link a").first().attr("href"); 
            var link = "https://karagarga.in/browse.php?search=" + getImdb(imdbUrl) + "&search_type=imdb";               
                                 
                    
           var l = $("#userpanel ul");
           var parent = l[0];
    
            var listItem = document.createElement('li');
            listItem.setAttribute('id','listitem');
               var a = document.createElement("a");
             a.innerHTML="KG - Search by IMDb code";
             a.setAttribute('href', link);
             listItem.appendChild(a);
            
             //DIRECTOR search
            var dir = $("#featured-film-header a")[1].innerHTML;
            var link2 = "https://karagarga.in/browse.php?dirsearch="+dir;  
    
           var listItem2 = document.createElement('li');
            listItem2.setAttribute('id','listitem2');
               var a2 = document.createElement("a");
             a2.innerHTML="KG - Search Director";
             a2.setAttribute('href', link2);
             listItem2.appendChild(a2);
    
             
              parent.appendChild(listItem);
             parent.appendChild(listItem2);
            $(l[0]).listview("refresh");
            
    }

function addLinkTitle() {
      
     
    // var parent = document.getElementById('featured-film-header');
             
            var title = $(".film-title-wrapper a").first().text(); 
            var link = "https://karagarga.in/browse.php?search=" + title + "&search_type=title";               
                 //alert(link);                
                    
           var l = $("#userpanel ul");
           var parent = l[0];
    
            var listItem = document.createElement('li');
            listItem.setAttribute('id','listitem');
             var a = document.createElement("a");
             a.innerHTML="KG - Search by Title";
             a.setAttribute('href', link);
             listItem.appendChild(a);
             
             parent.appendChild(listItem);
    
            $(l[0]).listview("refresh");
             
    
    }

function getImdb(href) {
    var from = href.indexOf("imdb.com/title/tt") + 17;
    if(from < 17)
        return null;
    var to = href.indexOf("/", from);
    if(to < 0)
        to = href.length;
    return href.substring(from, to);
}
 


String.prototype.contains = function(it) {
    return this.indexOf(it) != -1;
}

function xpath(query) {
    return document.evaluate(query, document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
}

(function () {
    var href = window.location.href;
    if(!href.contains("letterboxd.com/film/") && href.contains("/film/"))
       addLinkTitle();
    else if(href.contains("letterboxd.com/film/"))
       addLinkIMDB();
       
})();