StumbleOut

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

  1. // ==UserScript==
  2. // @name StumbleOut
  3. // @version 2.3
  4. // @author raina
  5. // @namespace raina
  6. // @description Breaks the original link out of StumbleUpon frames and rewrites YouTube embed URLs to their proper video pages.
  7. // @license http://www.gnu.org/licenses/gpl-3.0.txt
  8. // @include http://www.stumbleupon.com/su/*
  9. // @run-at document-start
  10. // @grant none
  11. // ==/UserScript==
  12. (function() {
  13. "use strict";
  14.  
  15.  
  16. var ready = function() {
  17. if ("complete" === document.readyState) {
  18. observe();
  19. }
  20. };
  21.  
  22.  
  23. var observe = function() {
  24. var observer = new MutationObserver(function(mutations) {
  25. mutations.forEach(function(mutation) {
  26. if ("class" === mutation.attributeName) {
  27. if ("undefined" === typeof iframe || !iframe) {
  28. iframe = document.querySelector('.stumble-frame');
  29. }
  30. if ("undefined" !== typeof iframe && iframe) {
  31. if (/youtube\.com\/embed/.test(iframe.src)) {
  32. var video = iframe.src.replace(/(embed\/)([\w\d-]+)(\?.*$)/, "watch?v=$2");
  33. var timestamp;
  34. if (timestamp = iframe.src.match(/t=\d+m\d+s/)) {
  35. video += "&" + timestamp[0];
  36. }
  37. window.location.href = video;
  38. } else {
  39. window.location.href = iframe.src;
  40. }
  41. observer.disconnect();
  42. }
  43. }
  44. });
  45. });
  46. var config = {attributes: true};
  47. observer.observe(document.body, config);
  48. }
  49.  
  50.  
  51. if (window.self === window.top) {
  52. var iframe;
  53. document.addEventListener("readystatechange", ready, false);
  54. }
  55. }());