Greasy Fork

Greasy Fork is available in English.

Criticker - Add Letterboxd Search Button

Adds a button to search the movie on Letterboxd

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Criticker - Add Letterboxd Search Button
// @namespace    https://www.criticker.com/
// @version      2.0
// @description  Adds a button to search the movie on Letterboxd
// @author       n00bCod3r
// @match        https://www.criticker.com/films*
// @grant        none
// ==/UserScript==

(function() {

  'use strict';
  function formatTitle(title) {
    title.trim();
    title = title.replaceAll('#','%23')
    title = title.replaceAll('+','%2B')
    title = title.replaceAll('&','%26')
    title = title.replaceAll('\'','%27')
    title = title.replaceAll('?', '%3F')
    title = title.replaceAll(' ', '+')
    return title;
  }

  //lbx logo
  const logoURL = 'https://a.ltrbxd.com/logos/letterboxd-decal-dots-pos-rgb-500px.png';
  const titlesList = document.querySelectorAll('div.fl_titlelist_title');

  titlesList.forEach(el => {
    const div = el.querySelector('.fl_name'); //cotnains <a> with movie info
    const title = formatTitle(div.querySelector('a').title);
    //console.log(title);

    //search link for the movie
    const lbxURL = `https://letterboxd.com/search/films/${title}/`;

    //<a> containing the lbx logo image
    const imgAnchor = document.createElement('a');
    imgAnchor.href = lbxURL;
    imgAnchor.target = "blank";
    imgAnchor.rel = "noopener noreferrer";

    //lbx logo image
    const img = document.createElement('img');
    img.src = logoURL;
    img.width = '20';
    imgAnchor.appendChild(img);

    //add image before div
    div.prepend(imgAnchor);
  })

})();