-
Notifications
You must be signed in to change notification settings - Fork 0
/
Letterboxd_30nama_Link.js
48 lines (41 loc) · 1.83 KB
/
Letterboxd_30nama_Link.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// ==UserScript==
// @name Letterboxd 30nama Link
// @namespace https://github.com/ar3h1d/letterboxd_30nama_link
// @version 0.1.1
// @description Adds a button to Letterboxd movie pages that links to the 30nama page of the movie.
// @author ar3h1d
// @match https://letterboxd.com/film/*
// @grant none
// @icon https://raw.githubusercontent.com/ar3h1d/letterboxd_30nama_link/main/ltb30n.png
// @license GPL3
// ==/UserScript==
(function() {
'use strict';
// Extract movie title from the page
const movieTitle = document.querySelector('.headline-1').textContent.trim().toLowerCase();
// Check if the URL already contains the year
const yearFromUrl = window.location.href.match(/-(\d{4})$/);
let movieYear = yearFromUrl ? yearFromUrl[1] : null;
// Extract movie year from the page if not found in the URL
if (!movieYear) {
const movieYearElement = document.querySelector('a[href^="/films/year/"]');
movieYear = movieYearElement ? movieYearElement.textContent.trim() : null;
}
if (movieTitle && movieYear) {
// Create the 30nama link
const sinamaLink = `https://30nama.com/search?q=${movieTitle}+${movieYear}`;
// Create the button element
const sinamaButton = document.createElement('a');
sinamaButton.className = 'micro-button track-event';
sinamaButton.href = sinamaLink;
sinamaButton.textContent = '30nama';
sinamaButton.target = '_blank';
sinamaButton.style.marginLeft = '3px';
// Find the TMDb button
const tmdbButton = document.querySelector('a[data-track-action="TMDb"]');
if (tmdbButton) {
// Insert the 30nama button after the TMDb button
tmdbButton.parentNode.insertBefore(sinamaButton, tmdbButton.nextSibling);
}
}
})();