- let wpimages = json.parse.text['*'].match(/<img\s[^>]+/g);
- imginput.value = wpimages[0].match(/\ssrc="([^"]+)"/)[1]
- .replace(/^(?=\/\/)/, 'https:')
- .replace(/\/thumb(\/.+)\/[^\/]+$/, '$1');
+ 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;
+ };
+ });