keys: wide padded key style on windows >1440x996 px
[sheet.git] / writer.js
index a958732274c5e43ecff87c2fe8c95ff16428a54a..da403b2217ad31c75178ea6cb1cc958cf7f2d1f1 100644 (file)
--- a/writer.js
+++ b/writer.js
@@ -2,6 +2,7 @@ document.addEventListener('DOMContentLoaded', () => {
        document.querySelectorAll('.multiinput > input[id]').forEach(el => {
                el.oninput = e => {
                        if (e.target.value == '') return;
+                       // insert another empty input element option
                        let add = e.target.cloneNode(true);
                        add.value = '';
                        add.oninput = e.target.oninput;
@@ -26,6 +27,13 @@ document.addEventListener('DOMContentLoaded', () => {
                                if (json.error) throw `error returned: ${json.error.info}`;
                                wpinput.value = json.parse.title;
 
+                               let wptext = json.parse.text['*'];
+                               let transrow = document.getElementById('trans-la');
+                               if (transrow && !transrow.value && wptext) {
+                                       const binom = wptext.match(/ class="binomial">.*?<i>(.*?)<\/i>/);
+                                       transrow.value = binom[1]
+                               }
+
                                // translations from language links
                                let wplangs = json.parse.langlinks;
                                if (wplangs) wplangs.forEach(wptrans => {
@@ -37,10 +45,9 @@ document.addEventListener('DOMContentLoaded', () => {
                                });
 
                                // copy first paragraph to story
-                               let wptext = json.parse.text['*'];
                                let storyinput = document.getElementById('story');
-                               if (storyinput && wptext) {
-                                       storyinput.innerHTML = wptext
+                               if (storyinput && !storyinput.value && wptext) {
+                                       storyinput.value = wptext
                                                .replace(/<h2.*/s, '') // prefix
                                                .replace(/<table.*?<\/table>/sg, '') // ignore infobox
                                                .match(/<p>(.*?)<\/p>/s)[0] // first paragraph
@@ -95,6 +102,29 @@ document.addEventListener('DOMContentLoaded', () => {
                };
        }
 
+       let thumbpreview = document.getElementById('convertpreview');
+       if (thumbpreview && imgpreview) {
+               thumbpreview.onclick = e => {
+                       let imgselect = imgpreview; /* TODO clone */
+                       imgselect.hidden = false;
+                       imgselect.classList.add('popup');
+                       imgselect.onmousemove = e => {
+                               let border = imgselect.getBoundingClientRect();
+                               let pos = [
+                                       Math.round(1000 * (e.clientX - border.x) / border.width),
+                                       Math.round(1000 * (e.clientY - border.y) / border.height)
+                               ];
+                               return pos;
+                       };
+                       imgselect.onclick = e => {
+                               let imgoption = document.getElementById('convert');
+                               imgoption.value += (imgoption.value && '-') + imgselect.onmousemove(e);
+                               imgselect.hidden = true;
+                               imgselect.classList.remove('popup');
+                       };
+               };
+       }
+
        let translist = document.getElementById('trans');
        if (translist) {
                let langoptions = Array.prototype.filter.call(document.getElementById('lang').options, opt => {