// ==UserScript== // @name DOUBAN Movie info for RARBG // @namespace http://rarbg.to/ // @version 0.4.1 // @description Adds douban movie info to RARBG.to // @author tofuliang // @match https://rarbg.to/* // @match http://rarbg.to/* // @grant GM_xmlhttpRequest // @grant GM_getValue // @grant GM_setValue // @connect api.douban.com // @downloadURL none // ==/UserScript== function isEmpty(s) { return !s || s === 'N/A'; } $('body').on('mouseenter', 'a[data-imdbId]', function() { var imdbId = $(this).attr('data-imdbId'); var aTag = this; overlib('数据加载中...'); function showDouBanInfo(data,aTag) { var html = ''; html += '
'; html += '
'; html += '

' + data.title + ' ' + data.alt_title + ' (' + data.attrs.year.join(' / ') + ')

'; html += '
'; html += '
'; html += '
'; html += '

' + data.rating.average + ' / ' + data.rating.numRaters + '

'; html += '
'; html += '
'; if (!isEmpty(data.attrs.pubdate)) { html += '

上映时间: ' + data.attrs.pubdate.join(' / ') + '

'; } if (!isEmpty(data.attrs.movie_duration)) { html += '

片长: ' + data.attrs.movie_duration.join(' / ') + '

'; } if (!isEmpty(data.attrs.title)) { html += '

别名: ' + data.attrs.title.join(' / ') + '

'; } if (!isEmpty(data.attrs.director)) { html += '

导演: ' + data.attrs.director.join(' / ') + '

'; } if (!isEmpty(data.attrs.writer)) { html += '

编剧: ' + data.attrs.writer.join(' / ') + '

'; } if (!isEmpty(data.attrs.cast)) { html += '

主演: ' + data.attrs.cast.join(' / ') + '

'; } if (!isEmpty(data.attrs.movie_type)) { html += '

类型: ' + data.attrs.movie_type.join(' / ') + '

'; } if (!isEmpty(data.attrs.country)) { html += '

制片国家/地区: ' + data.attrs.country.join(' / ') + '

'; } if (!isEmpty(data.attrs.language)) { html += '

语言: ' + data.attrs.language.join(' / ') + '

'; } if (!isEmpty(data.summary)) { html += '

简介: ' + data.summary + '

'; } html += '
'; html += '
'; overlib(html); var link = data.mobile_link.replace('m.douban.com','douban.com'); $(aTag).attr('href',link).attr('target','_blank'); } var data = GM_getValue('douBanInfo_' + imdbId, undefined); if (undefined !== data && +(new Date()) - data.lastModify < 86400000) { showDouBanInfo(data,aTag); return; } GM_xmlhttpRequest({ method: 'GET', url: 'https://api.douban.com/v2/movie/imdb/' + imdbId, onload: function(response) { var data = JSON.parse(response.responseText); if (5000 === data.code) { overlib('你太潮了,豆瓣都没资料...'); }else if (!isEmpty(data.alt)) { data.lastModify = +(new Date()); GM_setValue('douBanInfo_' + imdbId, data); showDouBanInfo(data,aTag); }else{ overlib('天晓得发生什么是了...'); } }, onerror: function () { overlib('你网络有问题...'); }, ontimeout: function () { overlib('豆瓣不鸟你...'); } }); }); $(document).on('ready AutoPagerize_DOMNodeInserted', function(e) { $('a[href^="/torrents.php?imdb="]').each(function(i,e){ var ee = $(e); if(ee.attr('doubaned') =='doubaned') return; var imdbId = $(this).attr('href').split("=").pop(); ee.after(''); ee.attr('doubaned','doubaned'); }); $('.lista span:contains("IMDB:")[hightlighted!=1]').each(function() { var txt = $(this).text(); var rate = txt.match(/MDB: ([\d\.]+)\/\d+/); if (undefined !== rate[1] && 6.0 <= parseFloat(rate[1])) { $(this).html($(this).text().replace(rate[1], '' + rate[1] + '')).attr('hightlighted', 1); } }); var thisYear = (new Date()).getFullYear(); var years = [thisYear - 2, thisYear - 1, thisYear]; for (var i in years) { $('a[href^="/torrent/"]:contains("' + years[i] + '")[hightlighted!=1]').each(function() { $(this).html($(this).text().replace(years[i], '' + years[i] + '')).attr('hightlighted', 1); }); } }); $(document).bind("ready", function() {}); $(document).ready(function() { $(document).trigger("ready"); });