SHOW:
|
|
- or go back to the newest paste.
1 | // ==UserScript== | |
2 | // @name Chaturbate Cam Viewer | |
3 | // @version 2.3 | |
4 | // @include http://chaturbate.com/ | |
5 | // @include http://chaturbate.com/#* | |
6 | // @include http://chaturbate.com/*-cams/* | |
7 | // @include http://*.chaturbate.com/ | |
8 | // @include http://*.chaturbate.com/#* | |
9 | // @include http://*.chaturbate.com/*-cams/* | |
10 | // @exclude http://serve.ads.chaturbate.com/ | |
11 | // @grant GM_getValue | |
12 | // @grant GM_setValue | |
13 | // @namespace http://userscripts.org/users/584739 | |
14 | // @source http://userscripts.org/scripts/show/386321 | |
15 | // @updateURL https://userscripts.org/scripts/source/386321.meta.js | |
16 | // @downloadURL https://userscripts.org/scripts/source/386321.user.js | |
17 | // ==/UserScript== | |
18 | ||
19 | var gm = new(function(){ | |
20 | ||
21 | var self = this; | |
22 | ||
23 | this.STORAGE_KEY_NAME = "chaturbate_girls"; | |
24 | this.LAYOUT_KEY_NAME = "chaturbate_layout"; | |
25 | ||
26 | this.get_layout = function(){ | |
27 | setTimeout(function(){ | |
28 | var temp = 2; | |
29 | var layout_id = GM_getValue(self.LAYOUT_KEY_NAME); | |
30 | if (typeof layout_id == "undefined") | |
31 | layout_id = temp; | |
32 | ||
33 | var adder = function(lid){ | |
34 | viewer.layout_id = lid; | |
35 | viewer.layout(lid); | |
36 | } | |
37 | var script = document.createElement("script"); | |
38 | script.textContent = "(" + adder.toString() + ")("+layout_id+");"; | |
39 | document.body.appendChild(script); | |
40 | ||
41 | },0); | |
42 | } | |
43 | ||
44 | this.get_girls = function(){ | |
45 | setTimeout(function(){ | |
46 | var temp = '[]'; | |
47 | var sJSON = GM_getValue(self.STORAGE_KEY_NAME); | |
48 | if (typeof sJSON == "undefined") | |
49 | sJSON = temp; | |
50 | var adder = function(savedGirls){ | |
51 | $.each(savedGirls,function(){ | |
52 | viewer.girls.push(new Girl(this)); | |
53 | }); | |
54 | if ( location.hash == "#live" ) | |
55 | viewer.show(); | |
56 | } | |
57 | var script = document.createElement("script"); | |
58 | script.textContent = "(" + adder.toString() + ")("+sJSON+");"; | |
59 | document.body.appendChild(script); | |
60 | ||
61 | },0); | |
62 | } | |
63 | ||
64 | this.set_girls = function(){ | |
65 | setTimeout(function(){ | |
66 | var data = JSON.stringify(unsafeWindow.jQuery.map(unsafeWindow.viewer.girls,function(o){ return o.username })); | |
67 | GM_setValue(self.STORAGE_KEY_NAME, data); | |
68 | },0); | |
69 | } | |
70 | ||
71 | this.set_layout = function(){ | |
72 | setTimeout(function(){ | |
73 | GM_setValue(self.LAYOUT_KEY_NAME, unsafeWindow.viewer.layout_id); | |
74 | },0); | |
75 | } | |
76 | }); | |
77 | ||
78 | unsafeWindow.gm = gm; | |
79 | ||
80 | function main() { | |
81 | if (typeof jQuery != "undefined"){ | |
82 | jQuery(document).ready(function(){ | |
83 | function getKey(e) { | |
84 | if(window.event) { // IE | |
85 | return e.keyCode; | |
86 | } else if(e.which) { // Netscape/Firefox/Opera | |
87 | return e.which | |
88 | } | |
89 | } | |
90 | ||
91 | var exports = "getKey,toHtml,websiteHostName,Girl,viewer"; | |
92 | ||
93 | var toHtml = function(data, template){ | |
94 | return template.replace(/#(?:\{|%7B)(.*?)(?:\}|%7D)/g, function($1, $2){ | |
95 | return ($2 in data) ? data[$2] : ''; | |
96 | }) | |
97 | } | |
98 | ||
99 | var websiteHostName = "http://" + location.host + "/"; | |
100 | ||
101 | var Girl = function(name){ | |
102 | var user = name.replace(/\//g,""); | |
103 | var self = this; | |
104 | this.href = websiteHostName + user; | |
105 | this.username = user; | |
106 | this.src = websiteHostName + "embed/" + self.username + "/?join_overlay=1&room=" + self.username; | |
107 | } | |
108 | ||
109 | ||
110 | var viewer = new (function(){ | |
111 | ||
112 | var self = this; | |
113 | ||
114 | var list_template = '<li id="#{username}">'+ | |
115 | ' <img src="http://ccstatic.highwebmedia.com/static/images/ico-01.png" class="remove" onclick="viewer.remove(\'#{username}\',this)">'+ | |
116 | ' <a target="_blank" href="#{href}"><img src="http://ccstatic.highwebmedia.com/static/images/ico-cams.png" class="handle" title="#{username}"></a>'+ | |
117 | ' <iframe src="#{src}"></iframe>'+ | |
118 | ' </li>'; | |
119 | ||
120 | this.layout_id = 2; | |
121 | this.girls = []; | |
122 | this.all_girls = []; | |
123 | this.loaded = false; | |
124 | ||
125 | this.init = function(){ | |
126 | ||
127 | $('.content').prepend("<div style='width:1500px; margin:3px 32px; padding:3px; border:1px solid #CCC;'> Use the <img src='http://ccstatic.highwebmedia.com/static/images/ico-01.png?a83ca9dd70c8' align='absmiddle'> icon to add girls to the LIVE CAMS tab </div>"); | |
128 | ||
129 | var template = '<div id="camGirls" style="visibility:hidden;">'+ | |
130 | '<div id="camControls">'+ | |
131 | 'Username: <input type="text" name="camGirlUsername" id="camGirlUsername" onkeyup="if (getKey(event) == 13) viewer.add()" >'+ | |
132 | '<input type="Button" value="Add" onclick="viewer.add()">'+ | |
133 | '<input type="Button" value="Add Top 12" onclick="viewer.addTop12()">'+ | |
134 | '<input type="Button" value="Remove All" onclick="viewer.removeAll()">'+ | |
135 | '<input type="Button" value="Remove Offlines" onclick="viewer.clearEmptyCams()">'+ | |
136 | '<input type="Button" value="Save" onclick="viewer.save()">'+ | |
137 | '[ Layout: '+ | |
138 | '<input type="Button" value="Semi-Compact" onclick="viewer.layout(1)" id="layout_1">'+ | |
139 | '<input type="Button" value="Compact" onclick="viewer.layout(2)" id="layout_2">'+ | |
140 | '<input type="Button" value="Full" onclick="viewer.layout(3)" id="layout_3">]'+ | |
141 | '</div>'+ | |
142 | '<ul id="girls_list"></ul>'+ | |
143 | '</div>'; | |
144 | $("#main .content").after(template); | |
145 | ||
146 | var css = '<style type="text/css">' + | |
147 | '#camGirls ul { margin: 0; padding:0; display:inline-block;}'+ | |
148 | '#camGirls li { margin: 0; padding:0; width:500px; overflow:hidden; display:inline-block; height:456px; }'+ | |
149 | '#camGirls iframe { margin: 0; padding:0; border:none; position:relative; width:1030px; height:528px; }'+ | |
150 | '#camGirls .remove { cursor:pointer; display:inline; top:2px; left:1px; position:relative; float:left; z-index:99; }'+ | |
151 | '#camGirls .handle { cursor:pointer; display:inline; top:2px; left:2px; position:relative; float:left; z-index:99; }'+ | |
152 | '#camControls { border:1px solid #CCC; margin:2px; padding:3px; }'+ | |
153 | '#camControls .active { border:1px solid black; background:#fff; color:#dc5500; }'+ | |
154 | '</style>'; | |
155 | $('body').append(css); | |
156 | ||
157 | ||
158 | self.getSaved(); | |
159 | self.fixRefresh(); | |
160 | self.updateLayout(); | |
161 | ||
162 | $(".sub-nav li").click(function(){ | |
163 | var page = location.href; | |
164 | if (page.indexOf('#') >- 1) | |
165 | page = location.href.split("#")[0]; | |
166 | var target = location.origin + $(this).find('a').attr('href'); | |
167 | if (page != target){ | |
168 | return true; | |
169 | } | |
170 | else { | |
171 | $("#main .content").show(); | |
172 | $("#main #camGirls").css({"visibility":"hidden","height":"0px"}); | |
173 | $(".sub-nav li").removeClass("active"); | |
174 | $(this).addClass("active"); | |
175 | location.hash = "#tab" | |
176 | return false; | |
177 | } | |
178 | }); | |
179 | ||
180 | var li = $("<li>").html("<a href='javascript:viewer.show();'>LIVE CAMS</a>"); | |
181 | ||
182 | $(".sub-nav").append(li); | |
183 | } | |
184 | ||
185 | this.fixRefresh = function(){ | |
186 | jQuery( "li.location" ).live("click", function() { | |
187 | viewer.add_girl($(this).parents('li').find('a').attr('href'),this); | |
188 | }).css("cursor","pointer").attr("title","Add girl to Live Cam"); | |
189 | } | |
190 | ||
191 | this.show = function(){ | |
192 | $(".sub-nav li").removeClass("active"); | |
193 | $(".sub-nav li:last").addClass("active"); | |
194 | $("#main .content").hide(); | |
195 | $("#main #camGirls").css({"visibility":"","height":"auto"}); | |
196 | location.hash = "#live" | |
197 | if (self.loaded == false){ | |
198 | self.loaded = true; | |
199 | self.updateLayout(); | |
200 | } | |
201 | } | |
202 | ||
203 | this.addTop12 = function(){ | |
204 | $(".list > li:lt(12)").each(function(){ | |
205 | self.add_girl($(this).find('a').attr('href')); | |
206 | }); | |
207 | self.updateLayout(); | |
208 | } | |
209 | ||
210 | this.add = function(){ | |
211 | viewer.girls.push(new Girl($('#camGirlUsername').val())); | |
212 | $("#camGirlUsername").val(""); | |
213 | self.updateLayout() | |
214 | } | |
215 | ||
216 | this.add_girl = function(username,obj){ | |
217 | self.girls.push(new Girl(username)); | |
218 | $(obj).html("Girl added to Live Cam"); | |
219 | self.loaded = false; | |
220 | } | |
221 | ||
222 | this.remove = function(username,elem){ | |
223 | $.each(self.girls, function(i,o){ | |
224 | if (typeof o != "undefined" && o.username.toLowerCase().indexOf(username.toLowerCase()) >-1 ){ | |
225 | self.girls.splice(i,1); | |
226 | $(elem).parent().remove(); | |
227 | } | |
228 | }); | |
229 | self.updateLayout(); | |
230 | } | |
231 | ||
232 | this.clearEmptyCams = function(){ | |
233 | $("#girls_list iframe").each(function(){ | |
234 | var username = $(this).parents("li")[0].id; | |
235 | //need to find a window variable that'll indicate when the flash object is there and it's offline | |
236 | if ($(this.contentWindow.document).find('#movie').length == 0) | |
237 | self.remove(username); | |
238 | }); | |
239 | } | |
240 | ||
241 | this.removeAll = function(){ | |
242 | self.girls = []; | |
243 | self.updateLayout(); | |
244 | } | |
245 | ||
246 | this.updateLayout = function(){ | |
247 | if ($("#camGirls:visible").length > 0) { | |
248 | $.each(self.girls, function(){ | |
249 | if ($("li#"+this.username).length == 0) | |
250 | $("#girls_list").append(toHtml(this,list_template)); | |
251 | }); | |
252 | $("#girls_list li").each(function(){ | |
253 | var user = this.id; | |
254 | var isIncluded = $.map(viewer.girls,function(o,i){ | |
255 | if (o.username == user){ | |
256 | return true; | |
257 | } | |
258 | }).length > 0; | |
259 | if (isIncluded == false) | |
260 | $(this).remove(); | |
261 | }); | |
262 | self.layout(self.layout_id); | |
263 | } | |
264 | } | |
265 | ||
266 | this.getSaved = function(){ | |
267 | gm.get_layout(); | |
268 | gm.get_girls(); | |
269 | } | |
270 | ||
271 | this.save = function(){ | |
272 | gm.set_girls(); | |
273 | gm.set_layout(); | |
274 | alert("Saved"); | |
275 | } | |
276 | ||
277 | this.layout = function(id){ | |
278 | self.layout_id = id; | |
279 | if (id == 1){ | |
280 | var columWidth = 500; | |
281 | var columnHeight = 470; | |
282 | var top = 0; | |
283 | } | |
284 | else if (id == 2){ | |
285 | var minWidth = 400; | |
286 | var columns = Math.floor($(window).width() / minWidth); | |
287 | var columWidth = Math.floor($(window).width() / columns) - 5; | |
288 | var columnHeight = 375; | |
289 | var top = -66; | |
290 | } | |
291 | else if (id == 3){ | |
292 | var columWidth = 1030; | |
293 | var columnHeight = 544; | |
294 | var top = 0; | |
295 | } | |
296 | $("#camControls input").removeClass('active') | |
297 | $("#layout_" + id).addClass('active') | |
298 | $("#camGirls li").width(columWidth); | |
299 | $("#camGirls li").height(columnHeight); | |
300 | $("#camGirls iframe").css({ top: top+"px" }); | |
301 | } | |
302 | ||
303 | }); | |
304 | $.each(exports.split(","),function(i,o){ | |
305 | window[o] = eval(o); | |
306 | }); | |
307 | window.viewer.init(); | |
308 | }); | |
309 | } | |
310 | } | |
311 | ||
312 | var script = document.createElement("script"); | |
313 | script.textContent = "(" + main.toString() + ")();"; | |
314 | document.body.appendChild(script); |