Skip to content

Commit

Permalink
add history 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
madneal committed Oct 23, 2017
1 parent 8f32843 commit d2e5d17
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions scripts/widget.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
let mainDiv = document.querySelector('.main')
const loadIcon = document.querySelector('.load')
const exportBtn = document.querySelector('.export')
const sourceDiv = document.querySelector('#source')
const MEDIUM_IMG_CDN = 'https://cdn-images-1.medium.com/max/'

document.querySelector('.export').addEventListener('click', function () {
if (sourceDiv.style.display === 'none') {
sourceDiv.style.display = 'block'
}
createLoadForm()
loadIcon.style.visibility = 'visible'
exportMedium()
Expand All @@ -14,6 +18,10 @@ document.querySelector('.copy').addEventListener('click', function () {
copyToClipboard(value);
})

document.querySelector('.history').addEventListener('click', function() {
displayHistory()
})

function createLoadForm() {
let shadow = document.createElement('div')
shadow.id = 'shadow'
Expand Down Expand Up @@ -42,7 +50,7 @@ function exportMedium() {
})
.then(function (text) {
const story = parseJsonToMarkdown(text)
saveHistory(story.title)
saveHistory(story.title, activeTab.url)
const markdownText = story.markdown.join('')
cancelLoad()
document.querySelector('#source').value = markdownText;
Expand All @@ -58,6 +66,18 @@ function saveHistory(title, url) {
localStorage.setItem(title, url);
}

function displayHistory() {
let list = ''
for (const ele in localStorage) {
const title = ele
const url = localStorage.getItem(title)
const str = '* [' + title + '](' + url + ')\n'
list = list + str
}
document.querySelector('.right-area').innerHTML = snarkdown(list)
sourceDiv.style.display = 'none'
}

function parseJsonToMarkdown(jsonStr) {
// cut the useless string to format json string
const str = jsonStr.substring(16, jsonStr.length)
Expand Down Expand Up @@ -195,7 +215,6 @@ function processMarkupSpace(tokens) {
if (ele === '**' || ele === '*' || ele === '[' || ele === ']') {
times = times + 1;
if (times % 2 === 1 && tokens[i + 1] && tokens[i + 1][0] === ' ') {
console.log(tokens[i + 1]);
tokens[i + 1] = tokens[i + 1].substring(1);
tokens[i - 1] = tokens[i - 1] + ' '
i = i + 1;
Expand Down

0 comments on commit d2e5d17

Please sign in to comment.