Side-Reddit

Handy Dandy Toggle for the Side Bar

当前为 2014-04-30 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Side-Reddit
  3. // @version 1.27
  4. // @description Handy Dandy Toggle for the Side Bar
  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 lastScrollTop = 0;
  26. $(window).scroll(function(event){
  27. var st = $(this).scrollTop();
  28. if (st > lastScrollTop){
  29. $('#myContainer1').css("top", "0");
  30. } else if (st == 0) {
  31. $('#myContainer1').css("top", "80px");
  32. lastScrollTop = st;
  33. }
  34. });
  35.  
  36. zNode1.innerHTML = '<button id="myButton1" type="button">'
  37. + '‡</button>';
  38.  
  39. zNode1.setAttribute ('id', 'myContainer1');
  40. document.getElementById('header-bottom-left').appendChild(zNode1);
  41. $(function () {
  42. $(".md").css("max-width", "100%");
  43. $(".commentarea").css("margin-right", "0px");
  44. });
  45. $("div.expando-button").click(function(){
  46. $(".md").css("max-width", "100%");
  47. $(".commentarea").css("margin-right", "0px");
  48. });
  49.  
  50.  
  51. //--- Activate the newly added button.
  52. document.getElementById ("myButton1").addEventListener (
  53. "click", ButtonClickAction, false
  54. );
  55. function ButtonClickAction (zEvent) {
  56. if(showCheck1 == 1) {
  57. $('.side').show();
  58. $("#siteTable").each(function () {
  59. this.style.setProperty("margin-right", "", "important");
  60. this.style.setProperty("margin-right", "", "important");
  61. });
  62. $("#siteTable").each(function () {
  63. this.style.setProperty("margin-right", smRight);
  64. this.style.setProperty("margin-right", spRight);
  65. });
  66. $(".thing").each(function () {
  67. this.style.setProperty("margin-right", "", "important");
  68. });
  69. $(".thing").each(function () {
  70. this.style.setProperty("margin-right", "");
  71. });
  72. $(".content").each(function () {
  73. this.style.setProperty("padding-top", "", "important");
  74. this.style.setProperty("margin-right", "", "important");
  75. this.style.setProperty("margin-top", "");
  76. });
  77. $("#myButton1").fadeTo("fast", 1).delay(300).css({"color":"red"});
  78. showCheck1 = 0;
  79. $.cookie("check", 1, { expires: 7, path: "/" });
  80. $(".md").css("max-width", "");
  81. $(".commentarea").css("margin-right", careaRight);
  82. if($(".expando").css("display") == "block") {
  83. $(".md").css("max-width", "");
  84. $(".commentarea").css("margin-right", careaRight);
  85. }
  86. else{
  87. }
  88. }
  89. else if(showCheck1 == 0) {
  90. $('.side').hide();
  91. $("#siteTable").each(function () {
  92. this.style.setProperty("margin-right", "auto", "important");
  93. this.style.setProperty("padding-right", "5px", "important");
  94. });
  95. $(".thing").each(function () {
  96. this.style.setProperty("margin-right", "auto", "important");
  97. });
  98. $(".content").each(function () {
  99. this.style.setProperty("padding-top", "1px", "important");
  100. this.style.setProperty("margin-right", "auto", "important");
  101. this.style.setProperty("margin-top", "auto", "important");
  102. });
  103. $("#myButton1").fadeTo("fast", 0.5).delay(300).css({"color":"blue"});
  104. showCheck1 = 1;
  105. $.cookie("check", 2, { expires: 7, path: "/" });
  106. $(".md").css("max-width", "100%");
  107. $(".commentarea").css("margin-right", "0px");
  108. if($(".expando").css("display") == "block") {
  109. $(".md").css("max-width", "100%");
  110. $(".commentarea").css("margin-right", "0px");
  111. }
  112. else{
  113. }
  114. }
  115. else {
  116. }
  117. }
  118. if($.cookie("check") == 1) {
  119. $('.side').show();
  120. $("#siteTable").each(function () {
  121. this.style.setProperty("margin-right", "", "important");
  122. this.style.setProperty("margin-right", "", "important");
  123. });
  124. $("#siteTable").each(function () {
  125. this.style.setProperty("margin-right", smRight);
  126. this.style.setProperty("margin-right", spRight);
  127. });
  128. $(".thing").each(function () {
  129. this.style.setProperty("margin-right", "", "important");
  130. });
  131. $(".thing").each(function () {
  132. this.style.setProperty("margin-right", "");
  133. });
  134. $(".content").each(function () {
  135. this.style.setProperty("padding-top", "", "important");
  136. this.style.setProperty("margin-right", "", "important");
  137. this.style.setProperty("margin-top", "");
  138. });
  139. $("#myButton1").fadeTo("fast", 1).delay(300).css({"color":"red"});
  140. showCheck1 = 0;
  141. $(".md").css("max-width", "");
  142. $(".commentarea").css("margin-right", careaRight);
  143. if($(".expando").css("display") == "block") {
  144. $(".md").css("max-width", "");
  145. $(".commentarea").css("margin-right", careaRight);
  146. }
  147. else{
  148. }
  149. }
  150. else if($.cookie("check") == 2) {
  151. $('.side').hide();
  152. $("#siteTable").each(function () {
  153. this.style.setProperty("margin-right", "auto", "important");
  154. this.style.setProperty("padding-right", "5px", "important");
  155. });
  156. $(".thing").each(function () {
  157. this.style.setProperty("margin-right", "auto", "important");
  158. });
  159. $(".content").each(function () {
  160. this.style.setProperty("padding-top", "1px", "important");
  161. this.style.setProperty("margin-right", "auto", "important");
  162. this.style.setProperty("margin-top", "auto", "important");
  163. });
  164. $("#myButton1").fadeTo("fast", 0.5).delay(300).css({"color":"blue"});
  165. showCheck1 = 1;
  166. $(".md").css("max-width", "100%");
  167. $(".commentarea").css("margin-right", "0px");
  168. if($(".expando").css("display") == "block") {
  169. $(".md").css("max-width", "100%");
  170. $(".commentarea").css("margin-right", "0px");
  171. }
  172. }
  173. else {
  174. }
  175. //--- Style our newly added elements using CSS.
  176. GM_addStyle ( multilineStr ( function () {/*!
  177. #myContainer1 {
  178. position: fixed;
  179. top: 80px;
  180. left: 0;
  181. font-size: 1px;
  182. border: 0px inset black;
  183. margin: 0px;
  184. opacity: 10.0;
  185. z-index: 99999;
  186. padding: 0px 0px;
  187. }
  188. #myButton1 {
  189. cursor: pointer;
  190. background: solid;
  191. background-color: #cee3f8;
  192. border: none !important;
  193. opacity: 8;
  194. color: red;
  195. font-weight: bold;
  196. }
  197. #myContainer1 p {
  198. color: purple;
  199. background: white;
  200. }
  201. */} ) );
  202.  
  203. function multilineStr (dummyFunc) {
  204. var str = dummyFunc.toString ();
  205. str = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
  206. .replace (/\s*\*\/\s*\}\s*$/, '') // Strip */ }
  207. .replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
  208. ;
  209. return str;
  210. }
  211. //
  212. });