-
Notifications
You must be signed in to change notification settings - Fork 2
/
script.js
54 lines (47 loc) · 1.36 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
/*
* 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 cssId = "sidebarhider"
$('body').on('click', 'a#hslink', function() {
var text = $(this).text()
if(text == hideText) {
$(this).text(showText)
$('div.side').hide()
hideUsingCss()
localStorage['hideStatus'] = 'hide'
} else {
$(this).text(hideText)
$('div.side').show()
localStorage['hideStatus'] = 'show'
showUsingCss()
}
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()
hideUsingCss()
$('#hslink').text(showText)
} else {
showUsingCss()
$('#hslink').text(hideText)
}
function hideUsingCss() {
var css = document.createElement("style");
css.type = "text/css";
css.innerHTML = "body > div.content {margin-right:5px;}";
css.id = cssId;
document.body.appendChild(css);
}
function showUsingCss() {
var cssNode = document.getElementById(cssId);
cssNode && cssNode.parentNode.removeChild(cssNode)
}