// ==UserScript== // @name TMDB-Info-for-PTP // @namespace https://github.com/techmovie/TMDB-Info-for-PTP // @version 0.2 // @description 在电影详情页展示部分中文信息 // @author Mekio // @match http*://passthepopcorn.me/torrents.php?id=* // @grant none // @downloadURL none // ==/UserScript== (function () { 'use strict'; const API_KEY = 'YOUR TMDB API_KEY'; const TMDB_URL = 'https://api.themoviedb.org/3'; const imdbLink = $('#imdb-title-link').attr('href'); if (!imdbLink) { return } const imdbId = /tt\d+/.exec(imdbLink)[0]; $.ajax({ url: `${TMDB_URL}/find/${imdbId}`, dataType: 'jsonp', data: { api_key: API_KEY, external_source: 'imdb_id' }, success(data) { if (data.movie_results.length > 0) { getMovieInfo(data.movie_results[0].id) } } }) const getMovieInfo = (movieId) => { $.ajax({ url: `${TMDB_URL}/movie/${movieId}`, dataType: 'jsonp', data: { api_key: API_KEY, language: 'zh-CN', append_to_response: 'credits,images' }, success(data) { addInfoToPage(data); } }) } const addInfoToPage = (data) => { const genres = data.genres.map(item => item.name) if (isChinese(data.title)) { $('.page__title').prepend(`[${data.title}] `) } if (data.overview) { $('#synopsis').html(data.overview) } if (genres.length > 0) { $('#movieinfo .panel__body').prepend(`
类型: ${genres.join('/')}
`) } if (data.credits && data.credits.cast.length) { const casts = data.credits.cast.map(item => { const imageEl = item.profile_path ? ` ` : `
` return `
  • ${imageEl}
    ${item.name}
    ${item.character}
  • ` }) const castPanelEl = `
    主演
    `; $('#synopsis-and-trailer').next('.panel').after(castPanelEl); } } const isChinese = (title) => { return /[\u4e00-\u9fa5]+/.test(title) } })();