Greasy Fork

Greasy Fork is available in English.

StumbleOut

Breaks the original link out of StumbleUpon frames. Now with mutation observers!

当前为 2016-09-15 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        StumbleOut
// @version     2
// @author      raina
// @namespace   raina
// @description Breaks the original link out of StumbleUpon frames. Now with mutation observers!
// @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 link, iframe;

	// Method 1: Actual link is appended to URL, get it and go.
	var method1 = function() {
		window.location.href = link;
	};


	// Method 2: Dig link from iframe after page has loaded. Probably deprecated on SU's part but flows naturally to Method 3.
	var method2 = function() {
		digger();
		if (iframe !== undefined && iframe) {
			window.location.href = iframe.src;
		} else if ("complete" === document.readyState) {
			method3();
		}
	};

	
	// Method 3: Dig link from iframe after web app reports having loaded.
	var method3 = function() {
		var target = document.body;
		var observer = new MutationObserver(function (mutations) {
			mutations.forEach(function (mutation) {
				if ("class" === mutation.attributeName) {
					digger();
					if (iframe !== undefined && iframe) {
						window.location.href = iframe.src;
						observer.disconnect();
					}
				}
			});
		});
		var config = {attributes: true};
		observer.observe(target, config);
	};


	var digger = function() {
		if (iframe === undefined || !iframe) {
			iframe = document.querySelector('.stumble-frame');
		}
	};


	if (window.self === window.top) {
		link = window.location.href.replace(/www\.stumbleupon\.com\/su\/[^\/]*(\/[^\/]*:[^\/]*)?\//, '').replace(/\/#?$/, '');
		if (window.location.href !== link && /^https?:\/\/[\d\w]/.test(link)) {
			method1();
		} else {
			document.addEventListener("readystatechange", method2, false);
		}
	}
}());