Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name cr
- // @namespace someNamefu
- // @include http://chaturbate.com/*
- // @include /^https?://[a-z]+\.chaturbate\.com/.*$/
- // @version 1
- // @grant GM_xmlhttpRequest
- // @grant unsafeWindow
- // ==/UserScript==
- //
- // Little userscript to interact with the HasNoName script from chaturbate.com
- // Based on snippet posted by malky
- //
- // TODO:
- // - make host variable
- var port = 80;
- var checkInterval = 5000;
- // Don't change this variables
- var requestUrl = "";
- var params = "";
- var btn_auto;
- var btn_record;
- var div_info;
- var recording = false;
- var autoRecord = false;
- $ = unsafeWindow.$;
- window = unsafeWindow;
- function createUI(){
- var box = document.createElement('div');
- box.style.position = "absolute";
- box.style.top = 0;
- box.style.left = "50%";
- box.style.border = "dotted 1px";
- btn_auto = document.createElement('input');
- btn_auto.type = "button";
- btn_auto.style.backgroundColor = 'green';
- btn_auto.value = "Start auto recording";
- btn_auto.onclick = triggerAutoRecord
- btn_record = document.createElement('input');
- btn_record.type = "button";
- btn_record.value = 'Record';
- btn_record.style.backgroundColor = 'green';
- btn_record.onclick = triggerRecord;
- div_info = document.createElement('div');
- div_info.style.display = "block";
- div_info.innerHTML = "No player found";
- div_info.style.backgroundColor = 'white';
- box.appendChild(btn_record);
- box.appendChild(btn_auto);
- box.appendChild(div_info);
- document.body.appendChild(box);
- }
- function isPlayerAvailable(){
- // pretty dirty check but should work. TODO: find a better way
- return $('#movie').attr('data') != undefined && $('.hostmessagelabel').last().parent().contents().last().text() != " has left the room.";
- }
- function getPlayerOptions(){
- var raw=$('param[name="FlashVars"]').val().split('&');
- var fv={};
- for(var i in raw){
- var d=raw[i].split('=');
- fv[d[0]] = unescape(d[1]);
- }
- var swfu=$('#movie').attr('data');
- if(swfu){
- swfv = swfu.substring(swfu.indexOf('_')+1,swfu.indexOf('.')).replace('p','.');
- cmd = btoa('-v -r "rtmp://'+fv['address']+'/live-edge" -p "http://'+fv['dom']+'/'+fv['pid']+'" -C S:'+fv['uid']+' -C S:'+fv['pid']+' -C S:'+swfv+' -C S:'+fv['pw']+' -C S:'+fv['rp']+' -T "m9z#$dO0qe34Rxe@sMYxx%%" -y "playpath"');
- return new Array(cmd, fv['pid']);
- }
- return false;
- }
- function triggerRecord(){
- // we don't care about responses here
- req = document.createElement('img');
- if( recording )
- req.src = "http://localhost:"+port+"/stop/" + params;
- else
- req.src = "http://localhost:"+port+"/record/" + params;
- div_info.innerHTML = (recording?"Stopped":"Started") + " recording";
- }
- function triggerAutoRecord(){
- if( autoRecord ){
- div_info.innerHTML = 'Stopped auto recording';
- btn_auto.style.backgroundColor = 'green';
- btn_auto.value = "Start auto recording";
- if( recording )
- triggerRecord();
- }else{
- div_info.innerHTML = "Started auto recording";
- btn_auto.style.backgroundColor = 'red';
- btn_auto.value = "Stop auto recording";
- }
- autoRecord = !autoRecord;
- }
- function checkStatus(cmd, performer){
- if( !isPlayerAvailable() ){
- if( requestUrl ) requestUrl = "";
- div_info.innerHTML = "No player found";
- return false;
- }else if ( ! requestUrl ){
- var pair = getPlayerOptions();
- params = "?performer="+pair[1]+"&cmd="+pair[0];
- requestUrl = "http://localhost:"+port+"/status/" + params;
- div_info.innerHTML = "Player found";
- }else
- div_info.innerHTML = "Update ...";
- // Do the web request with greasemonkey to avoid CrossDomain problems
- // TODO: TOCHECK: Is there something similar in chrome ?
- GM_xmlhttpRequest({
- method: "GET",
- url: requestUrl,
- timeout: 5000,
- onload: function(response) {
- data = JSON.parse(response.responseText);
- if( data[0] ){
- div_info.innerHTML = "Recording since " + data[1] + " seconds";
- btn_record.style.backgroundColor = 'red';
- btn_record.value = "Stop";
- recording = true;
- }else{
- div_info.innerHTML = "Not recording";
- btn_record.style.backgroundColor = 'green';
- btn_record.value = "Record";
- recording = false;
- if( autoRecord )
- triggerRecord()
- }
- },
- ontimeout: function(response) {
- div_info.innerHTML = "Timed out";
- }
- });
- }
- // start the main loop
- createUI();
- window.setInterval(checkStatus, checkInterval);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement