Side-Reddit

Handy Dandy Toggle for the Side Bar

目前為 2014-03-10 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Side-Reddit
// @version    1.26
// @description Handy Dandy Toggle for the Side Bar
// @include        http://*.reddit.com/*
// @include        http://reddit.com/*
// @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @require     http://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.0/jquery.cookie.min.js
// @grant       GM_addStyle
// @namespace https://greasyfork.org/users/59
// ==/UserScript==

$(document).ready(function () {
  
var showCheck1 = 0;
var pTop = $('.content').css("padding-top");
var cmRight = $('.content').css("margin-right");
var careaRight = $('.commentarea').css("margin-right");
var cMargin = $('.content').css("margin");
var mTop = $('.content').css("margin-top");
var smRight = $('#siteTable').css("margin-right");
var spRight = $('#siteTable').css("padding-right");
var tmRight = $('.thing').css("margin-right");
var zNode1       = document.createElement ('div');
var foo = document.getElementById(".expando-button")    
    
zNode1.innerHTML = '<button id="myButton1" type="button">'
                + '‡</button>';

zNode1.setAttribute ('id', 'myContainer1');
document.body.appendChild (zNode1);
    
    
    $(function () {
    $(".md").css("max-width", "100%");
      $(".commentarea").css("margin-right", "0px");
    });
        
    $("div.expando-button").click(function(){
        $(".md").css("max-width", "100%");
      $(".commentarea").css("margin-right", "0px"); 
    });


//--- Activate the newly added button.
document.getElementById ("myButton1").addEventListener (
    "click", ButtonClickAction, false
);

    /*
    if($(".expando-button").is(":hover"){
          
          $(".md").css("max-width", "100%");
      $(".commentarea").css("margin-right", "0px"); 
    	  
    }
    else{
       
     $(".md").css("max-width", "");
        $(".commentarea").css("margin-right", careaRight);
    } */
       
    
function ButtonClickAction (zEvent) {
    
if(showCheck1 == 1) {
	   $('.side').show();
       /* $('.content').css("margin", ""); */
       /* $('a').attr('target', ''); */
       $("#siteTable").each(function () {
         this.style.setProperty("margin-right", "", "important");
         this.style.setProperty("margin-right", "", "important");
});
       $("#siteTable").each(function () {
         this.style.setProperty("margin-right", smRight);
           this.style.setProperty("margin-right", spRight);
});
       $(".thing").each(function () {
         this.style.setProperty("margin-right", "", "important");
});
       $(".thing").each(function () {
         this.style.setProperty("margin-right", "");
});
       $(".content").each(function () {
         this.style.setProperty("padding-top", "", "important");
         this.style.setProperty("margin-right", "", "important");
         this.style.setProperty("margin-top", "");
});
    /* $(".content").each(function () {
        this.style.setProperty("padding-top", pTop);
        this.style.setProperty("margin-right", cmRight);
        this.style.setProperty("margin-left", mLeft);
        this.style.setProperty("margin", cMargin);
}); */
       $("#myButton1").fadeTo("fast", 1).delay(300).css({"color":"red"});
       showCheck1 = 0; 
       $.cookie("check", 1, { expires: 7, path: "/" });
       $(".md").css("max-width", "");
      $(".commentarea").css("margin-right", careaRight);
    
    if($(".expando").css("display") == "block") {
        $(".md").css("max-width", "");
        $(".commentarea").css("margin-right", careaRight);
    }
    else{
    }
}
else if(showCheck1 == 0) {
   
       $('.side').hide();
       /* $('.content').css("margin", "auto"); */
       /* $('a').attr('target', '_blank'); */
       $("#siteTable").each(function () {
         this.style.setProperty("margin-right", "auto", "important");
           this.style.setProperty("padding-right", "5px", "important");
});
       $(".thing").each(function () {
         this.style.setProperty("margin-right", "auto", "important");
});
       $(".content").each(function () {
         this.style.setProperty("padding-top", "1px", "important");
         this.style.setProperty("margin-right", "auto", "important");
         this.style.setProperty("margin-top", "auto", "important");
});
       $("#myButton1").fadeTo("fast", 0.5).delay(300).css({"color":"blue"});
       showCheck1 = 1;  
       $.cookie("check", 2, { expires: 7, path: "/" });
       $(".md").css("max-width", "100%");
      $(".commentarea").css("margin-right", "0px");
    if($(".expando").css("display") == "block") {
        $(".md").css("max-width", "100%");
      $(".commentarea").css("margin-right", "0px");
    }
    else{
    }
}
else {
    
}
       
}

//--- Cookie Test.
/* showCheck4 = $.cookie("check"); */
    
if($.cookie("check") == 1) {
	   $('.side').show();
       /* $('.content').css("margin", ""); */
       /* $('a').attr('target', ''); */
       $("#siteTable").each(function () {
         this.style.setProperty("margin-right", "", "important");
         this.style.setProperty("margin-right", "", "important");
});
       $("#siteTable").each(function () {
         this.style.setProperty("margin-right", smRight);
           this.style.setProperty("margin-right", spRight);
});
       $(".thing").each(function () {
         this.style.setProperty("margin-right", "", "important");
});
       $(".thing").each(function () {
         this.style.setProperty("margin-right", "");
});
       $(".content").each(function () {
         this.style.setProperty("padding-top", "", "important");
         this.style.setProperty("margin-right", "", "important");
         this.style.setProperty("margin-top", "");
});
    /* $(".content").each(function () {
        this.style.setProperty("padding-top", pTop);
        this.style.setProperty("margin-right", cmRight);
        this.style.setProperty("margin-left", mLeft);
        this.style.setProperty("margin", cMargin);
}); */
       $("#myButton1").fadeTo("fast", 1).delay(300).css({"color":"red"});
       showCheck1 = 0; 
       $(".md").css("max-width", "");
       $(".commentarea").css("margin-right", careaRight);
    if($(".expando").css("display") == "block") {
        $(".md").css("max-width", "");
        $(".commentarea").css("margin-right", careaRight);
    }
    else{
    }
      
}
else if($.cookie("check") == 2) {
   
       $('.side').hide();
       /* $('.content').css("margin", "auto"); */
       /* $('a').attr('target', '_blank'); */
       $("#siteTable").each(function () {
         this.style.setProperty("margin-right", "auto", "important");
           this.style.setProperty("padding-right", "5px", "important");
});
       $(".thing").each(function () {
         this.style.setProperty("margin-right", "auto", "important");
});
       $(".content").each(function () {
         this.style.setProperty("padding-top", "1px", "important");
         this.style.setProperty("margin-right", "auto", "important");
         this.style.setProperty("margin-top", "auto", "important");
});
       $("#myButton1").fadeTo("fast", 0.5).delay(300).css({"color":"blue"});
       showCheck1 = 1;
       $(".md").css("max-width", "100%");
       $(".commentarea").css("margin-right", "0px");
    if($(".expando").css("display") == "block") {
        $(".md").css("max-width", "100%");
      $(".commentarea").css("margin-right", "0px");
    }
}
else {
    
}
  
//--- Style our newly added elements using CSS.
GM_addStyle ( multilineStr ( function () {/*!
    #myContainer1 {
        position:               fixed;
        top:                    0;
        left:	 0;
        font-size:              1px;
        border:                 0px inset black;
        margin:                 1px;
        opacity:                10.0;
        z-index:                115;
        padding:                1px 1px;
    }
    #myButton1 {
        cursor:                 pointer;
       	background: 			solid;
        background-color:		#cee3f8;
    	border: 				none !important;
        opacity:				8;
        color:					red;
        font-weight:			bold;
    }
    #myContainer1 p {
        color:                  purple;
        background:             white;
    }
*/} ) );

function multilineStr (dummyFunc) {
    var str = dummyFunc.toString ();
    str     = str.replace (/^[^\/]+\/\*!?/, '') // Strip function () { /*!
            .replace (/\s*\*\/\s*\}\s*$/, '')   // Strip */ }
            .replace (/\/\/.+$/gm, '') // Double-slash comments wreck CSS. Strip them.
            ;
    return str;
}
    
  //
});