Advertisement
Guest User

dccon-batch-uploader v.22.08.19

a guest
Aug 19th, 2022
1,234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /// 사용법 : https://m.dcinside.com/board/dccon/7557
  2. // https://m.dcinside.com/board/dccon/7180 (https://archive.ph/wip/3xPEU)
  3.  
  4. const useFilenameAsAlt = true;      // true = 알트값에 파일명을 넣음 , false = 알트값에 숫자를 넣음
  5.  
  6. $ = $;
  7.  
  8. function upload() {
  9.   var frm = $("#regist_form");
  10.   var img_name = $(this).attr("name");
  11.   frm.find("input[name=" + img_name + "]").attr("disabled", false);
  12.   target_name = img_name;
  13.   if (target_name != "main_img" && target_name != "list_img") {
  14.     org_icon_fname = $(this)
  15.       .val()
  16.       .replace(/^.*[\\\/]/, "");
  17.   }
  18.  
  19.   frm.prop({
  20.     action: now_protocal + "//upimg.dcinside.com/dccon_uploader.php",
  21.     method: "post",
  22.     target: "dccon_frame",
  23.   });
  24.   frm.find("input[name=process]").val("regist");
  25.   frm.find("input[name=target_name]").val(img_name);
  26.   frm.submit();
  27.   console.log("ok");
  28. }
  29.  
  30. function FileListItems(files) {
  31.   var b = new ClipboardEvent("").clipboardData || new DataTransfer();
  32.   for (var i = 0, len = files.length; i < len; i++) b.items.add(files[i]);
  33.   return b.files;
  34. }
  35.  
  36. function uploadprogress(i,t="",r="500") {
  37.     let diva    = document.createElement('div');
  38.     let divat   = document.createElement('div');
  39.     let divatp  = document.createElement('p');
  40.     document.body.appendChild(diva);
  41.     diva.appendChild(divat);
  42.     divat.appendChild(divatp);
  43.     diva.setAttribute('id', 'ncc');
  44.     diva.setAttribute('class', 'ncc');
  45.     diva.style.position         = 'fixed';
  46.     diva.style.width            = '100%';
  47.     diva.style.top              = '0px';
  48.     diva.style.left             = '0px';
  49.     diva.style.textAlign        = 'center';
  50.     i == 100
  51.         ? divatp.innerHTML = '<p>디시콘 <b>업로드</b>가 <b>완료</b>되었습니다</p>'
  52.         : divatp.innerHTML = '<p><b>' + i + '</b> 번째 디시콘이 업로드 중 입니다' + t + '</p>';
  53.     divat.setAttribute('class', 'notification-container');
  54.     divat.setAttribute('id', 'notification-container');
  55.     divat.style.background      = 'rgba(0,0,0,.3)';
  56.     divat.style.padding         = '15px 20px';
  57.     divat.style.transition      = 'transform 0.3s ease-in-out';
  58.     divat.style.textShadow      = '-1px 0 white, 0 1px white, 1px 0 white, 0 -1px white';
  59.     divat.style.borderRadius    = '0 0 10px 10px';
  60.     divat.style.zindex          = '9999999';
  61.     $("#diva").show();
  62.     setTimeout(function() {
  63.         document.body.removeChild(diva);
  64.     }, r);
  65. }
  66.  
  67. const readURL = (file) => {
  68.   return new Promise((res, rej) => {
  69.     const reader = new FileReader();
  70.     reader.onload = (e) => res(e.target.result);
  71.     reader.onerror = (e) => rej(e);
  72.     reader.readAsDataURL(file);
  73.   });
  74. };
  75.  
  76. const fileList = $("<input/>")
  77.   .attr("type", "file")
  78.   .attr("accept", "image/x-png,image/jpeg,image/gif")
  79.   .attr("multiple", true)
  80.   .bind("change", async function () {
  81.     files = this.files;
  82.     let list = $("<ul/>")
  83.       .css("width", "1000px")
  84.       .attr("id", "file-list")
  85.       .sortable();
  86.     for (const [i, file] of Object.entries(this.files)) {
  87.       list.append(
  88.         $("<img/>")
  89.           .attr("file-name", file.name)
  90.           .attr("src", await readURL(file))
  91.       );
  92.     }
  93.     $("header[class*='cont_head']").before(list);
  94.     $("ul[id*='file-list']")
  95.       .append(
  96.         $("<button/>")
  97.           .html("제출")
  98.           .attr("id", "batch-submit")
  99.           .attr("class", "btn_blue smaller")
  100.           .attr("style", "width:800px;height:100px;")
  101.           .bind("click", async function () {
  102.             const fileArray = Array.from(files);
  103.             $("html, body").animate({scrollTop: 586},400);
  104.             $("input[class*='dccon_num'][id='icon_cnt']").attr("value",fileArray.length);
  105.             $("button[id='btn_regist_icon']").trigger("click");
  106.             const fileNameList = Array.from(
  107.               $("#file-list > img").map(function () {
  108.                 return this.getAttribute("file-name");
  109.               })
  110.             );
  111.             const sortedArray = fileNameList.map(
  112.               (name) =>
  113.                 fileArray[fileArray.findIndex((file) => file.name === name)]
  114.             );
  115.             let formattedFileNameList = fileNameList.map((name) => {
  116.               name = name.substr(0, name.lastIndexOf("."));
  117.               const formatted = word_length(name, 6);
  118.               return formatted === true ? name : formatted;
  119.             });
  120.             let duplicantname = 0;
  121.             const unique = new Set(formattedFileNameList);
  122.             const duplicant = Array.from(
  123.               new Set(
  124.                 formattedFileNameList.filter((name) => !unique.delete(name))
  125.               )
  126.             );
  127.             formattedFileNameList = formattedFileNameList.reduce(
  128.               (list, name) => {
  129.                 if (duplicant.includes(name)) {
  130.                     duplicantname += 1;
  131.                     duplicantname.toString().length < 2 ? '0' + duplicantname : duplicantname;
  132.                 }
  133.                 list.push(
  134.                   duplicant.includes(name)
  135.                     ? `중복${duplicantname}`
  136.                     : name
  137.                 );
  138.                 return list;
  139.               },
  140.               []
  141.             );
  142.             let tp = 0;
  143.             for (var [i, file] of Object.entries(sortedArray)) {
  144.                 let tz = 500;
  145.                 let tt = ".";
  146.                 let ti = Number(i)+1;
  147.                 let ty = 11+(138*tp);
  148.                 let tc = 1;
  149.                 $(`div[class='scroll']`).animate({scrollTop : ty}, 400);
  150.                 console.log( " > " + $(`li[id='icon_${Number(i) + 1}'] > div[class='file_imgupbox empty']`).parent().attr("id") );
  151.                   //console.log("\n> " + $(`li[id='icon_${Number(i) + 1}'] > div[class='file_imgupbox empty']`).parent().attr("id"));
  152.                 var documentInput = $(`input[name='icon_${Number(i) + 1}']`);
  153.                 documentInput[0].files = new FileListItems([file]);
  154.                 upload.bind(documentInput)();
  155.                 $(`input[name="alt_${Number(i) + 1}"]`).attr(
  156.                     "value",
  157.                     useFilenameAsAlt ? formattedFileNameList[i] : Number(i) + 1
  158.                 );
  159.             do {
  160.                   uploadprogress(ti,tt,tz);
  161.                   await new Promise((resolve) => setTimeout(resolve, tz));
  162.                   tz += 250 + Math.floor(Math.random() * 251);
  163.                   tt += ".";
  164.                   tz > 5000 ? tz = 500 : tz;
  165.               } while ( $(`li[id="icon_${Number(i) + 1}"] > img[src*="dccon.php"]`).length == "0" );
  166.               ti % 5 === 0 ? tp += 1 : tp;
  167.             }
  168.             //$(`button[class*='submit']`).trigger("click");
  169.             alert("업로드 완료");
  170.             uploadprogress(100,"",3000);
  171.           })
  172.       )
  173.       .append(
  174.         $("<b/>")
  175.            .html("&nbsp;&nbsp;")
  176.       )
  177.       .append(
  178.         $("<button/>")
  179.           .html("초기화")
  180.           .attr("id", "batch-reset")
  181.           .attr("class", "btn_blue smaller")
  182.           .attr("style", "width:191px; height:100px;")
  183.           .bind("click", () => {
  184.             $("#batch-submit").remove();
  185.             $("#batch-reset").remove();
  186.             $("#file-list").remove();
  187.           })
  188.       );
  189.       $("html, body").animate({scrollLeft: 10000},400);
  190.       $("html, body").animate({scrollTop: 174},400);
  191.   })
  192.   .click();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement