-
Notifications
You must be signed in to change notification settings - Fork 1
/
initialize.js
48 lines (43 loc) · 1.54 KB
/
initialize.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
// Persistence
var toggleRedditImageGalleryState;
if (typeof(Storage) !== "undefined") {
var redditImageGalleryEnabledIn = [];
var url = location.href;
var indexOfQuestionMark = url.indexOf('?');
if (indexOfQuestionMark >= 0) {
url = url.substr(0, indexOfQuestionMark);
}
else {
var indexOfHash = url.indexOf('#');
if (indexOfHash >= 0)
url = url.substring(0, indexOfHash);
}
if (!localStorage.RedditImageGallery) {
localStorage.RedditImageGallery = [];
}
else {
redditImageGalleryEnabledIn = JSON.parse(localStorage.RedditImageGallery);
}
toggleRedditImageGalleryState = function() {
// Save state
var curIndex = redditImageGalleryEnabledIn.indexOf(url);
if (curIndex >= 0) {
$("a.rig_button").removeClass('active');
redditImageGalleryEnabledIn.splice(curIndex, 1);
}
else {
$("a.rig_button").addClass('active');
redditImageGalleryEnabledIn.push(url);
}
localStorage.RedditImageGallery = JSON.stringify(redditImageGalleryEnabledIn);
};
$(function(){
var $sep = $("#header-bottom-right .separator").last();
$("<span>").addClass('separator').text("|").insertBefore($sep);
$("<a>").addClass('rig_button rig_icon').click(toggleRedditImageGallery).insertBefore($sep);
if (redditImageGalleryEnabledIn.indexOf(url) >= 0) {
toggleRedditImageGalleryState();
toggleRedditImageGallery();
}
});
}