+ raw => <<'EOT',
+<style>
+dd > input {
+ width: 32em;
+ max-width: 100%;
+ padding: 1ex;
+ font-family: monospace;
+}
+dl > dt, dl > dd {
+ float: none;
+ display: inline-block;
+ box-sizing: border-box;
+ width: 50%;
+ margin: 0;
+ line-height: 4ex;
+ vertical-align: text-top;
+}
+dd > img {
+ max-width: 300px;
+ display: block;
+}
+dd input ~ button {
+ margin-left: -5em;
+}
+
+ul.popup {
+ display: flex;
+ flex-wrap: wrap;
+ align-items: end;
+ position: fixed;
+ left: 0;
+ top: 0;
+ margin: auto;
+ max-height: 90%;
+ max-width: 90%;
+ overflow: auto;
+ background: rgba(0, 0, 0, .8);
+ border: 1px solid #CCC;
+}
+
+section {
+ position: absolute;
+ top: 7ex;
+ right: 1em;
+}
+section > ul {
+ margin-top: 1ex;
+}
+section > ul strong, section form {
+ line-height: 2;
+}
+</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);
+ let wpselect = wpinput.parentNode.appendChild(document.createElement('ul'));
+ wpselect.className = 'popup';
+ wpimages.forEach(img => {
+ let selectitem = wpselect.appendChild(document.createElement('li'));
+ selectitem.insertAdjacentHTML('beforeend', img);
+ selectitem.onclick = e => {
+ let imgsrc = e.target.src
+ .replace(/^(?=\/\/)/, 'https:')
+ .replace(/\/thumb(\/.+)\/[^\/]+$/, '$1');
+ imginput.value = imgsrc;
+ wpselect.remove();
+ return false;
+ };
+ });
+ }).catch(error => alert(error));
+ return false;
+ };
+});
+</script>
+EOT