Skip to content

Instantly share code, notes, and snippets.

@jcpst
Last active August 9, 2018 02:17
Show Gist options
  • Save jcpst/6a1335220e3dbb272813113f882861a9 to your computer and use it in GitHub Desktop.
Save jcpst/6a1335220e3dbb272813113f882861a9 to your computer and use it in GitHub Desktop.
Chrome extension to get markdown from dokuwiki
{
"manifest_version": 2,
"name": "Doku-To-Markdown",
"description": "Convert Doku Page to markdown",
"version": "1.0",
"browser_action": {
"default_popup": "popup.html"
},
"permissions": [
"activeTab"
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="lib/turndown.js"></script>
<script src="popup.js"></script>
<title></title>
</head>
<body>
<textarea readonly cols="90" rows="30" id="output"></textarea>
</body>
</html>
chrome.tabs.getSelected(null, function (tab) {
var url = new URL(tab.url)
var dontRenderYet = false // gross. sorry.
if (!url.searchParams.has('do')) {
url.searchParams.append('do', 'export_xhtml')
dontRenderYet = true
}
chrome.tabs.query({ active: true, currentWindow: true }, function () {
chrome.tabs.update({ url: url.href }, function() {
if (dontRenderYet) {
document.getElementById('output').innerHTML = 'click TWO more times!'
return
}
chrome.tabs.executeScript({ code: 'document.body.innerHTML'},function (selection) {
var markdown = new TurndownService().turndown(selection[0])
document.getElementById('output').innerHTML = markdown
url.searchParams.delete('do')
chrome.tabs.query({ active: true, currentWindow: true }, function () {
chrome.tabs.update({ url: url.href })
})
})
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment