Good o'l Reddit

Makes sure you're using Good o'l Reddit. (C) TheNH813 2018. Edited by SkauOfArcadia.

  1. // ==UserScript==
  2. // @name Good o'l Reddit
  3. // @description Makes sure you're using Good o'l Reddit. (C) TheNH813 2018. Edited by SkauOfArcadia.
  4. // @author TheNH813 & SkauOfArcadia
  5. // @version 1.5.1
  6. // @homepage https://skau.neocities.org/
  7. // @contactURL https://t.me/SkauOfArcadia
  8. // @match *://*.reddit.com/*
  9. // @match *://preview.redd.it/*
  10. // @run-at document-start
  11. // @grant none
  12. // @namespace https://greasyfork.org/users/751327
  13. // ==/UserScript==
  14. /**
  15. * This program is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation, either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. if (location.hostname === "preview.redd.it") {
  29. location.replace(location.protocol + "//i.redd.it" + location.pathname);
  30. } else if (location.hostname !== "old.reddit.com" && location.pathname.indexOf('/poll/') !== 0 && location.pathname.indexOf('/gallery/') !== 0) {
  31. var oldReddit = location.protocol + "//old.reddit.com" + location.pathname + location.search + location.hash;
  32. location.replace(oldReddit);
  33. } else {
  34. window.addEventListener("DOMContentLoaded", function() {
  35. var observer = new MutationObserver(mutate);
  36. observer.observe(document,{childList:true,attributes:true,subtree:true});
  37.  
  38. function mutate(){
  39. if (location.pathname.indexOf('/comments/') !== -1){
  40. improveEmbeds();
  41. }
  42. if (location.pathname.indexOf('/r/') === 0 && document.getElementsByClassName('archived-infobar').length === 0 && (!document.getElementById('res-style-checkbox') || document.getElementById('res-style-checkbox').checked)){
  43. unhideVotes();
  44. }
  45. improveLinks();
  46. }
  47.  
  48. function unhideVotes(){
  49. let vote = document.getElementsByClassName('arrow');
  50. for (var x = 0; x < vote.length; x++){
  51. let pp = vote[x].parentElement.parentElement;
  52. if(vote[x].getAttribute('style') !== 'visibility: visible !important; display: block !important; pointer-events: auto !important;' && !pp.classList.contains('collapsed')){
  53. vote[x].setAttribute('style', 'visibility: visible !important; display: block !important; pointer-events: auto !important;');
  54. } else if (pp.classList.contains('collapsed')){
  55. vote[x].removeAttribute('style');
  56. }
  57. }
  58. }
  59. function improveLinks(){
  60. let links = document.getElementsByTagName('a');
  61. for (var x = 0; x < links.length; x++) {
  62. if (links[x].hasAttribute('data-outbound-url')){
  63. links[x].removeAttribute('data-outbound-url');
  64. links[x].removeAttribute('data-href-url');
  65. links[x].removeAttribute('data-outbound-expiration');
  66. links[x].setAttribute('rel','noopener noreferrer');
  67. console.log('Removed Outbound URL for: ' + links[x].href);
  68. }
  69. if (links[x].href.indexOf('//preview.redd.it') !== -1) {
  70. links[x].href = links[x].href.split('?')[0].replace('preview.redd.it','i.redd.it');
  71. }
  72. }
  73. }
  74. function improveEmbeds(){
  75. let embeds = document.getElementsByClassName('media-embed');
  76. for (var x = 0; x < embeds.length; x++) {
  77. let pp = embeds[x].parentElement.parentElement;
  78. let title = pp.getElementsByClassName('title')[pp.getElementsByClassName('title').length -1]
  79. if (embeds[x].src.indexOf('//www.redditmedia.com/') !== -1
  80. && !!title && (title.href.indexOf('youtube') !== -1 || title.href.indexOf('youtu.be') !== -1)
  81. && title.href.indexOf('/clip/') === -1) {
  82. let yt = title.href;
  83. if(yt.indexOf('/shorts/') !== -1){
  84. yt = yt.replace('?', '&').replace('/shorts/','/watch?v=');
  85. }
  86. let params = new URLSearchParams();
  87. if(yt.indexOf('?') !== -1){
  88. params = new URLSearchParams(yt.split('?').pop());
  89. yt = yt.split('?')[0];
  90. } else if (yt.indexOf('&') !== -1) {
  91. params = new URLSearchParams(yt.split(yt.split('&')[0]).pop());
  92. yt = yt.split('&')[0];
  93. }
  94. if(yt.indexOf('youtu.be') !== -1){
  95. yt = yt.replace('www.', '').replace('youtu.be/', 'www.youtube-nocookie.com/embed/');
  96. } else if(!!params.get('v')) {
  97. yt = 'https://www.youtube-nocookie.com/embed/' + params.get('v');
  98. params.delete('v');
  99. }
  100. params.set('autoplay', 0);
  101. yt += '?' + params;
  102. embeds[x].src = yt;
  103. ResizeEmbed(embeds[x], pp.clientWidth);
  104. } else if (embeds[x].src.indexOf('//www.redditmedia.com/') !== -1
  105. && !!title && title.href.indexOf('twitch.tv') !== -1) {
  106. let tw = title.href;
  107. let value = tw.split('/v/').pop().split('/clip/').pop().replace('videos/','').split('twitch.tv/').pop();
  108. let params = new URLSearchParams();
  109. if (value.indexOf('?') !== -1){
  110. params = new URLSearchParams(value.split('?').pop());
  111. params.delete('channel');
  112. params.delete('clip');
  113. params.delete('video');
  114. value = value.split('?')[0];
  115. }
  116. if (value.indexOf('/') !== -1){
  117. value = value.split('/')[0];
  118. }
  119. params.set('autoplay', 'false');
  120. params.set('parent', location.hostname);
  121. if (tw.indexOf('clips.twitch.tv/') !== -1 || tw.indexOf('/clip/') !== -1){
  122. params.set('clip', value);
  123. tw = 'https://clips.twitch.tv/embed?' + params;
  124. } else if (tw.indexOf('videos/') !== -1 || tw.indexOf('/v/') !== -1){
  125. params.set('video', 'v' + value);
  126. tw = 'https://player.twitch.tv/?' + params;
  127. } else {
  128. params.set('channel', value);
  129. tw = 'https://player.twitch.tv/?' + params;
  130. }
  131. if (location.hostname !== window.location.hostname) {
  132. tw += '&parent=' + window.location.hostname;
  133. }
  134. embeds[x].src = tw;
  135. ResizeEmbed(embeds[x], pp.clientWidth);
  136. } else if (embeds[x].src.indexOf('//www.redditmedia.com/') !== -1
  137. && !!title && title.href.indexOf('streamable.com/') !== -1) {
  138. let st = title.href.replace('streamable.com/', 'streamable.com/o/');
  139. let params = new URLSearchParams();
  140. if(st.indexOf('?') !== -1){
  141. params = new URLSearchParams(st.split('?').pop());
  142. st = st.split('?')[0];
  143. }
  144. params.set('autoplay', 0);
  145. embeds[x].src = st + '?' + params;
  146. ResizeEmbed(embeds[x], pp.clientWidth);
  147. } else if (embeds[x].src.indexOf('//www.redditmedia.com/') !== -1
  148. && !!title && (title.href.indexOf('//vimeo.com/') !== -1 || title.href.indexOf('//www.vimeo.com/') !== -1)) {
  149. embeds[x].src = title.href.replace('//www.', '//').replace('vimeo.com/', 'player.vimeo.com/video/');
  150. ResizeEmbed(embeds[x], pp.clientWidth);
  151. }
  152. }
  153. }
  154. function ResizeEmbed(element, wwidth){
  155. const elRatio = element.clientWidth / element.clientHeight;
  156. element.width = Math.round(((wwidth * 0.9) * 0.5625) * elRatio);
  157. element.height = Math.round((wwidth * 0.9) * 0.5625);
  158. }
  159. if (location.pathname.indexOf('/comments/') !== -1){
  160. improveEmbeds();
  161. }
  162. if (location.pathname.indexOf('/r/') === 0 && document.getElementsByClassName('archived-infobar').length === 0 && (!document.getElementById('res-style-checkbox') || document.getElementById('res-style-checkbox').checked)){
  163. unhideVotes();
  164. }
  165. improveLinks();
  166. });
  167. }