function addNotification(msg, className='is-warning') { var n = document.createElement('div') n.classList.add('notification') n.classList.add(className) n.innerHTML = msg document.getElementById('notifications').appendChild(n) } function mediumFetch(e) { if(e) { e.preventDefault() } const postSlug = document.querySelector('[data-post-slug]').dataset.postSlug const mediumUrl = document.querySelector('[data-post-mediumurl]').dataset.postMediumurl console.log('Fetching ' + postSlug) const socketProtocol = (window.location.protocol === 'https:' ? 'wss:' : 'ws:') const socketUrl = socketProtocol + '//' + window.location.host + '/ws/fetch-medium/' const socket = new WebSocket(socketUrl) // set up the div statusDiv = document.getElementById('statusbar') statusText = document.createElement('p') statusText.innerText = 'Fetching post' statusText.classList.add('card-footer-item') // hide buttons for (i=0;i { socket.send('fetch ' + postSlug + ' ' + mediumUrl) } socket.onmessage = m => { console.log('Got message: ' + m.data) console.log(m.data) if (m.data.indexOf(': ') != -1) { var command = m.data.slice(0, m.data.indexOf(': ')) var commandData = m.data.slice(m.data.indexOf(': ')+2) statusText.innerHTML = `${command}: ${commandData}` // if it's done, clean up if (command == 'done') { // remove statusbar statusDiv.removeChild(statusText) // show alert addNotification(`${postSlug} has been fetched successfully. You can now push it to Ghost`, 'is-success') // show buttons, change text and save slug for (i=0;i { socket.send('push ' + postSlug) } socket.onmessage = m => { console.log('Got message: ' + m.data) console.log(m.data) if (m.data.indexOf(': ') != -1) { var command = m.data.slice(0, m.data.indexOf(': ')) var commandData = m.data.slice(m.data.indexOf(': ')+2) statusText.innerHTML = `${command}: ${commandData}` // if it's done, clean up if (command[0] == 'done') { // remove statusbar statusDiv.removeChild(statusText) // show alert addNotification(`${postSlug} has been pushed to Ghost`, 'is-success') // show buttons and change text for (i=0;i