Discussions » Creation Requests

Youtube Embeded privacy/anonymization and removal of "fullscreen" restriction

§
Posted: 2019-01-11

Youtube Embeded privacy/anonymization and removal of "fullscreen" restriction

Hi script masters!

I'm not a programmer so I'm hoping someone here can help me (and others!) by creating this privacy-oriented YT script.

I'd like a script that acts on embedded YouTube videos on other blogs and websites. When people embed YT video, they usually embed it with default options that you get when you click on the "Share:" icon on YT. Problem is that by default YT uses a domain that tracks you and then can tell when you watch some video on another site. They associate the views of embedded videos with your account. However, YouTube also has a non-tracking option and all that it requires is that you use a different domain: youtube-nocookie.com (which YT also controls but they don't track you with it.

So the script I'm looking for should go though a page and replace YT embeds that use a youtube.com/youtu.be domain with youtube-nocookie.com domain.

Example: iframe src="//www.youtube.com/embed/yvvES47OdmY?wmode=transparent" frameborder="0" with: iframe src="//www.youtube-nocookie.com/embed/yvvES47OdmY?wmode=transparent" frameborder="0"

Also, some websites/videos prevent you from playing a video in full screen but this can be remedied with: *allowFullScreen="allowFullScreen" * attribute option.

So the final embed would look something like: *iframe src="//www.youtube-nocookie.com/embed/yvvES47OdmY?wmode=transparent" frameborder="0" allowFullScreen="allowFullScreen" *

Thank you so much!!!!

§
Posted: 2019-01-11
// ==UserScript==
// @name         Nocookie and Fullscreenable Youtube Embeded Frame
// @namespace    greasyfork.org
// @version      0.1
// @include      *
// @run-at       document-idle
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    [].forEach.call(document.querySelectorAll('iframe'),frame=>{
        const matchSrc = frame.src && frame.src.match(/\/\/(www\.)?(youtube\.com)|(youtu\.be)/);
        if (matchSrc){
            frame.setAttribute('allowfullscreen', 'true');
            frame.src = frame.src.replace(matchSrc[0],'//www.youtube-nocookie.com');
        }
        const matchDataSrc = frame.dataset.src && frame.dataset.src.match(/\/\/(www\.)?(youtube\.com)|(youtu\.be)/)
        if (matchDataSrc){
            frame.setAttribute('allowfullscreen', 'true');
            frame.dataset.src = frame.dataset.src.replace(matchDataSrc[0],'//www.youtube-nocookie.com');
        }
    });
})();

this may work somewhere but not ever site,frames that load after document load will not be process

§
Posted: 2019-01-11

WOW! Thank you so much indefined! It works great! You should put this script on here as a full-fledged script so others can find it. Finally I can watch videos around the web without YT/Google tracking me and constantly suggesting me videos that I'd never watch on YT itself. Thanks again!!!

Post reply

Sign in to post a reply.