script_msg.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //jQuery time
  2. var current_fs, next_fs, previous_fs; //fieldsets
  3. var left, opacity, scale; //fieldset properties which we will animate
  4. var animating; //flag to prevent quick multi-click glitasdaches
  5. $(".gen_avatar").click(function(){
  6. imsrc = $('.img_src').val();
  7. srcObj = {'imgurl':imsrc}
  8. srcObjstr = JSON.stringify(srcObj);
  9. alert('生成中,請稍候 按下確認開始生成')
  10. $.ajax({
  11. url: 'http://www.choozmo.com:8888/swapFace',
  12. //url: 'http://www.choozmo.com:8888/qqreq',
  13. dataType : 'json', // 預期從server接收的資料型態
  14. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  15. type: 'post',
  16. data: srcObjstr,
  17. success: function(suc_data) {
  18. alert(suc_data.msg)
  19. },
  20. //data:JSON.stringify({n1:"12",n2:"22"}),
  21. error: function (error) {
  22. alert(error)
  23. }
  24. });
  25. });
  26. $(".next").click(function(){
  27. avatar = $('.avatar').val();
  28. name_title = $('.title_new').val();
  29. txtARR=[];
  30. imgARR=[];
  31. var step;
  32. for (step = 1; step <= 10; step++) {
  33. if($(".txtsrc"+step).val()!=""){
  34. txtARR.push($(".txtsrc"+step).val())
  35. }
  36. }
  37. var step2;
  38. for (step2 = 1; step2 <= 10; step2++) {
  39. if($(".imgsrc"+step2).val()!=""){
  40. imgARR.push($(".imgsrc"+step2).val())
  41. }
  42. }
  43. dataOBJ = {"name":name_title,"text_content":txtARR,"image_urls":imgARR,"avatar":avatar}
  44. objstr = JSON.stringify(dataOBJ);
  45. console.log(dataOBJ)
  46. $.ajax({
  47. url: 'http://www.choozmo.com:8888/make_anchor_video_v2',
  48. //url: 'http://www.choozmo.com:8888/qqreq',
  49. dataType : 'json', // 預期從server接收的資料型態
  50. contentType : 'application/json; charset=utf-8', // 要送到server的資料型態
  51. type: 'post',
  52. data: objstr,
  53. success: function(suc_data) {
  54. alert(suc_data.msg)
  55. },
  56. //data:JSON.stringify({n1:"12",n2:"22"}),
  57. error: function (error) {
  58. alert(error)
  59. }
  60. });
  61. });
  62. var loaded_data = ''
  63. function openNav() {
  64. document.getElementById("mySidenav").style.width = "250px";
  65. $.get("http://www.choozmo.com:8888/history_input", function(data, status){
  66. console.log(data)
  67. loaded_data = data
  68. for (var obj of data) {
  69. var sideBAR = document.getElementById('mySidenav')
  70. var message = document.createElement('a')
  71. var content = document.createTextNode(obj.name)
  72. message.id = obj.id
  73. message.setAttribute('href', "#")
  74. message.setAttribute('onclick', "load_data()")
  75. message.appendChild(content)
  76. sideBAR.appendChild(message)
  77. }
  78. });
  79. }
  80. function closeNav() {
  81. document.getElementById("mySidenav").style.width = "0";
  82. }
  83. function load_data(){
  84. var title = document.getElementById("title")
  85. tid = event.srcElement.id
  86. console.log(tid);
  87. $(".title_new").val(loaded_data.find(item => item.id == tid).name)
  88. var step;
  89. for (step = 1; step <= 10; step++) {
  90. $(".txtsrc"+step).val(loaded_data.find(item => item.id == tid).text_content[step-1])
  91. }
  92. var step2;
  93. for (step2 = 1; step2 <= 10; step2++) {
  94. $(".imgsrc"+step2).val(loaded_data.find(item => item.id == tid).image_urls[step2-1])
  95. }
  96. }
  97. var ws = new WebSocket('ws://www.choozmo.com:8888/progress');
  98. ws.onmessage = function(event) {
  99. console.log(event.data);
  100. var elem = document.getElementById("myBar");
  101. elem.style.width = event.data + "%";
  102. elem.innerHTML = event.data + "%";
  103. };
  104. function sendMessage(event) {
  105. var input = document.getElementById("messageText")
  106. ws.send(input.value)
  107. input.value = ''
  108. event.preventDefault()
  109. }