mdict.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <!DOCTYPE html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="UTF-8">
  5. <base href="https://fastly.jsdelivr.net/gh/fengdh/mdict-js/">
  6. <title>mdict</title>
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <link rel="stylesheet" type="text/css" href="selectize.default.css" media="screen">
  9. <style>
  10. #btnLookup {
  11. border: none;
  12. height: 36px;
  13. font-size: 12pt;
  14. font-weight: bold;
  15. vertical-align: top;
  16. border-radius: 3px;
  17. }
  18. #btnLookup:not([disabled]) {
  19. background: #1A4FDD;
  20. color: white;
  21. }
  22. #dict-title {
  23. display:none;
  24. }
  25. #word + .selectize-control {
  26. display: inline-block;
  27. min-width: 18em;
  28. }
  29. </style>
  30. <script type="text/javascript" src="conf.js"></script>
  31. <script src="require.js" data-main="mdict"></script>
  32. </head>
  33. <body>
  34. Choose a dictionary file (*.mdx + optional *.mdd): <input id="dictfile" type="file" multiple>
  35. <p>
  36. <input id="word" type="text" value="">
  37. <input id="btnLookup" type="button" value="look up" disabled="false">
  38. <div id="dict-title"></div>
  39. <div id="definition">
  40. </div>
  41. <script>
  42. //?file=.../xx.xx,.../xx.xxx#word=
  43. var dictinput = document.getElementById('dictfile');
  44. var wordinput = document.getElementById('word');
  45. var btnLookup = document.getElementById('btnLookup');
  46. window.onhashchange = function() {
  47. let v = location.hash.substring(6);
  48. if(v.length>0){
  49. wordinput.value = v;
  50. //wordinput.dispatchEvent(new Event('change', {'bubbles': true}));
  51. btnLookup.click();
  52. }
  53. };
  54. {
  55. let v = decodeURIComponent(location.hash.substring(6));
  56. wordinput.value = v;
  57. }
  58. {
  59. let filenames = location.search.substring(6);
  60. window.onload = function(){
  61. if(filenames.length>0){
  62. let clickurl = "i:5fdictinput.click():"+filenames;
  63. location.href=clickurl;
  64. //setTimeout(()=>{dictinput.dispatchEvent(new Event('change', {'bubbles': true}));},100);
  65. var callbackTimer = setInterval(function() {
  66. let files = dictinput.files;
  67. if(files.length>0){
  68. if(!btnLookup.disabled){
  69. clearInterval(callbackTimer);
  70. return;
  71. }
  72. }else
  73. location.href=clickurl;
  74. dictinput.dispatchEvent(new Event('change', {'bubbles': true}));
  75. }, 100);
  76. }
  77. };
  78. }
  79. </script>
  80. </body>
  81. </html>