Advertisement
Guest User

chaturbate greasemonkey script

a guest
Mar 10th, 2014
3,224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        cr
  3. // @namespace   someNamefu
  4. // @include     http://chaturbate.com/*
  5. // @include     /^https?://[a-z]+\.chaturbate\.com/.*$/
  6. // @version     1
  7. // @grant       GM_xmlhttpRequest
  8. // @grant       unsafeWindow
  9. // ==/UserScript==
  10. //
  11. // Little userscript to interact with the HasNoName script from chaturbate.com
  12. // Based on snippet posted by malky
  13. //
  14. // TODO:
  15. // - make host variable
  16.  
  17. var port = 80;
  18. var checkInterval = 5000;
  19.  
  20.  
  21. // Don't change this variables
  22. var requestUrl = "";
  23. var params = "";
  24. var btn_auto;
  25. var btn_record;
  26. var div_info;
  27. var recording = false;
  28. var autoRecord = false;
  29. $ = unsafeWindow.$;
  30. window = unsafeWindow;
  31.  
  32. function createUI(){
  33.     var box = document.createElement('div');
  34.     box.style.position = "absolute";
  35.     box.style.top = 0;
  36.     box.style.left = "50%";
  37.     box.style.border = "dotted 1px";
  38.  
  39.     btn_auto = document.createElement('input');
  40.     btn_auto.type = "button";
  41.     btn_auto.style.backgroundColor = 'green';
  42.     btn_auto.value = "Start auto recording";
  43.     btn_auto.onclick = triggerAutoRecord
  44.    
  45.     btn_record = document.createElement('input');
  46.     btn_record.type = "button";
  47.     btn_record.value = 'Record';
  48.     btn_record.style.backgroundColor = 'green';
  49.     btn_record.onclick = triggerRecord;
  50.    
  51.     div_info = document.createElement('div');
  52.     div_info.style.display = "block";
  53.     div_info.innerHTML = "No player found";
  54.     div_info.style.backgroundColor = 'white';
  55.  
  56.     box.appendChild(btn_record);
  57.     box.appendChild(btn_auto);
  58.     box.appendChild(div_info);
  59.     document.body.appendChild(box);
  60. }
  61.  
  62.  
  63. function isPlayerAvailable(){
  64.     // pretty dirty check but should work. TODO: find a better way
  65.     return $('#movie').attr('data') != undefined && $('.hostmessagelabel').last().parent().contents().last().text() != "  has left the room.";
  66. }
  67.  
  68. function getPlayerOptions(){
  69.     var raw=$('param[name="FlashVars"]').val().split('&');
  70.     var fv={};
  71.     for(var i in raw){
  72.         var d=raw[i].split('=');
  73.         fv[d[0]] = unescape(d[1]);
  74.     }
  75.     var swfu=$('#movie').attr('data');
  76.     if(swfu){
  77.         swfv = swfu.substring(swfu.indexOf('_')+1,swfu.indexOf('.')).replace('p','.');
  78.         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"');
  79.         return new Array(cmd, fv['pid']);
  80.     }
  81.     return false;
  82. }
  83.  
  84. function triggerRecord(){
  85.     // we don't care about responses here
  86.     req = document.createElement('img');
  87.     if( recording )
  88.         req.src = "http://localhost:"+port+"/stop/" + params;
  89.     else
  90.         req.src = "http://localhost:"+port+"/record/" + params;
  91.     div_info.innerHTML = (recording?"Stopped":"Started") + " recording";
  92. }
  93. function triggerAutoRecord(){
  94.     if( autoRecord ){
  95.         div_info.innerHTML = 'Stopped auto recording';
  96.         btn_auto.style.backgroundColor = 'green';
  97.         btn_auto.value = "Start auto recording";
  98.         if( recording )
  99.             triggerRecord();
  100.     }else{
  101.         div_info.innerHTML = "Started auto recording";
  102.         btn_auto.style.backgroundColor = 'red';
  103.         btn_auto.value = "Stop auto recording";
  104.     }
  105.     autoRecord = !autoRecord;
  106. }
  107.  
  108. function checkStatus(cmd, performer){
  109.     if( !isPlayerAvailable() ){
  110.         if( requestUrl ) requestUrl = "";
  111.         div_info.innerHTML = "No player found";
  112.         return false;
  113.     }else if ( ! requestUrl ){
  114.         var pair = getPlayerOptions();
  115.         params = "?performer="+pair[1]+"&cmd="+pair[0];
  116.         requestUrl = "http://localhost:"+port+"/status/" + params;
  117.         div_info.innerHTML = "Player found";
  118.     }else
  119.         div_info.innerHTML = "Update ...";
  120.    
  121.     // Do the web request with greasemonkey to avoid CrossDomain problems
  122.     // TODO: TOCHECK: Is there something similar in chrome ?
  123.     GM_xmlhttpRequest({
  124.         method: "GET",
  125.         url: requestUrl,
  126.         timeout: 5000,
  127.         onload: function(response) {
  128.             data = JSON.parse(response.responseText);
  129.             if( data[0] ){
  130.                 div_info.innerHTML = "Recording since " + data[1] + " seconds";
  131.                 btn_record.style.backgroundColor = 'red';
  132.                 btn_record.value = "Stop";
  133.                 recording = true;
  134.             }else{
  135.                 div_info.innerHTML = "Not recording";
  136.                 btn_record.style.backgroundColor = 'green';
  137.                 btn_record.value = "Record";
  138.                 recording = false;
  139.                 if( autoRecord )
  140.                     triggerRecord()
  141.             }
  142.         },
  143.         ontimeout: function(response) {
  144.             div_info.innerHTML = "Timed out";
  145.         }
  146.     });
  147.  
  148. }
  149.  
  150. // start the main loop
  151. createUI();
  152. window.setInterval(checkStatus, checkInterval);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement