YouTube Mobile Redirect (Safe)

Redirects to m.youtube.com only if user agent is mobile

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name        YouTube Mobile Redirect (Safe)
// @namespace   youtube-mobile-redirect
// @match       https://www.youtube.com/*
// @run-at      document-start
// @grant       none
// @version     2
// @description Redirects to m.youtube.com only if user agent is mobile
// ==/UserScript==

(function() {
    'use strict';

    const isMobileUA = /Android|iPhone|iPad|iPod|Mobile/i.test(navigator.userAgent);

    if (isMobileUA && window.location.hostname === 'www.youtube.com') {
        window.location.replace(
            'https://m.youtube.com' + window.location.pathname + window.location.search
        );
    }
})();