No Embed Youtube

replace embed iframe, object with anchor link.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name No Embed Youtube
// @version 3.0.0
// @description replace embed iframe, object with anchor link.
// @homepageURL https://github.com/eight04/no-embed-youtube
// @supportURL https://github.com/eight04/no-embed-youtube/issues
// @license MIT
// @author eight04 <[email protected]>
// @namespace eight04.blogspot.com
// @include http*
// @exclude http://www.youtube.com/*
// @exclude https://www.youtube.com/*
// @exclude https://vimeo.com/*
// @run-at document-start
// @grant none
// ==/UserScript==

"use strict";

var xpath = `(
	//iframe[
		contains(@src, 'youtube.com/embed/') or
		contains(@src, 'youtube.com/v/') or
		contains(@src, 'youtube-nocookie.com/embed/') or
		contains(@src, 'youtube-nocookie.com/v/') or
		contains(@data-src, 'youtube.com/embed/') or
		contains(@src, 'vimeo.com/video')
	] |
	//object[./param[contains(@value, 'youtube.com/v/')]] |
	//embed[
		contains(@src, 'youtube.com/v/') and
		not(ancestor::object)
	]
)[not(ancestor::*[@id='YTLT-player'])]`;

const patterns = [
	{
    test: /youtube(-nocookie)?\.com\/(embed|v)\/(.+?)(\?|&|$)/,
    repl: match => `https://www.youtube.com/watch?v=${match[3]}`
  },
  {
    test: /vimeo\.com\/video\/(\d+)/,
    repl: match => `https://vimeo.com/${match[1]}`
  }
];

var unEmbed = function(node){

	var result = document.evaluate(
		xpath, node, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

	var element = null;
	var i = 0, j;

	while ((element = result.snapshotItem(i++))) {

		// iframe or embed
		var url = element.src || element.dataset.src;

		// object
		if(!url){
			for(j = 0; j < element.childNodes.length; j++){
				var pa = element.childNodes[j];
				if(pa.nodeName == "PARAM" && pa.getAttribute("name") == "movie"){
					url = pa.getAttribute("value");
					break;
				}
			}
		}

		if(!url){
			continue;
		}

    for (const pattern of patterns) {
      const match = url.match(pattern.test);
      if (!match) continue;
      const newUrl = pattern.repl(match);
      var a = document.createElement("a");
      a.textContent = newUrl;
      a.href = newUrl;
      a.target = "_blank";
      a.className = "unembed";
      element.parentNode.replaceChild(a, element);
      break;
    }
	}
};

new MutationObserver(function(){
	if (document.body) {
		unEmbed(document.body);
	}
}).observe(document, {
	childList: true,
	subtree: true
});