Criticker: Add Letterboxd Search Button

Adds a button to search the movie on Letterboxd

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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);
  })

})();