-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuser.js
247 lines (225 loc) · 8.83 KB
/
user.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
// ==UserScript==
// @name sig easy copy
// @author Nick Hall
// @namespace http://soitgo.es
// @include https://soitgo.es/
// @include https://soitgo.es/?*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @version 1.2.5
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// ==/UserScript==
$(document).ready(function()
{
if ($('#login').length === 0)
{
easycopy.init();
}
});
var easycopy = {
init: function()
{
easycopy.loadSettings();
console.log(easycopy.settings);
// Add x and + links
$('#links .date').append('<span class="easycopy"><a href="#" class="ezc-links">x</a> <a href="#" class="ezc-thumbs">+</a></span>');
$('.easycopy a.ezc-links').click(easycopy.handleClick);
$('.easycopy a.ezc-thumbs').click(easycopy.thumbsClick);
// Link box, loading box
$('#links').before('<div id="ezc-textcontainer" style="height: 100px; clear: both; margin: 0 20px 20px 20px; padding: 0 !important;"><textarea id="easycopytext" style="width: 922px; height: 98px; padding: 0 !important; margin: 0 !important; z-index: 10;" placeholder="Click the x to the right of each link to get started."></textarea></div><div id="ezc-loading" style="position: fixed; bottom: 0; right: 0;">Loading...</div>');
$('#ezc-loading').hide();
$('#easycopytext').focus(function() {$(this).select();});
//Comment this out if you don't want the top link I guess
$('body').append('<div id="toTheTop" style="position: fixed; left: 5px; bottom: 5px;"><a href="#">top</a></div>');
$('#toTheTop').click(function(e)
{
e.preventDefault();
window.scrollTo(0, 0);
});
// Settings page
var settingsIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjAuNWWFMmUAAAJ2SURBVDhPjVVJixNBFC69qD9BVBwVFQ+DN/EPCIoHYYbxrqC3HHKc5BAIgWxGzB6ym5iNNGTS2ZeLiKcR5uBfEBM3RNwHpP2eqeeUPR31g0dXV73vq7dUdYu/weFwHK1Wq497vd6Lbrf7sl6vP3U6nSfl8v/B5/OtyqEIBAJXx+OxQTYajYzJZGIEg8E1uSy8Xu9FObRGMpncHAwG3zOZTLJYLBYQ1cfhcGiohrlP5YflR/B5gMh30+m0W9L/wIFwOLxJEXAkPDYLmten06kRi8U8pLGQAtxu9yo7W5E5batN6J3M4/FcknJCuFyuw9lsNkEEdiQBXdc/IPVsKpW6i3LcKRQKqXa7/U71o3EulyvZ7fYjUm6BYqGYY0d6NpvN52qDGH6//7zW1J6pvqVSqSmXhcAxOAHiFRT4C4ePwr9HGS5Il30A51Rnq/OGuw//b9C4hkxXBJ0zXuAdkX5GcpcC3b1HDSEOcUmj0WhsC0Q2YzEWTCQStyVvKaLR6DqJME9G+ooE52bBeDx+S/KWIhKJrFkIvhZ0nbjALJjP55OStxRI2WvmoVk7VOAzuGI3qLC0C1lH77ylecndBxT/eKvVmilN2Q2FQuuYPycMIYxlhiNyVmr8Bu7vSq1We8LR0bNcLm/JZbBUEYLyTpHi0IZwtW6iURvovl9v6XNzqrjXWZvNduifgpQOESg1MhrTHIuRcZlw9S7vCVpBCqpkFiBhFqeziOjvo34H9wTZpBBbv9//bBbEMftaqVTaKEUO7z+oJL+EGKqAWRAf0+ucEhmljW5uSCp9jBdpqlAFzIZfwDGtoW0j0hlsrmnaDlI7LakWEOIn6cMDH2scnnQAAAAASUVORK5CYII=';
$('body').append('<div id="ezc-settings-div" style="position: fixed; width: 800px; max-height: 500px; top: 50%; left: 50%; margin-left: -400px; margin-top: -250px; background-color: ' + $('body').css('background-color') + '; border: 2px solid ' + $('body').css('color') + '; border-radius: 10px; padding: 10px;">\
<h2>Settings</h2>\
<p><label>Show link box by default <input type="checkbox" id="ezc-settings-linkbox" /></label></p>\
<button id="ezc-settings-save">Save</button>\
<p><a href="#" class="ezc-settings-open">Close</a></p>\
</div>');
$('#ezc-settings-div').hide();
$('#ezc-settings-save').click(easycopy.saveSettings);
$('nav .ten.columns.omega').append('<a href="#" class="ezc-settings-open"><img src="' + settingsIcon + '" style="height: 20px; width: 20px; margin-bottom: 5px;" /></a>');
$('.ezc-settings-open').click(function(e) {e.preventDefault(); $('#ezc-settings-div').toggle('fast');});
if(easycopy.settings.showLinkBox) $('#ezc-settings-linkbox').prop('checked', true);
// Another div for status messages
$('body').append('<div id="ezc-status" style="position: fixed; right: 5px; top: 5px; background-color: #191919 !important; color: white !important; padding: 5px !important;">This should never be seen</div>');
$('#ezc-status').hide();
MutationObserver = window.MutationObserver || window.WebKitMutationObserver;
var observer = new MutationObserver(function(mutations)
{
mutations.forEach(function(mutation)
{
if (typeof mutation.addedNodes == "object")
{
$(mutation.addedNodes).find('.date').each(function()
{
$(this).append(' <span class="easycopy"><a href="#" class="ezc-links">x</a> <a href="#" class="ezc-thumbs">+</a></span>');
$(this).find('.ezc-links').click(easycopy.handleClick);
$(this).find('.ezc-thumbs').click(easycopy.thumbsClick);
});
}
});
});
// define what element should be observed by the observer
observer.observe(document, {
subtree: true,
childList: true
});
// Set up moving the text area on scroll
var textareaInitialPosition = $('#easycopytext').offset().top - 10;
$(window).scroll(function()
{
if ($(window).scrollTop() > textareaInitialPosition)
{
$('#easycopytext').css('position', 'fixed');
$('#easycopytext').css('top', '10px');
}
else
{
$('#easycopytext').css('position', '');
$('#easycopytext').css('top', '');
}
});
// Throw in some custom inline CSS for voting links (since we need to use !important)
$('head').append('<style type="text/css">\
.ezc-flood {\
color: orange !important;\
}\
.ezc-voted {\
color: green !important;\
}\
.ezc-alreadyvoted {\
color: red !important;\
}\
.easycopy button {\
margin: 0 !important;\
}\
</style>');
// Show/hide the link box if we want
$('#middlebar > a:nth-child(4)').after('<button id="ezc-linkToggle">Link Box</button>');
$('#ezc-linkToggle').click(function(e)
{
$('#ezc-textcontainer').toggle('fast');
});
if (!easycopy.settings.showLinkBox) $('#ezc-textcontainer').hide();
},
handleClick: function(event)
{
event.preventDefault();
var url = $(this).parent().parent().prev().find('.title').parent().attr('href'); // This was being really finnicky
$(this).parent().parent().prev().find('.title').css("cssText", "color: #FF0000 !important;");
easycopy.enqueue();
$.get(url, easycopy.populateURLBox);
$(this).remove();
},
thumbsClick: function(event)
{
event.preventDefault();
var linkID = $(this).parent().parent().prev().find('.title').parent().attr('href').split(':');
var currentLink = $(this);
if (currentLink.hasClass('ezc-alreadyvoted') || currentLink.hasClass('ezc-voted'))
{
easycopy.displayMessage("Already voted");
return; // Don't pester the server if we've already voted
}
easycopy.enqueue('vote');
$.ajax('ajax.php?i=link&thank=' + linkID[1]).done(function (msg)
{
currentLink.removeClass('ezc-flood');
currentLink.removeClass('ezc-voted');
currentLink.removeClass('ezc-alreadyvoted');
if (msg == 'flood')
{
currentLink.addClass('ezc-flood');
easycopy.displayMessage("Please wait");
console.log("FLOOD!!!");
}
else if (msg)
{
easycopy.displayMessage("Vote successful");
currentLink.addClass('ezc-voted');
console.log("VOTED");
}
else
{
easycopy.displayMessage("Already voted");
currentLink.addClass('ezc-alreadyvoted');
console.log("Already voted");
}
easycopy.dequeue();
}
);
},
populateURLBox: function(data)
{
var linkData = "";
var password = $(data).find('#password').text();
linkData += $(data).find('#title').text() + ' [password: ' + password + ']\n';
$(data).find('#links_mega a').each(function() { linkData += $(this).attr('href') + '\n\n'; });
$('#easycopytext').val($('#easycopytext').val() + linkData);
easycopy.dequeue();
},
loadingCount: 0,
enqueue: function(type)
{
easycopy.loadingCount++;
if (type !== 'vote')
{
$('#easycopytext').prop('disabled', true);
$('#easycopytext').css('user-select', 'none');
}
$('#ezc-loading').show('fast');
},
dequeue: function(type)
{
easycopy.loadingCount--;
if (easycopy.loadingCount === 0)
{
if (type !== 'vote')
{
$('#easycopytext').prop('disabled', false);
$('#easycopytext').css('user-select', 'all');
}
$('#ezc-loading').hide('slow');
}
},
displayMessage: function(message)
{
$('#ezc-status').text(message);
$('#ezc-status').show('fast').delay(3000).fadeOut();
},
settings: [],
saveSettings: function()
{
GM_setValue('showLinkBox', $('#ezc-settings-linkbox').is(':checked'));
easycopy.displayMessage("Settings saved");
},
loadSettings: function()
{
var settings = GM_listValues();
if (settings.length === 0)
{
easycopy.runFirstTime(); // Run if we haven't saved anything yet
settings = GM_listValues(); // Reload
}
for (var i = 0; i < settings.length; i++)
{
easycopy.settings[settings[i]] = GM_getValue(settings[i]);
}
},
runFirstTime: function()
{
console.log('Running initial setup...');
console.log('Defaulting link box display to true');
GM_setValue('showLinkBox', true);
}
};