Sleazy Fork is available in English.

Redgifs source

Redirects redgifs link to its source video

  1. // ==UserScript==
  2. // @name Redgifs source
  3. // @description Redirects redgifs link to its source video
  4. // @license MIT
  5. // @namespace http://tampermonkey.net/
  6. // @version 0.1
  7. // @description Redgifs source
  8. // @author John
  9. // @match https://*.redgifs.com/*
  10. // @match https://gfycat.com/*
  11. // @include /https?://.*gifv.*
  12. // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
  13. // @grant none
  14. // @run-at document-start
  15. // ==/UserScript==
  16.  
  17. var interval = undefined;
  18.  
  19. function sleep(ms) {
  20. return new Promise(resolve => setTimeout(resolve, ms));
  21. }
  22.  
  23. function openInNewTab(url) {
  24. window.open(url, '_blank').focus();
  25. }
  26. function navigate(currentDoc, path) {
  27. if (interval != undefined) {
  28. clearInterval(interval);
  29. }
  30. if (navigated) {
  31. console.log("Already navigated");
  32. return;
  33. }
  34. navigated = true;
  35. console.log("orig path:", path);
  36. var player = getPlayer();
  37. if (window.location.href.indexOf("redgifs") > -1) {
  38. //path = path.replace("-mobile", "");
  39. }
  40. if (player && player.src.indexOf("expires") > -1) {
  41. // path = path.replace("thumbs4.redgifs", "thumbs2.redgifs");
  42. // path = path.replace("thumbs4.redgifs", "thumbs3.redgifs");
  43. }
  44. console.log("Navigating to:", path);
  45. if (path == "") {
  46. console.log("Cannot navigate!")
  47. } else {
  48. // currentDoc.location = path;
  49. window.location = path;
  50. }
  51. //openInNewTab(path);
  52. }
  53.  
  54. function getPlayer() {
  55. try {
  56. var qualityButton = document.getElementsByClassName("gif-quality")[0];
  57. // console.log("quality button:", qualityButton);
  58. if (qualityButton.classList.contains("sd")) {
  59. qualityButton.click();
  60. window.location.reload();
  61. return;
  62. }
  63. var playerVideo;
  64. var playerVideoClass;
  65. if (window.location.href.indexOf("redgifs") > -1) {
  66. console.log("redgifs!", document);
  67. // playerVideoClass = "player-video";
  68. playerVideoClass = "videoWrapper";
  69. // console.log("redgifs:", document.getElementsByClassName(playerVideoClass)[0].getElementsByTagName("video"));
  70. playerVideo = document.getElementsByClassName(playerVideoClass)[0].getElementsByTagName("video")[0];
  71. } else if (window.location.href.indexOf("gfycat") > -1) {
  72. playerVideoClass = "video media";
  73. playerVideo = document.getElementsByClassName(playerVideoClass)[0].getElementsByTagName("source")[0];
  74. } else if (window.location.href.indexOf("gifv") > -1) {
  75. playerVideo = document.getElementsByTagName("video")[0].getElementsByTagName("source")[0];
  76. }
  77. console.log("Player video:", playerVideo);
  78. return playerVideo;
  79. } catch (error) {
  80. // console.log("Not ready yet?", error);
  81. return undefined;
  82. }
  83. }
  84.  
  85. var navigated = false;
  86. document.onkeyup = function (e) {
  87. var code = (e.keyCode ? e.keyCode : e.which);
  88. if(code == 13) { //Enter keycode
  89. console.log("Key press enter");
  90. var player = getPlayer();
  91. if (player != undefined) {
  92. tryNavigate();
  93. }
  94. }
  95. };
  96.  
  97. function getMeta(metaName) {
  98. const metas = document.getElementsByTagName('meta');
  99. console.log("metas:", metas)
  100.  
  101. for (let i = 0; i < metas.length; i++) {
  102. console.log(metas[i].getAttribute('property'))
  103. if (metas[i].getAttribute('property') === metaName) {
  104. return metas[i].getAttribute('content');
  105. }
  106. }
  107. return '';
  108. }
  109.  
  110. function tryNavigate() {
  111. var player = getPlayer();
  112. if (player != undefined) {
  113. var srcPath = player.src || player.currentSrc;
  114. // if (window.location.href.indexOf("redgifs") > -1) {
  115. // srcPath = getMeta("og:video");
  116. // }
  117. navigate(document, srcPath);
  118. return true;
  119. }
  120. return false;
  121. }
  122.  
  123. function start() {
  124. if (window.location.href.indexOf("redgifs") > -1 &&
  125. window.location.href.indexOf("watch") <= -1) {
  126. interval = setInterval(function(){
  127. var player = getPlayer();
  128. if (player != undefined) {
  129. console.log("player:", player);
  130. // var newHeight = document.body.clientHeight * 0.75;
  131. var newHeight = 700;
  132. console.log("New height:", newHeight);
  133. if (player.parentElement.parentElement.parentElement.clientHeight > newHeight) {
  134. player.parentElement.parentElement.parentElement.style = `height: ${newHeight}px`
  135. }
  136. clearInterval(interval);
  137. }
  138. }, 1000);
  139. return;
  140. }
  141. if (!tryNavigate()) {
  142. interval = setInterval(function(){
  143. if (!tryNavigate()) {
  144. console.log("Waiting for players");
  145. }
  146. }, 1000);
  147. }
  148. }
  149.  
  150. window.addEventListener('load', function() {
  151. console.log("Window loaded: redgifs");
  152. setTimeout(function() {
  153. start();
  154. }, 1500);
  155. }, false);