IMDb details page links

Adds some links to IMDb details page

目前为 2015-08-11 提交的版本,查看 最新版本

// ==UserScript==
// @name           IMDb details page links
// @namespace      IMDb.com
// @description    Adds some links to IMDb details page
// @include        *imdb.com/title/*
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @grant          GM_getValue
// @grant          GM_setValue
// @version 1.1
// ==/UserScript==  

// CHANGELOG
// 1.1 - Update URLs      

// https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/Trim
if(!String.prototype.trim) {
    String.prototype.trim = function () {
        return this.replace(/^\s+|\s+$/g,'');
    };
}

function defaultSites() {
    return [{title:"Google",           url:"http://www.google.com/search?q={title} {year}"},
            {title:"Subtitles",        url:"http://www.google.com/search?q={title} {year} subtitles"},
            {title:"YouTube",          url:"http://www.youtube.com/results?search_query={title} {year}"},
            {title:"iCheckMovies",     url:"http://www.icheckmovies.com/search/movies/?query={imdbid}"},
            {title:"RottenTomatoes",   url:"http://www.rottentomatoes.com/search/?search={title}"},
            {title:"HDBits",           url:"http://hdbits.org/browse2.php#film/dir=null&searchtype=film&actorfilm=film&search={imdbid}"},
            {title:"AsianDVDClub",     url:"http://asiandvdclub.org/browse.php?search={imdbid}&descr=1"},
            {title:"PassThePopCorn",   url:"http://passthepopcorn.me/torrents.php?searchstr={imdbid}"},
            {title:"KaraGarga",        url:"http://karagarga.in/browse.php?incldead=&d=&sort=&search={imdbidn}&search_type=imdb"},    
            {title:"Cinemageddon",     url:"http://cinemageddon.net/browse.php?search={imdbid}&proj=0"},
            {title:"AsiaTorrents",     url:"https://avistaz.to/torrents?in=1&search={title}&tags=&type=0&language=0&subtitle=0&discount=0&rip_type=0&video_quality=0&tv_type=0&uploader="},
            {title:"TehConnection",    url:"http://tehconnection.eu/torrents.php?searchstr={title}"},
            {title:"WhatTheMovie",     url:"http://whatthemovie.com/search?t=movie&q={imdbid}"},
            {title:"Mubi",             url:"http://www.google.com/search?q=site:mubi.com {title} {year}"},
            {title:"ListAL",           url:"http://www.google.com/search?q=site:listal.com {title} {year}"},
            {title:"HanCinema",        url:"http://www.hancinema.net/googlesearch.php?cx=partner-pub-1612871806153672%3A2t41l1-gajp&cof=FORID%3A10&ie=ISO-8859-1&hl=en&q={title}"},    
            {title:"Criticker",        url:"http://www.criticker.com/?st=movies&h={imdbid}&g=Go"},
            {title:"iCM Highest Rated",url:"http://themagician.host56.com/highestrated/search/#search={imdbid}"}];
}

/**
 * @brief Find header element
 * @return Header element or null if not found 
 */ 
function findHeader() {
    $header = null;
    if(location.href.indexOf("reference") === -1 && 
            location.href.indexOf("combined") === -1) {
        $overview = $("#overview-top");    
        if($overview !== null) {
            $header = $overview.find(".header:first");
        }                                                               
    }
    else {
        $header = $("#tn15title");                
    }
    return $header;
}

function parseConstants() {
    $header = findHeader();
    if($header.length === 0) {
        return null;
    }
    
    var matches = $header.text().replace(/(\r\n|\n|\r)/gm,"").match(/(.*)(?:[\s]+)(?:.*)\(.*([0-9]{4})/);
    var imdb_id = window.location.href.match(/(tt[0-9]+)/)[0];
    return {title: matches[1].trim(),
            year: matches[2].trim(),
            imdbid: imdb_id,
            imdbid_n: imdb_id.replace("tt", "")};
}

var App = {
    links: [],
    init: function() {
        $root = $("#pagecontent");
        $root.css("position", "relative");
        
        $c = $("<div></div>");
        $c.attr("id", "linkbar");
        $c.css({width: "150px", padding: "15px",
                textAlign: "right", position: "absolute", top: "8px",
                left: "-170px", backgroundColor: "#fff"});
                                
        $root.append($c);
        
        var sites = defaultSites();
        for(var i = 0; i < sites.length; ++i) {
            App.addSite(sites[i]);
        }
    },
    addSite: function(site) {
        var c = parseConstants();
        if(c === null) {
            return;
        }
        var url = site.url.replace("{title}", c.title)
                            .replace("{year}", c.year)
                            .replace("{imdbid}", c.imdbid)
                            .replace("{imdbidn}", c.imdbid_n);
        $root = $("#linkbar");                            
        $link = $("<a></a>");
        $link.attr("href", url);
        $link.text(site.title);
        $link.css({display: "block", marginBottom: "2px"});        
        $root.append($link);
    }
};

$(window).ready(App.init);