// ==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 // @downloadURL 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); } } }());