StumbleOut

Breaks the original link out of StumbleUpon frames and rewrites YouTube embed URLs to their proper video pages.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name        StumbleOut
// @version     2.3
// @author      raina
// @namespace   raina
// @description Breaks the original link out of StumbleUpon frames and rewrites YouTube embed URLs to their proper video pages.
// @license     http://www.gnu.org/licenses/gpl-3.0.txt
// @include     http://www.stumbleupon.com/su/*
// @run-at      document-start
// @grant       none
// ==/UserScript==
(function() {
	"use strict";


	var ready = function() {
		if ("complete" === document.readyState) {
			observe();
		}
	};


	var observe = function() {
		var observer = new MutationObserver(function(mutations) {
			mutations.forEach(function(mutation) {
				if ("class" === mutation.attributeName) {
					if ("undefined" === typeof iframe || !iframe) {
						iframe = document.querySelector('.stumble-frame');
					}
					if ("undefined" !== typeof iframe && iframe) {
						if (/youtube\.com\/embed/.test(iframe.src)) {
							var video = iframe.src.replace(/(embed\/)([\w\d-]+)(\?.*$)/, "watch?v=$2");
							var timestamp;
							if (timestamp = iframe.src.match(/t=\d+m\d+s/)) {
								video += "&" + timestamp[0];
							}
							window.location.href = video;
						} else {
							window.location.href = iframe.src;
						}
						observer.disconnect();
					}
				}
			});
		});
		var config = {attributes: true};
		observer.observe(document.body, config);
	}


	if (window.self === window.top) {
		var iframe;
		document.addEventListener("readystatechange", ready, false);
	}
}());