forked from hsbakshi/reddit_hide_sidebar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
66 lines (59 loc) · 2.05 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright 2010 Hrishikesh Bakshi
*
* Reddit-Hide-Sidebar
* Shows a "Hide Sidebar" or "Show Sidebar" to hide/show reddit's sidebar.
*/
var showText = "Show Sidebar";
var hideText = "Hide Sidebar";
var marginCutOff = 50;
var contentLeft = $('div.content').css('margin-left');
var contentRight = $('div.content').css('margin-right');
var commentLeft = $('div.commentarea').css('margin-left');
var commentRight = $('div.commentarea').css('margin-right');
$('body').on('click', 'a#hslink', function() {
var text = $(this).text();
if(text == hideText) {
$(this).text(showText);
$('div.side').hide();
removeMargins();
localStorage['hideStatus'] = 'hide'
} else {
$(this).text(hideText);
addMargins();
$('div.side').show();
localStorage['hideStatus'] = 'show';
}
return false;
})
var show = '<span id="hideSpan" class="showlink">'+
'<a id="hslink" href=""></a></span>';
$("div#header-bottom-right").append('<span class="separator">|</span>');
$("div#header-bottom-right").append(show);
if (localStorage["hideStatus"] == "hide") {
$('div.side').hide();
removeMargins();
$('#hslink').text(showText);
} else {
$('#hslink').text(hideText);
}
function removeMargins() {
setMargin('div.content', 'margin-left', '0px', contentLeft);
setMargin('div.content', 'margin-right', '0px', contentRight);
setMargin('div.commentarea', 'margin-left', '0px', commentLeft);
setMargin('div.commentarea', 'margin-right', '0px', commentRight);
}
function addMargins() {
setMargin('div.content', 'margin-left', contentLeft);
setMargin('div.content', 'margin-right', contentRight);
setMargin('div.commentarea', 'margin-left', commentLeft);
setMargin('div.commentarea', 'margin-right', commentRight);
}
function setMargin(selector, style, val, orig) {
if(typeof orig === "undefined") {
orig = val;
}
if(parseInt(orig) > marginCutOff) {
$(selector).css(style, val, true);
}
}