Code viewer for World: Second (clone by Moses Crasto)
// Cloned by Moses Crasto on 19 Nov 2023 from World "Generate with Blockade Labs API by Moses Crasto" by Moses Crasto 
// Please leave this clone trail here.

const URL = "https://api.d-id.com/clips";  // API endpoint
var skyboxAPIKey = "";  // API key

// Default body is margin 0 and padding 0, give it more whitespace:
$('body').css("margin", "20px");
$('body').css("padding", "20px");

document.write(`
  <h1>Generate with Labs</h1>
  <br>
  Generate a using the <a href=""> AI API</a>.
  <br>
//   <div id="enterkey">
//     Enter API key:
//     <input style='width:25vw;' maxlength='2000' name="apikey" id="apikey" value=''>
//     <button onclick='setkey();' class=ab-normbutton>Set API key</button>
//   </div>

  <div style="width:60vw; background-color:white; border: 1px solid black; margin:20; padding: 20px;">
    <h3>Enter a "prompt"</h3>
    <input style="width:50vw;" id="me" value="Hello from Ireland">
    <button onclick="sendchat();" class=ab-normbutton>Send</button>
  </div>

  <div style="width:60vw; background-color:#ffffcc; border: 1px solid black; margin:20; padding: 20px;">
    <div id="them"></div>
    <div id="hem"></div>
  </div>
`);

var theprompt = "Hello from Ireland";

// function setkey() {
//   skyboxAPIKey = jQuery("input#apikey").val();
//   skyboxAPIKey = skyboxAPIKey.trim();
//   $("#enterkey").html("<b> API key has been set. </b>");
// }

document.getElementById('me').onkeydown = function (event) { if (event.keyCode == 13) sendchat(); };

function sendchat() {
  //theprompt = $("#me").val();

  var thedata = {
    "script": {
        "type": "text",
        "input": "Hello from Ireland"
    },
    "presenter_id": "jack-KVaDW71ltd",
    "driver_id": "RISWj5PLjy"
  };

  var thedatastring = JSON.stringify(thedata);
  
  $.ajaxSetup({
     headers:
     {
         "Authorization":"Basic bW9zZXMuY3Jhc3RvMkBtYWlsLmRjdS5pZQ:3AcT1pVzX0l8e0uqzHD9K"
     }
  });
  
  $.ajax({
    type: "POST",
    url: URL,
    data: {
            "script": {
                "type": "text",
                "input": "Hello from Ireland"
            },
            "presenter_id": "jack-KVaDW71ltd",
            "driver_id": "RISWj5PLjy"
          },
    dataType: "json",
    success: function (d) { console.log(d); },
    error: function (e) { errorfn(e); }
  });
}

var a;

function successfn(data, rc) {
  a = data;
  var id = a["id"];
  console.log(data);
  
  setTimeout(doSomething, 20000);
  function doSomething() {
    $.ajax({
     type: "GET",
     url: `${URL}/${id}`,
     success: function (d, rc) { successf(d, rc); },
     error: function () { errorfn(); }
    });
      
    function successf(data, rc) {
      console.log(data);
      console.log(data.result_url);
      var answer = data.result_url;
      $("#them").html(`<video width="320" height="240" controls>
          <source src="https://d-id-clips-prod.s3.us-west-2.amazonaws.com/google-oauth2%7C116784674457195274488/clp_IP1QREPpXOIb-o_e0WlEQ/jack-KVaDW71ltd.mp4?AWSAccessKeyId=AKIA5CUMPJBIJ7CPKJNP&Expires=1701383475&Signature=RTKiDDFHNFr4nmYLpiYdCo05Xr0%3D&X-Amzn-Trace-Id=Root%3D1-6567bbb3-669de52435d74dec4b25c49c%3BParent%3D21c863575c2cc765%3BSampled%3D0%3BLineage%3D84e41ec0%3A0" type="video/mp4">
        </video>`);
    }
  }
}

function errorfn(e) {
    console.log(e);
  if (skyboxAPIKey == "") $("#them").html("<font color=red><b> Enter API key to be able to chat. </b></font>");
  else $("#them").html("<font color=red><b> Unknown error. </b></font>");
}