${tmdb_en_overview_300}
// ==UserScript== // @name Letterboxd Enhancer 中文增强显示与搜索:集合啦!数字难民 // @namespace http://tampermonkey.net/ // @version 0.4 // @connect * // @description Letterboxd全局TMDB中文标题搜索 / 查询bt、字幕源是否存在 / 电影详情页增加显示:电影中文标题|导演中文名|中文简介|演员头像列表(中日韩演员显示中文名)|豆瓣ID图标|IMDB电影宽高比、底片格式 // @thanks Catspinner bimzcy Rhilip LeLobster // @author estost // @match https://letterboxd.com/film/* // @match https://letterboxd.com/* // @match https://letterboxd.com* // @license estost // @grant GM_xmlhttpRequest // @grant GM_addStyle // @grant GM_setValue // @grant GM_getValue // @icon https://letterboxd.com/favicon.ico // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js // @downloadURL none // ==/UserScript== // 设置横向滚动条的样式 GM_addStyle(` /* 滚动条整体样式 */ ::-webkit-scrollbar { width: 8px; height: 6px; background-color: #14181c; } /* 滑道样式 */ ::-webkit-scrollbar-track:horizontal { background-color: #14181c; } /* 滑块样式 */ ::-webkit-scrollbar-thumb:horizontal:hover { background-color: #242c34; border-radius: 5px; \`); `); // 设置竖向滚动条的样式 GM_addStyle(` /* 滚动条整体样式 */ ::-webkit-scrollbar { width: 6px; height: 8px; background-color: #202830; } /* 滑道样式 */ ::-webkit-scrollbar-track:vertical { background-color: #202830; } /* 滑块样式 */ ::-webkit-scrollbar-thumb:vertical { background-color: #14181c; border-radius: 5px; } `); // 默认显示details菜单 var currentUrl = window.location.href; if (currentUrl.startsWith('https://letterboxd.com/film/') && currentUrl.indexOf('/details') === -1 && currentUrl.indexOf('/lists/') === -1 && currentUrl.indexOf('/members/') === -1) { window.location.replace(currentUrl + 'details/'); } var tmdb_api = '你的api' var tmdb_api = GM_getValue('tmdb_api', ''); if (tmdb_api.length <= 15) { var api = prompt('请输入 TMDB API:'); if (api !== null && api.length > 0) { GM_setValue('tmdb_api', api); alert('TMDB API设置成功!'); } } $(document).ready(function () { // 获取imdb/tmdb id/原始标题/电影年份 var imdb_nb = ''; try { imdb_nb = [...document.querySelectorAll(".micro-button")].find(a => a.href.includes("imdb")).href.split("/tt")[1].split("/")[0]; } catch (error) { imdb_nb = null; } var imdb_id = 'tt' + imdb_nb var tmdb_id = [...document.querySelectorAll(".micro-button")].find(a => a.href.includes("themoviedb")).href.split(/\/(movie|tv)\//)[2].split("/")[0].split("/")[0]; var imdb_link = `https://www.imdb.com/title/${imdb_id}/` var has_imdb_button = imdb_id.length > 0; // 从 Letterboxd 中已有的数组 filmData 中获取电影的标题和年份 // var filmTitle01 = filmData['name'] // filmTitle01 = filmTitle01.replace(/[\/\\#,+()$~%.":*?<>{}!&]/g, ''); // var filmYear01 = filmData['releaseYear'] var film_title = $('#featured-film-header').find('h1').text().replace(/[\/\\#,+()$~%.":*?<>{}!&]/g, '').replace(/\xa0/g, ' '); var film_year = $('#featured-film-header a[href*="films/year/"]').text(); var originalTitle = $('#featured-film-header').not('#chi_title').find('em').text().replace(/[\/\\#,+()$~%.":*?<>{}!&]/g, ''); var film_language_a = $('div#tab-details span:contains("Language")').parent('h3').next('div').find('a'); console.log(`IMDB ID: ${imdb_id}`) console.log(`TMDB ID: ${tmdb_id}`) console.log(`英文标题: ${film_title}`) console.log(`原始标题: ${originalTitle}`) console.log(`电影年份: ${film_year}`) function hasJapanese(str) { var regExp = /[\u3040-\u309F\u30A0-\u30FF\u31F0-\u31FF\uFF65-\uFF9F]/g; return regExp.test(str); } function getZhName(also_known_as) { // 判断是不是简体中文字符 function isSimpChinese(char) { return /^[\u4E00-\u9FA5]+$/.test(char); } // 判断是不是繁体中文字符 function isTradChinese(char) { return /^[\u4E00-\u9FFF]+$/.test(char); } // 判断是不是日文汉字 function isJapaneseKanji(char) { return /^[\u4E00-\u9FFF\u3400-\u4DBF]+$/.test(char); } // 判断是不是日文平假名 function isHiragana(char) { return /^[\u3040-\u309F]+$/.test(char); } // 判断是不是日文片假名 function isKatakana(char) { return /^[\u30A0-\u30FF]+$/.test(char); } function isHangul(char) { const unicode = char.charCodeAt(0); return unicode >= 0xAC00 && unicode <= 0xD7AF; } const weights = { "汉": {"simp": 10, "trad": 8, "jap": 7}, "ひらがな": {"jap": 2}, "カタカナ": {"jap": -2}, "kor": {"kor": -3} }; let maxWeight = 0; let zhjaName = ""; let minStrokeNames = []; // 记录权重相同且笔画最少的名字 let minStrokeCount = Number.MAX_SAFE_INTEGER; // 记录当前权重相同名字中笔画最少的名字的笔画数 let isAllNonChineseJapanese = true; // 新增变量,记录是否所有名字都不含汉字和平假名 for (let i = 0; i < also_known_as.length; i++) { const name = also_known_as[i]; let weight = 0; if (/(豆瓣)$/.test(name)) return name.replace('(豆瓣)', ''); let isNonChineseJapanese = true; // 新增变量,记录当前名字是否不含汉字和平假名 for (let j = 0; j < name.length; j++) { let char = name[j]; if (isSimpChinese(char)) { weight += weights["汉"]["simp"] || 0; isNonChineseJapanese = false; } else if (isTradChinese(char)) { weight += weights["汉"]["trad"] || 0; isNonChineseJapanese = false; } else if (isJapaneseKanji(char)) { weight += weights["汉"]["jap"] || 0; isNonChineseJapanese = false; } else if (isHiragana(char)) { weight += weights["ひらがな"]["jap"] || 0; isNonChineseJapanese = false; } else if (isKatakana(char)) { weight += weights["カタカナ"]["jap"] || 0; isNonChineseJapanese = false; } else if (isHangul(char)) { weight += weights["kor"]["kor"] || 0; } } if (isNonChineseJapanese) { continue; // 如果当前名字不含汉字和平假名,则继续循环下一个名字 } else { isAllNonChineseJapanese = false; // 反之,记录当前名字为包含汉字和平假名的名字 } if (weight > maxWeight) { maxWeight = weight; zhjaName = name; } } if (isAllNonChineseJapanese) { return ""; // 如果所有名字都不含汉字和平假名,则返回 null } let return_name = zhjaName || ''; return return_name.replace('(dorama.info)', '').replace('(旧芸名)', '').replace('(本名)', ''); } $(document).ready(function () { $('#userpanel').css('margin-top', '-30px'); }); // 获取导演中文名 function getDirectorAndAKA(tmdb_id) { return new Promise((resolve, reject) => { $.getJSON(`https://api.themoviedb.org/3/movie/${tmdb_id}/credits?api_key=${tmdb_api}`, function (data) { const crew = data.crew; let director = null; // 找到第一位导演信息 for (let i = 0; i < crew.length; i++) { if (crew[i].job === 'Director') { director = crew[i]; break; } } if (director !== null) { // 获取导演的 AKA 信息 $.getJSON(`https://api.themoviedb.org/3/person/${director.id}?api_key=${tmdb_api}`, function (data) { console.log(`导演aka: ${data.also_known_as}`) resolve(data.also_known_as); // resolve(`${director.name} (${data.also_known_as.join(', ')})`); }); } else { reject('未找到导演信息!'); } }); }); }; async function printDirectorAndAKA(tmdb_id) { try { const director_aka = await getDirectorAndAKA(tmdb_id); console.log(director_aka); var dir_zh_txt = getZhName(director_aka).replace(' ', ''); var dir_en = $('#featured-film-header p').children('a:first').find('.prettify'); dir_en.css({'font-weight': '300'}); var dir_en_txt = dir_en.text(); dir_en.text(`${dir_zh_txt} ${dir_en_txt}`); } catch (error) { console.error(error); } }; printDirectorAndAKA(tmdb_id); // 定义获取tmdb电影信息的函数 var tmdb_zh_overview = ''; $.getJSON( "https://api.themoviedb.org/3/movie/" + tmdb_id + "?api_key=" + tmdb_api + "&language=zh-CN", function (tmdb_zh_data) { console.log(tmdb_zh_data); tmdb_zh_overview = tmdb_zh_data.overview; console.log(tmdb_zh_overview); createTmdbZhOverview(tmdb_zh_overview); // 在回调函数中执行封装函数 } ); GM_addStyle(` #overview-content header { border-bottom: 1px solid #456; margin-bottom: 15px; } #overview-content header ul { margin-bottom: -1px; overflow: hidden; } #overview-content header ul li { float: left; font-size: 1rem; letter-spacing: .075em; line-height: 1; margin: 0 15px 0 0; text-transform: uppercase; } #overview-content header ul li a { cursor: pointer; color: #00e054; display: block; padding: 0 0 5px; } #overview-content header ul li.selected a { border-bottom: 1px solid #fff; color: #fff; } `); // 创建tmdb中文简介栏 function createTmdbZhOverview(tmdb_zh_overview) { var en_condenseable = $('div.review.body-text.-prose.-hero.prettify').find('div.condenseable'); var tmdb_en_overview = ''; var tmdb_en_overview_300 = ''; var tmdb_zh_overview_140 = tmdb_zh_overview.substring(0, 140); console.log(tmdb_zh_overview_140); // 判断页面原英文简介是否折叠 if (en_condenseable.length) { tmdb_en_overview = $('.truncate.condenseable').find('p').text().replace('×', ''); console.log(tmdb_en_overview); tmdb_en_overview_300 = tmdb_en_overview.substring(0, 300); console.log(`原英文简介折叠了:${tmdb_en_overview_300}`); } else { const en_truncate = $('.review.body-text.-prose.-hero.prettify .truncate p'); tmdb_en_overview_300 = en_truncate.text(); console.log(`原英文简介没有折叠:${tmdb_en_overview_300}`) } // 创建选项卡和内容的HTML const tabbedContentHtml = `
`; $('.section.col-10.col-main section').hide(); // 在#tabbed-content div之前插入选项卡内容 $('#tabbed-content').before(tabbedContentHtml); // 判断原英文简介是否折叠 并创建…more 按键 if (en_condenseable.length) { $('#en_overview_truntxt').append(`…more`); } // 判断tmdb中文简介长度是否大于140 并创建 …more 按键 if ((tmdb_zh_overview.length > 140)) { $('#zh_overview_truntxt').append(`…更多`); } // 判断tagline是否存在 并新建 const en_tagline = $('.review.body-text.-prose.-hero.prettify h4.tagline'); if (en_tagline.length) { $('.ov-en-seable').prepend(en_tagline); $('.ov-en-sed').prepend(en_tagline); } function overviewPanelInteraction() { // 处理标签页点击 $('.view-tab').click(function () { // 获取要显示的内容的ID const tabId = $(this).data('tab'); // 隐藏所有内容块 $('.tab-content').hide(); // 显示所选的内容块 $('#' + tabId).show(); // 更新活动选项卡的样式 $('.view-tab').removeClass('selected'); $(this).addClass('selected'); }); // 显示更多英文简介 $('.ov-en-condense-more').click(function () { $('.ov-en-sed').hide(); $('.ov-en-seable').show(); }); // 隐藏更多英文简介 $('.ov-en-condense-less').click(function () { $('.ov-en-seable').hide(); $('.ov-en-sed').show(); }); // 显示更多中文简介 $('.ov-zh-condense-more').click(function () { $('.ov-zh-sed').hide(); $('.ov-zh-seable').show(); }); // 隐藏更多中文简介 $('.ov-zh-condense-less').click(function () { $('.ov-zh-seable').hide(); $('.ov-zh-sed').show(); }); }; overviewPanelInteraction(); } // 折叠aka title function akaTtitleFold() { const aka_title = $('#tab-details .text-indentedlist'); const alternative_title = aka_title.find('p').text().replace(/\s{2,}/g, ''); console.log(`aka标题:${alternative_title}`) const alternative_title_30 = alternative_title.substring(0, 60); const alternativeTitleFold = `${alternative_title_30}…