Side-Reddit

Simple side-bar toggle for Reddit

  1. // ==UserScript==
  2. // @name Side-Reddit
  3. // @version 1.30
  4. // @description Simple side-bar toggle for Reddit
  5. // @include http://*.reddit.com/*
  6. // @include http://reddit.com/*
  7. // @include https://*.reddit.com/*
  8. // @include https://reddit.com/*
  9. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  10. // @require http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.min.js
  11. // @grant GM_addStyle
  12. // @icon https://monkeyguts.com/icon/141.png
  13. // @namespace https://greasyfork.org/users/59
  14. // ==/UserScript==
  15.  
  16. $(document).ready(function () {
  17. var showCheck1 = 0;
  18. var pTop = $('.content').css("padding-top");
  19. var cmRight = $('.content').css("margin-right");
  20. var careaRight = $('.commentarea').css("margin-right");
  21. var cMargin = $('.content').css("margin");
  22. var mTop = $('.content').css("margin-top");
  23. var smRight = $('#siteTable').css("margin-right");
  24. var spRight = $('#siteTable').css("padding-right");
  25. var tmRight = $('.thing').css("margin-right");
  26. var zNode1 = document.createElement ('div');
  27. var foo = document.getElementById(".expando-button");
  28. var percent;
  29. var lastScrollTop = 0;
  30. $(window).scroll(function(event){
  31. var st = $(this).scrollTop();
  32. if (st > lastScrollTop){
  33. $('#myContainer1').css("top", "0");
  34. } else if (st === 0) {
  35. $('#myContainer1').css("top", "");
  36. lastScrollTop = st;
  37. }
  38. });
  39.  
  40. zNode1.innerHTML = '<button id="myButton1" type="button">' + '‡</button>';
  41.  
  42. zNode1.setAttribute ('id', 'myContainer1');
  43. document.getElementById('header-bottom-left').appendChild(zNode1);
  44. $(function () {
  45. $(".md").css("max-width", "100%");
  46. $(".commentarea").css("margin-right", "0px");
  47. });
  48. $("div.expando-button").click(function(){
  49. $(".md").css("max-width", "100%");
  50. $(".commentarea").css("margin-right", "0px");
  51. });
  52.  
  53.  
  54. //--- Activate the newly added button.
  55. document.getElementById ("myButton1").addEventListener (
  56. "click", ButtonClickAction, false
  57. );
  58. function ButtonClickAction (zEvent) {
  59. if(showCheck1 == 1) {
  60. $('.side').show(100, "swing");
  61. $("#siteTable").each(function () {
  62. this.style.setProperty("margin-right", "", "important");
  63. this.style.setProperty("margin-right", "", "important");
  64. });
  65. $("#siteTable").each(function () {
  66. this.style.setProperty("margin-right", smRight);
  67. this.style.setProperty("margin-right", spRight);
  68. });
  69. $(".thing").each(function () {
  70. this.style.setProperty("margin-right", "", "important");
  71. this.style.setProperty("width", "");
  72. });
  73. $(".thing").each(function () {
  74. this.style.setProperty("margin-right", "");
  75. });
  76. $(".content").each(function () {
  77. //this.style.setProperty("padding-top", "", "important");
  78. this.style.setProperty("margin-right", "", "important");
  79. this.style.setProperty("margin-top", "");
  80. this.style.setProperty("border-right", "");
  81. });
  82. $("#myButton1").fadeTo("fast", 1).delay(300).css({"color":"red"});
  83. showCheck1 = 0;
  84. $.cookie("check", 1, { expires: 7, path: "/" });
  85. $(".md").css("max-width", "");
  86. $(".commentarea").css("margin-right", careaRight);
  87. if($(".expando").css("display") == "block") {
  88. $(".md").css("max-width", "");
  89. $(".commentarea").css("margin-right", careaRight);
  90. }
  91. else{
  92. }
  93. }
  94. else if(showCheck1 === 0) {
  95. $('.side').hide(100, "swing");
  96. $("#siteTable").each(function () {
  97. this.style.setProperty("margin-right", "auto", "important");
  98. this.style.setProperty("padding-right", "5px", "important");
  99. });
  100. // alert($(".link").css("width"));
  101. percent = $(".link").width() / $(window).width() * 100;
  102. // alert(percent);
  103. if(percent > 97 || percent === 0){
  104. }
  105. else {
  106. $(".thing").each(function () {
  107. this.style.setProperty("width", "99%");
  108. });
  109. }
  110. if($(".content").css("border-right") === 0){
  111. }
  112. else {
  113. $(".content").each(function () {
  114. this.style.setProperty("border-right", "0");
  115. });
  116. }
  117. $(".thing").each(function () {
  118. this.style.setProperty("margin-right", "auto", "important");
  119. });
  120. $(".content").each(function () {
  121. //this.style.setProperty("padding-top", "1px", "important");
  122. this.style.setProperty("margin-right", "5px", "important");
  123. this.style.setProperty("margin-top", "7px", "important");
  124. });
  125. $("#myButton1").fadeTo("fast", 0.5).delay(300).css({"color":"blue"});
  126. showCheck1 = 1;
  127. $.cookie("check", 2, { expires: 7, path: "/" });
  128. $(".md").css("max-width", "100%");
  129. $(".commentarea").css("margin-right", "0px");
  130. if($(".expando").css("display") == "block") {
  131. $(".md").css("max-width", "100%");
  132. $(".commentarea").css("margin-right", "0px");
  133. }
  134. else{
  135. }
  136. }
  137. else {
  138. console.log("Error with Side-Reddit");
  139. }
  140. }
  141. if($.cookie("check") == 1) {
  142. $('.side').show(100, "swing");
  143. $("#siteTable").each(function () {
  144. this.style.setProperty("margin-right", "", "important");
  145. this.style.setProperty("margin-right", "", "important");
  146. });
  147. $("#siteTable").each(function () {
  148. this.style.setProperty("margin-right", smRight);
  149. this.style.setProperty("margin-right", spRight);
  150. });
  151. $(".thing").each(function () {
  152. this.style.setProperty("margin-right", "", "important");
  153. this.style.setProperty("width", "");
  154. });
  155. $(".thing").each(function () {
  156. this.style.setProperty("margin-right", "");
  157. });
  158. $(".content").each(function () {
  159. //this.style.setProperty("padding-top", "", "important");
  160. this.style.setProperty("margin-right", "", "important");
  161. this.style.setProperty("margin-top", "");
  162. this.style.setProperty("border-right", "");
  163. });
  164. $("#myButton1").fadeTo("fast", 1).delay(300).css({"color":"red"});
  165. showCheck1 = 0;
  166. $(".md").css("max-width", "");
  167. $(".commentarea").css("margin-right", careaRight);
  168. if($(".expando").css("display") == "block") {
  169. $(".md").css("max-width", "");
  170. $(".commentarea").css("margin-right", careaRight);
  171. }
  172. else{
  173. }
  174. }
  175. else if($.cookie("check") == 2) {
  176. $('.side').hide(100, "swing");
  177. $("#siteTable").each(function () {
  178. this.style.setProperty("margin-right", "auto", "important");
  179. this.style.setProperty("padding-right", "5px", "important");
  180. });
  181. percent = $(".link").width() / $(window).width() * 100;
  182. // alert(percent);
  183. if(percent > 97 || percent === 0){
  184. }
  185. else {
  186. $(".thing").each(function () {
  187. this.style.setProperty("width", "99%");
  188. });
  189. }
  190. if($(".content").css("border-right") === 0){
  191. }
  192. else {
  193. $(".content").each(function () {
  194. this.style.setProperty("border-right", "0");
  195. });
  196. }
  197. $(".thing").each(function () {
  198. this.style.setProperty("margin-right", "auto", "important");
  199. // this.style.setProperty("width", "100%");
  200. });
  201. $(".content").each(function () {
  202. //this.style.setProperty("padding-top", "1px", "important");
  203. this.style.setProperty("margin-right", "5px", "important");
  204. this.style.setProperty("margin-top", "7px", "important");
  205. });
  206. $("#myButton1").fadeTo("fast", 0.5).delay(300).css({"color":"blue"});
  207. showCheck1 = 1;
  208. $(".md").css("max-width", "100%");
  209. $(".commentarea").css("margin-right", "0px");
  210. if($(".expando").css("display") == "block") {
  211. $(".md").css("max-width", "100%");
  212. $(".commentarea").css("margin-right", "0px");
  213. }
  214. }
  215. else {
  216. console.log("Error with Side-Reddit");
  217. }
  218. //--- Style our newly added elements using CSS.
  219. GM_addStyle ( multilineStr ( function () {/*!
  220. #myContainer1 {
  221. position: fixed;
  222. left: 0;
  223. font-size: 1px;
  224. border: 0px inset black;
  225. margin: 0px;
  226. opacity: 10.0;
  227. z-index: 99999;
  228. padding: 0px 0px;
  229. }
  230. #myButton1 {
  231. cursor: pointer;
  232. background: solid;
  233. background-color: #cee3f8;
  234. border: none !important;
  235. opacity: 8;
  236. color: red;
  237. font-weight: bold;
  238. }
  239. #myContainer1 p {
  240. color: purple;
  241. background: white;
  242. }
  243. */} ) );
  244.  
  245. function multilineStr (dummyFunc) {
  246. var str = dummyFunc.toString ();
  247. str = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
  248. .replace (/\s*\*\/\s*\}\s*$/, '') // Strip */ }
  249. .replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
  250. ;
  251. return str;
  252. }
  253. //
  254. });