Netflix Tile Fix

Open Netflix's non-link tiles in new tabs with "title" URLs instead of "watch" on middle click, ignoring regular links.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

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

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name		Netflix Tile Fix
// @namespace	http://tampermonkey.net/
// @version     0.92
// @description Open Netflix's non-link tiles in new tabs with "title" URLs instead of "watch" on middle click, ignoring regular links.
// @author      Murat Malatya
// @match		https://www.netflix.com/*
// @grant		none
// @license     MIT
// ==/UserScript==

(function() {
    'use strict';

    function extractNetflixId(element) {
        const allElements = [element, ...element.querySelectorAll('*')];
        for (const el of allElements) {
            const ctx = el.getAttribute('data-ui-tracking-context');
            if (ctx) {
                try {
                    const parsed = JSON.parse(decodeURIComponent(ctx));
                    if (parsed.video_id) {
                        return parsed.video_id;
                    }
                }
                catch (e) {
                }
            }
        }
        return null;
    }

    function isNetflixRecommendation(element) {
        if (element.closest('.ptrack-content')) {
            return true;
        }
        return false;
    }

    function handleMouseDown(event) {
        if (event.button !== 1) {
            return;
        }

        const target = event.target;
        let element = target;
        let maxDepth = 10;

        while (element && maxDepth > 0) {
            if (element.tagName === 'A' && element.href) {
                return;
            }

            if (isNetflixRecommendation(element)) {
                const netflixId = extractNetflixId(element);
                if (netflixId) {
                    event.preventDefault();
                    event.stopPropagation();
                    event.stopImmediatePropagation();
                    const titleUrl = `https://www.netflix.com/title/${netflixId}`;
                    window.open(titleUrl, '_blank');
                    return;
                }
            }

            element = element.parentElement;
            maxDepth--;
        }
    }

    document.addEventListener('mousedown', handleMouseDown, {
        capture: true,
        passive: false
    });
})();