snippets.zerodogg.org

Letterboxd search bookmarklet

This bookmark attempts to find a movie you have open in the current tab (for instance in a webstore) and search letterboxd for it.

Search letterboxd

((document) => {
    const queries = [
        // Platekompaniet
        '.header-information > h1'
    ];
    const cleanup = (str) => {
        return str.replace(/\([^\)]+\)/g,'').replace(/\s+/,' ').replace(/\s+$/,'');
    };
    let search = null;
    for (const query of queries)
    {
        const attempt = document.querySelectorAll(query);
        if(attempt && attempt[0] && attempt[0].innerText)
        {
            search = attempt[0].innerText;
            break;
        }
    }
    if(search === null)
    {
        search=document.querySelector('title').innerText.replace(/\s+-\s+.+/g,'');
    }
    window.open('https://letterboxd.com/search/films/'+encodeURIComponent(cleanup(search)));
})(document);