Last active
August 9, 2018 02:17
-
-
Save jcpst/6a1335220e3dbb272813113f882861a9 to your computer and use it in GitHub Desktop.
Chrome extension to get markdown from dokuwiki
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"manifest_version": 2, | |
"name": "Doku-To-Markdown", | |
"description": "Convert Doku Page to markdown", | |
"version": "1.0", | |
"browser_action": { | |
"default_popup": "popup.html" | |
}, | |
"permissions": [ | |
"activeTab" | |
] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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