script_util2.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. const urlSearchParams = new URLSearchParams(window.location.search);
  2. const params = Object.fromEntries(urlSearchParams.entries());
  3. name_hash = params['id']
  4. dataArr=''
  5. function get_script() {
  6. var url = "uploadmp3";
  7. var xhr = new XMLHttpRequest();
  8. xhr.open("POST", url);
  9. xhr.setRequestHeader("accept", "application/json");
  10. xhr.setRequestHeader("Content-Type", "application/json");
  11. xhr.onreadystatechange = function () {
  12. if (xhr.readyState === 4) {
  13. console.log(xhr.status);
  14. console.log(xhr.responseText);
  15. dataArr = xhr.responseText.split(',');
  16. }};
  17. var data = `{"name_hash": `+name_hash+`}`;
  18. xhr.send(data);
  19. }
  20. get_script();
  21. var srcInput = document.querySelector(".msrcParent");
  22. for (step = 0; step < dataArr.length; step++) {
  23. console.log(dataArr[step])
  24. var pdiv = document.createElement('div');
  25. pdiv.classList.add('subtitle-inputs')
  26. var rawSrc = document.createElement("input");
  27. rawSrc.setAttribute('type', 'text');
  28. rawSrc.value = dataArr[step];
  29. rawSrc.style.width = "47%";
  30. var mSrc = document.createElement("input");
  31. mSrc.setAttribute('type', 'text');
  32. mSrc.setAttribute('id', `s${step }`);
  33. mSrc.style.width = "47%";
  34. pdiv.appendChild(rawSrc)
  35. pdiv.appendChild(mSrc)
  36. srcInput.appendChild(pdiv)
  37. }
  38. $(".confirmbtn" ).click(function() {
  39. for (i = 0; i < dataArr.length; i++) {
  40. if ($(`#s${i }`).val()!=''){
  41. dataArr[i]=$(`#s${i }`).val();
  42. }
  43. }
  44. sendString = dataArr.join(',');
  45. var url = "http://www.choozmo.com:8889/updateScript";
  46. var xhr = new XMLHttpRequest();
  47. xhr.open("POST", url);
  48. xhr.setRequestHeader("accept", "application/json");
  49. xhr.setRequestHeader("Content-Type", "application/json");
  50. xhr.onreadystatechange = function () {
  51. if (xhr.readyState === 4) {
  52. console.log(xhr.status);
  53. console.log(xhr.responseText);
  54. alert('請等待line通知');
  55. }};
  56. var data = `{"name_hash":`+name_hash+ `,"scriptStr": `+sendString+`}`;
  57. xhr.send(data);
  58. });