Side-Reddit

Simple side-bar toggle for Reddit

当前为 2014-05-24 提交的版本,查看 最新版本

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