Letterboxd Rating Base 10

Changes the Letterboxd rating to Base 10

  1. // ==UserScript==
  2. // @name Letterboxd Rating Base 10
  3. // @namespace https://github.com/Tetrax-10
  4. // @description Changes the Letterboxd rating to Base 10
  5. // @icon https://raw.githubusercontent.com/worldwidewaves/letterboxd-scripts/master/img/letterboxd_icon.png
  6. // @license MIT
  7. // @version 1.0
  8. // @match *://*.letterboxd.com/film/*
  9. // ==/UserScript==
  10.  
  11. ;(async () => {
  12. async function waitForElement(selector, timeout = null, nthElement = 1) {
  13. // wait till document body loads
  14. while (!document.body) {
  15. await new Promise((resolve) => setTimeout(resolve, 10))
  16. }
  17.  
  18. nthElement -= 1
  19.  
  20. return new Promise((resolve) => {
  21. if (document.querySelectorAll(selector)?.[nthElement]) {
  22. return resolve(document.querySelectorAll(selector)?.[nthElement])
  23. }
  24.  
  25. const observer = new MutationObserver(async () => {
  26. if (document.querySelectorAll(selector)?.[nthElement]) {
  27. resolve(document.querySelectorAll(selector)?.[nthElement])
  28. observer.disconnect()
  29. } else {
  30. if (timeout) {
  31. async function timeOver() {
  32. return new Promise((resolve) => {
  33. setTimeout(() => {
  34. observer.disconnect()
  35. resolve(false)
  36. }, timeout)
  37. })
  38. }
  39. resolve(await timeOver())
  40. }
  41. }
  42. })
  43.  
  44. observer.observe(document.body, {
  45. childList: true,
  46. subtree: true,
  47. })
  48. })
  49. }
  50.  
  51. const currentURL = location.protocol + "//" + location.hostname + location.pathname
  52.  
  53. if (/^(https?:\/\/letterboxd\.com\/film\/[^\/]+(?:\/\?.*)?\/?(crew|details|genres)?)$/.test(currentURL)) {
  54. const ratingElement = await waitForElement(".tooltip.display-rating", 10000)
  55. if (ratingElement.innerText) {
  56. let rating = (parseFloat(ratingElement.innerText) * 2).toFixed(1)
  57. ratingElement.innerText = rating
  58. }
  59. }
  60. })()