- // ==UserScript==
- // @name MoreMovieRatings
- // @namespace http://www.jayxon.com/
- // @version 0.7.3
- // @description Show IMDb ratings on Douban, and vice versa
- // @description:zh-CN 豆瓣和IMDb互相显示评分
- // @author JayXon
- // @match *://movie.douban.com/subject/*
- // @match *://www.douban.com/personage/*
- // @match *://www.imdb.com/title/tt*
- // @match *://letterboxd.com/film/*
- // @grant GM.xmlHttpRequest
- // @connect api.douban.com
- // @connect movie.douban.com
- // @connect p.media-imdb.com
- // @connect www.omdbapi.com
- // ==/UserScript==
-
- 'use strict';
-
- function getURL_GM(url, headers, data) {
- return new Promise(resolve => GM.xmlHttpRequest({
- method: data ? 'POST' : 'GET',
- url: url,
- headers: headers,
- data: data,
- onload: function (response) {
- if (response.status >= 200 && response.status < 400) {
- resolve(response.responseText);
- } else {
- console.error(`Error getting ${url}:`, response.status, response.statusText, response.responseText);
- resolve();
- }
- },
- onerror: function (response) {
- console.error(`Error during GM.xmlHttpRequest to ${url}:`, response.statusText);
- resolve();
- }
- }));
- }
-
- async function getJSON_GM(url, headers, post_data) {
- const data = await getURL_GM(url, headers, post_data);
- if (data) {
- return JSON.parse(data);
- }
- }
-
- async function getJSONP_GM(url, headers, post_data) {
- const data = await getURL_GM(url, headers, post_data);
- if (data) {
- const end = data.lastIndexOf(')');
- const [, json] = data.substring(0, end).split('(', 2);
- return JSON.parse(json);
- }
- }
-
- async function getJSON(url) {
- try {
- const response = await fetch(url);
- if (response.status >= 200 && response.status < 400)
- return await response.json();
- console.error(`Error fetching ${url}:`, response.status, response.statusText, await response.text());
- }
- catch (e) {
- console.error(`Error fetching ${url}:`, e);
- }
- }
-
- async function getIMDbInfo(id) {
- const keys = ['40700ff1', '4ee790e0', 'd82cb888', '386234f9', 'd58193b6', '15c0aa3f'];
- const apikey = keys[Math.floor(Math.random() * keys.length)];
- const omdbapi_url = `https://www.omdbapi.com/?tomatoes=true&apikey=${apikey}&i=${id}`;
- const imdb_url = `https://p.media-imdb.com/static-content/documents/v1/title/${id}/ratings%3Fjsonp=imdb.rating.run:imdb.api.title.ratings/data.json`;
- let [omdb_data, imdb_data] = await Promise.all([getJSON(omdbapi_url), getJSONP_GM(imdb_url)]);
- omdb_data = omdb_data || {};
- if (imdb_data && imdb_data.resource) {
- const resource = imdb_data.resource;
- if (resource.rating) {
- omdb_data.imdbRating = resource.rating;
- }
- if (resource.ratingCount) {
- omdb_data.imdbVotes = resource.ratingCount;
- }
- if (resource.ratingsHistograms && resource.ratingsHistograms["IMDb Users"]) {
- omdb_data.histogram = resource.ratingsHistograms["IMDb Users"].histogram;
- }
- if (resource.topRank) {
- omdb_data.topRank = resource.topRank;
- }
- }
- return omdb_data;
- }
-
- async function getDoubanAPI(query) {
- return await getJSON_GM(`https://api.douban.com/v2/${query}`, {
- "Content-Type": "application/x-www-form-urlencoded; charset=utf8",
- }, "apikey=0ab215a8b1977939201640fa14c66bab");
- }
-
- async function getDoubanInfo(id) {
- const data = await getDoubanAPI(`movie/imdb/${id}`);
- if (data) {
- if (isEmpty(data.alt))
- return;
- const url = data.alt.replace('/movie/', '/subject/') + '/';
- return { url, rating: data.rating, title: data.title };
- }
- // Fallback to search.
- const search = await getJSON_GM(`https://movie.douban.com/j/subject_suggest?q=${id}`);
- if (search && search.length > 0 && search[0].id) {
- const abstract = await getJSON_GM(`https://movie.douban.com/j/subject_abstract?subject_id=${search[0].id}`);
- const average = abstract && abstract.subject && abstract.subject.rate ? abstract.subject.rate : '?';
- return {
- url: `https://movie.douban.com/subject/${search[0].id}/`,
- rating: { numRaters: '', max: 10, average },
- title: search[0].title,
- };
- }
- }
-
- function isEmpty(s) {
- return !s || s === 'N/A';
- }
-
- function insertDoubanRatingDiv(parent, title, rating, link, num_raters, histogram) {
- let star = (5 * Math.round(rating)).toString();
- if (star.length == 1)
- star = '0' + star;
- if (typeof rating === 'number')
- rating = rating.toFixed(1);
- let histogram_html = '';
- if (histogram) {
- histogram_html += '<div class="ratings-on-weight">';
- const max = Math.max(...Object.values(histogram));
- for (let i = 10; i > 0; i--) {
- const percent = histogram[i] * 100 / num_raters;
- histogram_html += `<div class="item">
- <span class="stars${i} starstop" style="width:18px;text-align:center">${i}</span>
- <div class="power" style="width:${64 / max * histogram[i]}px"></div>
- <span class="rating_per">${percent.toFixed(1)}%</span>
- <br>
- </div>`;
- }
- histogram_html += '</div>';
- }
- parent.insertAdjacentHTML('beforeend',
- `<div class="rating_logo">${title}</div>
- <div class="rating_self clearfix">
- <strong class="ll rating_num">${rating}</strong>
- <div class="rating_right">
- <div class="ll bigstar${star}"></div>
- <div style="clear: both" class="rating_sum"><a href=${link} target=_blank>${num_raters.toString().replace(/,/g, '')}人评价</a></div>
- </div>
- </div>` + histogram_html);
- }
-
- function insertDoubanInfo(name, value) {
- const info = document.querySelector('#info');
- if (info) {
- if (info.lastElementChild.nodeName != 'BR')
- info.insertAdjacentHTML('beforeend', '<br>');
- info.insertAdjacentHTML('beforeend', `<span class="pl">${name}:</span> ${value}<br>`);
- }
- }
-
- function insertLetterboxdRating(ratings, title, title_href, rating, link, num_raters, histogram) {
- let new_rating = ratings.cloneNode(true);
- new_rating.querySelector('a[href$="/fans/"]')?.remove();
- const title_element = new_rating.querySelector('a[href$="/ratings/"]');
- title_element.textContent = title;
- title_element.href = title_href;
- title_element.target = '_blank';
- let average_element = new_rating.querySelector('a.display-rating');
- if (!average_element) {
- const average_span = document.createElement('span');
- average_span.classList.add('average-rating');
- average_element = document.createElement('a');
- average_element.classList.add('tooltip');
- average_element.classList.add('display-rating');
- average_span.append(average_element);
- new_rating.querySelector('.rating-histogram').before(average_span);
- }
- const average_rating = rating / 2;
- average_element.textContent = average_rating.toFixed(1);
- average_element.href = link;
- average_element.target = '_blank';
- average_element.title = `Weighted average of ${average_rating.toFixed(2)} based on ${new Intl.NumberFormat("en-US").format(num_raters)} ratings`;
- if (histogram) {
- const histogram_elements = new_rating.querySelectorAll('li i');
- const max = Math.max(...Object.values(histogram));
- for (let i = 10; i > 0; i--) {
- const current = histogram[i];
- const percent = current * 100 / num_raters;
- if (!histogram_elements[i - 1].previousSibling) {
- histogram_elements[i - 1].before(histogram_elements[i - 1].parentNode.dataset.originalTitle.replace(/No/, current) + `(${~~percent}%)`)
- } else {
- histogram_elements[i - 1].previousSibling.textContent = histogram_elements[i - 1].previousSibling.textContent.replace(/^[\d,]+/, current).replace(/\d+%/, ~~percent + '%');
- }
- histogram_elements[i - 1].style = `height: ${Math.max(44 / max * current, 1)}px`;
- }
- }
- ratings.after(new_rating);
- }
-
- function linkifyIMDbNode(text_node, url_base) {
- const id = text_node.textContent.trim();
- let a = document.createElement('a');
- a.href = url_base + id;
- a.target = '_blank';
- a.appendChild(document.createTextNode(id));
- text_node.replaceWith(a);
- a.insertAdjacentText('beforebegin', ' ');
- return id;
- }
-
- (async () => {
- let host = location.hostname;
- if (host === 'movie.douban.com') {
- let sectl = document.getElementById('interest_sectl');
- if (!sectl) {
- // No rating, might be censored, try to recover using API
- const douban_id = location.href.match(/douban\.com\/subject\/(\d+)/)[1];
- if (!douban_id)
- return;
-
- // Insert related div back in
- const subjectwrap = document.querySelector('.subjectwrap');
- const subject = document.querySelector('.subject');
- if (!subjectwrap || !subject)
- return;
- sectl = document.createElement('div');
- sectl.id = 'interest_sectl';
- subjectwrap.insertBefore(sectl, subject.nextSibling);
- const rating_wrap = document.createElement('div');
- rating_wrap.className = 'rating_wrap';
- sectl.appendChild(rating_wrap);
-
- const data = await getDoubanAPI(`movie/${douban_id}`)
-
- if (data && data.rating && !isEmpty(data.rating.average)) {
- insertDoubanRatingDiv(rating_wrap, '豆瓣评分', data.rating.average, `https://movie.douban.com/subject/${douban_id}/collections`, data.rating.numRaters);
- rating_wrap.title = '此条目的豆瓣评分已被和谐,MoreMovieRatings恢复了部分评分';
- }
- // Move it down to leave space for fixed rating.
- if (document.querySelector('#movie-rating-iframe'))
- sectl.style.marginTop = '96px';
- }
-
- // Douban stops linking to IMDb, so find the text node instead and retore the link.
- const imdb_text = [...document.querySelectorAll('#info > span.pl')].find(s => s.innerText.trim() == 'IMDb:');
- if (!imdb_text) {
- console.log('IMDb id not available');
- return;
- }
- const text_node = imdb_text.nextSibling;
- const id = linkifyIMDbNode(text_node, 'https://www.imdb.com/title/');
-
- const data = await getIMDbInfo(id);
- if (!data)
- return;
- if (isEmpty(data.imdbRating) && isEmpty(data.Metascore)) {
- console.log('MoreMovieRatings: No ratings found');
- return;
- }
- const ratings = document.createElement('div');
- ratings.style.padding = '15px 0';
- ratings.style.borderTop = '1px solid #eaeaea';
- let rating_wrap = document.querySelector('.friends_rating_wrap');
- if (!rating_wrap)
- rating_wrap = document.querySelector('.rating_wrap');
- sectl.insertBefore(ratings, rating_wrap.nextSibling);
- ratings.className = 'rating_wrap clearbox';
- // Reduce whitespace
- sectl.style.marginBottom = document.querySelector('.colbutt') ? '-136px' : '-154px';
- const rec_sec = document.querySelector('.rec-sec');
- if (rec_sec)
- rec_sec.style.width = '488px';
- const interest_sect_level = document.querySelector('#interest_sect_level');
- if (interest_sect_level)
- interest_sect_level.style.width = '488px';
- // IMDb
- if (!isEmpty(data.imdbRating)) {
- insertDoubanRatingDiv(ratings, 'IMDb评分', data.imdbRating, `https://www.imdb.com/title/${id}/ratings`, data.imdbVotes, data.histogram);
- // IMDb Top 250
- if (!isEmpty(data.topRank) && data.topRank <= 250) {
- // inject css if needed
- if (document.getElementsByClassName('top250').length === 0) {
- const style = document.createElement('style');
- style.innerHTML = '.top250{background:url(https://img1.doubanio.com/f/movie/f8a7b5e23d00edee6b42c6424989ce6683aa2fff/pics/movie/top250_bg.png) no-repeat;width:150px;font:12px Helvetica,Arial,sans-serif;margin:5px 0;color:#744900}.top250 span{display:inline-block;text-align:center;height:18px;line-height:18px}.top250 a,.top250 a:link,.top250 a:hover,.top250 a:active,.top250 a:visited{color:#744900;text-decoration:none;background:none}.top250-no{width:34%}.top250-link{width:66%}';
- document.head.appendChild(style);
- }
- let after = document.getElementById('dale_movie_subject_top_icon');
- if (!after)
- after = document.querySelector('h1');
- after.insertAdjacentHTML('beforebegin', `<div class="top250"><span class="top250-no">No.${data.topRank}</span><span class="top250-link"><a href="https://www.imdb.com/chart/top">IMDb Top 250</a></span></div>`);
- [].forEach.call(document.getElementsByClassName('top250'), function (e) {
- e.style.display = 'inline-block';
- });
- }
- }
-
- // Metascore
- if (!isEmpty(data.Metascore)) {
- const metascore = parseInt(data.Metascore);
- let metacolor;
- if (metascore >= 60)
- metacolor = '#6c3';
- else if (metascore >= 40)
- metacolor = '#fc3';
- else
- metacolor = '#f00';
- ratings.insertAdjacentHTML('beforeend',
- `<br>Metascore:
- <span style="background-color: ${metacolor}; color: #fff; height: 24px; width: 24px; line-height: 24px; vertical-align: middle; display: inline-block; text-align: center; font-weight: bold">
- ${data.Metascore}
- </span>`
- );
- }
-
- // Rotten Tomatoes
- let tomato_score = null;
- for (let i in data.Ratings) {
- if (data.Ratings[i].Source == 'Rotten Tomatoes') {
- tomato_score = data.Ratings[i].Value;
- break;
- }
- }
- if (tomato_score) {
- ratings.insertAdjacentHTML('beforeend', '<br>');
-
- const tomatoimg = {
- 'certified': 'iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAAEyElEQVR4AdWTY4DkSABGXyXpTqYxRk+PT2sLZ9u2bdu2bdvmeG27b8dWWkhSZxO/7sWo7xX53yP4C/yGGtx7M/f+20xWtivNE5mOBAGicp4zZ+4C53Pg3X8l0DVh3H+695GjDuLwxqjklsd8lBbaDN/Y+vZaP89FcaHDqDyn9dQbkxcBz/xtwaAC19CZz3jm1a4X+gfVOhcfH+G9SjejBqeonaMzYpDFgy96OHi3GMUBG78Oi2fw3lG3mwcAsT8VDP4m/FV97pd9GB/WGDS1KRQVSE4+IMxDs3OZEjTJVGwkMHJQikPPz+SW80z6TMGSma7lwNA/FBiaMFY+m9V307uanpUuOfmgKO9U6l+HR4lZKue9HKQs6HDqZm3oikN/WLAipHHZPX5KAjbnHh7htefFPcCZfI/Gzzh3d//NxaNj+hYtBg++4qG8THLkPjGqm7O5e3ohfQv6aGkQ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cRvhuvaoIwDoyzYaLBRCEIMtfoIPN8DYRxURQGhPnxQ+B6BSTkfjWUfQHXE2l0btXdnCyK+/vVpGIYZWEUaG0BAKQEJQkRBwMCFGGQlFHgkRRX4YKAE4BqgvjqxPM939gEM9hoblYTWUqpwmDHpBkysXIKRai8MqwbTqsO2dZh2HYb5Z+J1GNYoeodXgcLGxHYeYeZAtxXsHCLQBrQR1/GNfQDbN47NMgyn2j4+fJ9ujGQkMYGonIYgRMCHJHCcEPQECEGIA6q1Pjz79r0Yre3E2VNGkRHqsHgev65T4Lqt2rd0g3XQTr705uaXuyZGH5T4JCgNwXHNv5stCllqQKUkVKUQHOev+BBbdy3Hw1fciS41jj2bF4AQAeFkS+/Fd794NoD1+Fv/ZnzXlvpsQUa+p3ty1xnTb2PlwkSSTVQg8BEYZg39Q9uweccCrNn4E+raACyXQIaBKc05REsTURvYiWg8JYyf0Fnp7xvEgqVbN45VdYfsO4YJpyb5rkxO6Sw3FdtLTbm2YqnU1N7W1dwYd4lYLK6KgiQ2QomvZ74Es7oV906ahpbWqUDYgM8SQSn7zgC+XUA++fHXxT+Qo5n9gsipUYXPp9JqUyIdbS2VcxXGG20O65vQU0hHWtTSxrOnTu+CuUsaHBrarVaupG99OPPNWXOXzyI4ToVFFm/rjF1BeGRH99o/P3DLRVcrvB6fu3DtPCtU1mbNXTFzeGRsGCd0JP0BLHO0MJZ4Kw0AAAAASUVORK5CYII='
- };
- // Currently no way to know if it's certified or not
- let fresh;
- if (parseInt(tomato_score) >= 60)
- fresh = 'fresh';
- else
- fresh = 'rotten';
- const tomato_url = data.tomatoURL.replace('http://', 'https://');
- ratings.insertAdjacentHTML('beforeend',
- "<a href=" + tomato_url + " target=_blank style='background:none'><span style='background: url(data:image/png;base64," + tomatoimg[fresh] + ") no-repeat; background-size: cover; width: 18px; height: 18px; margin: 0 2px; vertical-align: middle; display: inline-block'></span></a>" +
- "<span style='vertical-align: middle; display: inline-block; line-height: 18px'>" + tomato_score + "</span>"
- );
- if (!isEmpty(data.tomatoUserMeter)) {
- let userimage;
- if (parseFloat(data.tomatoUserRating) >= 3.5)
- userimage = "full";
- else
- userimage = "spilled";
-
- ratings.insertAdjacentHTML('beforeend',
- "<a href=" + tomato_url + " target=_blank style='background:none'><span style='background: url(data:image/png;base64," + tomatoimg[userimage] + ") no-repeat; background-size: cover; width: 18px; height: 18px; margin: 0 2px; vertical-align: middle; display: inline-block'></span></a>" +
- "<span style='vertical-align: middle; display: inline-block; line-height: 18px'>" + data.tomatoUserMeter + "%</span>"
- );
- }
- }
-
- // MPAA Rating
- if (!isEmpty(data.Rated)) {
- insertDoubanInfo('MPAA评级', data.Rated);
- }
-
- // Box office
- if (!isEmpty(data.BoxOffice)) {
- insertDoubanInfo('票房', data.BoxOffice);
- }
- } else if (host === 'www.douban.com') {
- // www.douban.com/personage/*
- let person_id_node = [...document.querySelectorAll('span.value')].find(s => s.innerText.trim().match(/^nm\d+/));
- if (person_id_node) {
- linkifyIMDbNode(person_id_node, 'https://www.imdb.com/name/');
- }
- } else if (host === 'www.imdb.com') {
- const id = location.href.match(/tt\d+/);
- if (!id)
- return;
- const data = await getDoubanInfo(id);
- if (!data)
- return;
- const imdb_rating = document.querySelector('.rating-bar__base-button');
- if (!imdb_rating) {
- console.log('rating bar not found, IMDb UI updated again?');
- return;
- }
-
- let douban_rating = imdb_rating.cloneNode(true);
- douban_rating.firstElementChild.textContent = 'Douban RATING';
- douban_rating.children[1].href = data.url;
- douban_rating.children[1].target = '_blank';
- douban_rating.children[1].title = data.title;
- const rating_div = douban_rating.querySelector('div[data-testid="hero-rating-bar__aggregate-rating__score"]');
- rating_div.firstElementChild.textContent = data.rating.average;
- rating_div.nextElementSibling.nextElementSibling.textContent = new Intl.NumberFormat("en-US", {
- notation: 'compact',
- }).format(data.rating.numRaters);
- imdb_rating.insertAdjacentElement('beforebegin', douban_rating);
- } else if (host === 'letterboxd.com') {
- const imdb_link = document.querySelector('.text-link a[href*="://www.imdb.com/"]');
- if (!imdb_link)
- return;
- const id = imdb_link.href.match(/tt\d+/);
-
- const [imdb_data, douban_data] = await Promise.all([getIMDbInfo(id), getDoubanInfo(id)]);
- const ratings = document.querySelector('.ratings-histogram-chart');
- if (!ratings) {
- console.log('ratings section not found');
- return;
- }
-
- if (imdb_data && !isEmpty(imdb_data.imdbRating)) {
- insertLetterboxdRating(ratings, 'IMDb', 'https://www.imdb.com/title/' + id, imdb_data.imdbRating, `https://www.imdb.com/title/${id}/ratings`, imdb_data.imdbVotes, imdb_data.histogram)
- }
-
- if (douban_data) {
- insertLetterboxdRating(ratings, 'Douban', douban_data.url, douban_data.rating.average, douban_data.url + 'comments', douban_data.rating.numRaters, null)
- }
- }
- })();