max-width: 300px;
display: block;
}
+dd input ~ button {
+ margin-left: -5em;
+}
</style>
+
+<script>
+document.addEventListener('DOMContentLoaded', () => {
+ var wpinput = document.getElementById('wptitle');
+ var wpbutton = wpinput.parentNode.appendChild(document.createElement('button'));
+ wpbutton.type = 'button';
+ wpbutton.append('Copy');
+ wpbutton.onclick = () => {
+ let wptitle = wpinput.value || document.getElementById('form').value;
+ let wppage = 'https://en.wikipedia.org/w/api.php?action=parse&format=json&origin=*&prop=text&page='+wptitle;
+ fetch(wppage).then(res => res.json()).then(json => {
+ if (json.error) throw `error returned: ${json.error.info}`;
+ wpinput.value = json.parse.title;
+ let imginput = document.getElementById('source');
+ if (imginput.value) return;
+ let wpimages = json.parse.text['*'].match(/<img\s[^>]+/g);
+ imginput.value = wpimages[0].match(/\ssrc="([^"]+)"/)[1]
+ .replace(/^(?=\/\/)/, 'https:')
+ .replace(/\/thumb(\/.+)\/[^\/]+$/, '$1');
+ }).catch(error => alert(error));
+ return false;
+ };
+});
+</script>
EOT
});
my @wordcols = (
form => 'Translation',
+ wptitle => 'Wikipedia',
ref => 'Reference',
cat => 'Category',
lang => 'Language',
source => 'Image URL',
thumb => 'Convert options',
- wptitle => 'Wikipedia',
);
my ($find) = map {{id => $_}} $fields{id} || $Request || ();