// ==UserScript== // @name Douban-Info-for-PTP&HDB // @namespace https://github.com/techmovie/Douban-Info-for-PTP // @version 0.4 // @description 在ptp和hdb电影详情页展示部分中文信息 // @author birdplane // @match https://passthepopcorn.me/torrents.php?id=* // @match https://hdbits.org/details.php?id=* // @grant GM_addStyle // @grant GM_xmlhttpRequest // @resource emptyIcon https://www.themoviedb.org/assets/2/v4/glyphicons/basic/glyphicons-basic-4-user-grey-d8fe957375e70239d6abdd549fd7568c89281b2179b5f4470e2e12895792dfa5.svg // @downloadURL none // ==/UserScript== (function () { 'use strict'; const API_KEY = '054022eaeae0b00e0fc068c0c0a2102a'; const DOUBAN_API_URL = 'https://frodo.douban.com/api/v2'; const DOUBAN_SEARCH_API = 'https://movie.douban.com/j/subject_suggest'; const isPTP = location.host.includes('passthepopcorn'); const isHDB = location.host.includes('hdbits'); let imdbLink = null if(isPTP){ imdbLink = $('#imdb-title-link').attr('href'); } if(isHDB){ imdbLink = $j('.contentlayout h1 a').attr('href'); } if (!imdbLink) { return } const imdbId = /tt\d+/.exec(imdbLink)[0]; GM_xmlhttpRequest({ method: 'GET', url: `${DOUBAN_SEARCH_API}?q=${imdbId}`, onload(res) { const data = JSON.parse(res.responseText); if (data.length > 0) { getMovieInfo(data[0].id) } } }) const getMovieInfo = (movieId) => { GM_xmlhttpRequest({ url: `${DOUBAN_API_URL}/movie/${movieId}?apiKey=${API_KEY}`, onload(res) { const data = JSON.parse(res.responseText); if(isPTP){ addInfoToPtpPage(data); } if(isHDB){ addInfoToHdbPage(data); } } }) } const addInfoToHdbPage = (data) => { const infoContent = `
- 豆瓣信息
豆瓣评分 ${data.rating.value}  (${data.rating.count} votes)
${data.intro|| '暂无简介'}
导演: ${data.directors.map(item => { return ` ${item.name} ` })}
类型: ${data.genres.join('/')}
制片国家/地区: ${data.countries.join('/')}
语言: ${data.languages.join('/')}
时长: ${data.durations.join('/')}
又名: ${data.aka.join('/')}
${createCastDom(data)}
` $j('#details>tbody>tr').eq(1).before(infoContent); } const addInfoToPtpPage = (data) => { if (isChinese(data.title)) { $('.page__title').prepend(`[${data.title}] `) } if (data.intro) { $('#synopsis').html(data.intro) } $('#movieinfo').before(`
电影信息
导演: ${data.directors.map(item => { return ` ${item.name} ` })}
类型: ${data.genres.join('/')}
制片国家/地区: ${data.countries.join('/')}
语言: ${data.languages.join('/')}
时长: ${data.durations.join('/')}
又名: ${data.aka.join('/')}
`) if (data.rating.value) { $('#movie-ratings-table tr').prepend( `
豆瓣评分
${data.rating.value} / ${data.rating.max}
(${data.rating.count} votes)`) } const castEl = createCastDom(data); if(castEl){ const castPanelEl = `
主演
    ${castEl}
`; $('#synopsis-and-trailer').next('.panel').after(castPanelEl); } } const isChinese = (title) => { return /[\u4e00-\u9fa5]+/.test(title) } const createCastDom=(data)=>{ if (data.actors && data.actors.length) { const castsDom = data.actors.map(item => { const imageEl = item.cover_url ? ` ` : `
` return `
  • ${imageEl}
  • ` }); return castsDom; } return '' } GM_addStyle( ` .contentlayout.douban-info { display: flex; justify-content: space-around; } .detail .title{ font-size: 26px; font-weight: 600; margin-bottom: 20px; } .detail .title a{ text-decoration: none; } .movie-detail{ display: flex; justify-content: space-between; } .movie-detail .synopsis { width: 60%; } .movie-detail .movieinfo { margin-right: 20px; max-width: 30%; } .icon-pt1{ font-size: 14px; display: inline-block; text-align: center; border: 1px solid #41be57; background-color: #41be57; color: white; border-top-left-radius: 4px; border-bottom-left-radius: 4px; width: 24px; height: 24px; line-height: 24px; } .icon-pt2{ display: inline-block; text-align: center; border: 1px solid #41be57; color: #3ba94d; background: #ffffff; border-top-right-radius: 4px; border-bottom-right-radius: 4px; width: 69px; height: 24px; line-height: 24px; font-size: 14px; } .cast-emty{ background-image: url(GM.getResourceUrl("emptyIcon")); width: auto; display: flex; align-content: center; align-items: center; flex-wrap: wrap; overflow: hidden; height: 100%; background-position: center center; background-repeat: no-repeat; background-color: #dbdbdb; box-sizing: border-box; background-size: 50%; text-overflow: ellipsis; } .cast-item{ margin-top: 10px; margin-bottom: 10px; flex-shrink: 0; display: inline-block; margin-left: 10px; margin-right: 4px; width: 138px; background-color: #fff; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); padding-bottom: 10px; border-radius: 6px; overflow: hidden; } .cast-item-image{ width: 138px; height: 175px; display:block; overflow: hidden; } .cast-item .actor-name{ color: #000; font-weight: bold; padding: 10px 10px 0; } `) })();