Greasy Fork

Greasy Fork is available in English.

Letterboxd Watched to Fan Ratio

Display the ratio of watchers to fans.

当前为 2022-05-24 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Letterboxd Watched to Fan Ratio
// @namespace    stanuwu
// @version      0.1
// @description  Display the ratio of watchers to fans.
// @author       stanuwu
// @match        https://letterboxd.com/film/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=simply-how.com
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
  'use strict';

  const findData = () => {
    // get possible elements that could contain the amount of fans or watched
    const searchLink = document.querySelectorAll(
      'a.all-link.more-link, a.has-icon.icon-watched.icon-16.tooltip',
    );

    let fanElement;
    let fans = '';
    let watched = '';

    //go through the elements and find the fans and watched
    for (let l of searchLink) {
      if (l.innerHTML ? l.innerHTML.includes(' fans') : false) {
        fans = l.innerHTML;
        fanElement = l;
      } else if (l.dataset.originalTitle.includes('Watched by ')) {
        watched = l.dataset.originalTitle;
      }
    }

    //stupid formating to get the numbers
    const fanNumber = numberFormat(fans.split(' ')[0]);
    const watchedNumber = Number(watched.split(' ')[2].replace(' members', '').replaceAll(',', ''));

    //display as percentage next to the fans
    const percentRatio = ((fanNumber / watchedNumber) * 100).toFixed(2);
    fanElement.innerHTML += ` (${percentRatio}%)`;
  };

  //code to format numbers using k or m
  const numberFormat = (num) => {
    switch (num[num.length - 1]) {
      case 'k':
        return parseFloat(num) * 1e3;
      case 'm':
        return parseFloat(num) * 1e6;
      default:
        return Number(num);
    }
  };

  setTimeout(findData, 500);
})();