<script src="//ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<script language="JavaScript" src="https://pulipulichen.github.io/blogger/posts/2016/20160420-youdo/tongwen_core.js"></script>
<script language="JavaScript" src="https://pulipulichen.github.io/blogger/posts/2016/20160420-youdo/tongwen_table_s2t.js"></script>
<script language="JavaScript" src="https://pulipulichen.github.io/blogger/posts/2016/20160420-youdo/tongwen_table_ps2t.js"></script>
<form onsubmit="return false;">
  <label class="youdoict20160420_input_label">
    Upload Youdo Dict XML:   
  <input id="youdoict20160420_input" type="file" name="youdoict20160420_input" /> </label>
  <div class="youdoict20160420_output_label" style="display: none">
    <div style="text-align:center;">Select full content to import to<a href="https://quizlet.com/" target="quizlet">Quizlet</a>:</div> <textarea onclick="this.select()" class="youdoict20160420_output" style="height: 30em; width: 90%; display: block;margin: 0 auto;"></textarea> <input class="youdoict20160420_filename" type="hidden" />
    <button class="youdoict20160420_reset" type="reset">RESET</button> </div>

  <label style="display:block;text-align:center;font-size:20pt">
    <input type="checkbox" class="youdoict20160420_filename_s2t" checked="checked" style="font-size:20pt" />
    Convert Simplified to Traditional Chinese (<a href="https://siongui.github.io/2012/10/03/javascript-conversion-of-traditional-and-simplified-chinese/" target="ntsc">New Tong Wen Tang</a>)
  </label>
</form>
form {
  font-size: 20pt;
  /*
  border-top: #ce8a42 2px solid;
  border-right: #ce8a42 2px solid;
  border-bottom: #ce8a42 2px solid;
  border-left: #ce8a42 2px solid;
  */
  margin: 10px;
  
  text-align: center;
}

input#youdoict20160420_input, .youdoict20160420_reset {
  font-size: 20pt;
  display: inline-block;
  text-align: center;
  /*border:1px solid red;*/
}
var _youdoict20160420_handleFileSelect = function(evt) {
  var files = evt.target.files; // FileList object

  // Loop through the FileList and render image files as thumbnails.
  for (var i = 0, f; f = files[i]; i++) {

    $(".youdoict20160420_filename").val(f.name);

    var reader = new FileReader();

    // Closure to capture the file information.
    reader.onload = (function(theFile) {
      return function(e) {
        var _input = e.target.result;
        var _output = _scantailor20150710SetFullContent(_input);
        $(".youdoict20160420_output").val(_output);
        $(".youdoict20160420_input_label").hide();
        $(".youdoict20160420_output_label").show();
        //$(".youdoict20160420_download").click();
      };
    })(f);

    // Read in the image file as a data URL.
    reader.readAsText(f);
  }
};

setTimeout(function() {
  document.getElementById('youdoict20160420_input').addEventListener('change', _youdoict20160420_handleFileSelect, false);
  $(".youdoict20160420_reset").click(function() {
    $(".youdoict20160420_output_label").hide();
    $(".youdoict20160420_input_label").show();
  });

  $(".youdoict20160420_download").click(function() {
    var _text = $(".youdoict20160420_output").val();
    var _filename = $(".youdoict20160420_filename").val();

    //_youdoict20160420_download(_filename, _text);
  });
}, 500);

// var _youdoict20160420_download = function(filename, text) {
//   var element = document.createElement('a');
//   element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
//   element.setAttribute('download', filename);

//   element.style.display = 'none';
//   document.body.appendChild(element);

//   element.click();

//   document.body.removeChild(element);
// }

var _scantailor20150710SetFullContent = function(_input) {

  var _xml = $($.parseXML(_input));

  return _youdoict20160420_convertXMLtoString(_xml);
};

var _youdoict20160420_convertXMLtoString = function(_xml) {
  // var _xmlString;
  // if (window.ActiveXObject) {
  //   _xmlString = _xml.xml;
  // } else {
  //   var _oSerializer = new XMLSerializer();
  //   _xmlString = _oSerializer.serializeToString(_xml[0]);
  // }
  var _lines = [];
  _xml.find("item").each(function(_index, _item) {
    var _item = $(_item);
    var _word = _item.find("word").text();
    var _trans = _item.find("trans").text();
    _trans = _trans.replace(/(?:\r\n|\r|\n)/g, ' ');
   
    if ($(".youdoict20160420_filename_s2t:checked").length > 0) {
    _trans = TongWen.convert(_trans, TongWen.flagTrad);
    }
    _lines.push(_word + "\t" + _trans);
  });

  var _xmlString = _lines.join("\n");

  return _xmlString;
};

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.