Skip to content

Commit

Permalink
Fixed: cant serialize some sites, now it works on more (heise tested)
Browse files Browse the repository at this point in the history
  • Loading branch information
enrico-kaack committed Jan 4, 2019
1 parent c0470a1 commit 67b626d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
17 changes: 14 additions & 3 deletions background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,34 @@ function convertArticleToMarkdown(article) {
return markdown;
}

function generateValidFileName(title) {
//remove < > : " / \ | ? *
console.log(title);
var illegalRe = /[\/\?<>\\:\*\|":]/g;
var name = title.replace(illegalRe, "");
console.log(name);
return name;
}

function downloadMarkdown(markdown, article) {
var blob = new Blob([markdown], {
type: "text/markdown;charset=utf-8"
});
var url = URL.createObjectURL(blob);
browser.downloads.download({
url: url,
filename: article.title + ".md",
filename: generateValidFileName(article.title) + ".md",
incognito: true,
saveAs: true
});
}

function notify(message) {


function notify(message) {
console.log(message);
var parser = new DOMParser();
var dom = parser.parseFromString(message.dom, "application/xml");
var dom = parser.parseFromString(message.dom, "text/html");
console.log(dom.documentElement.nodeName == "parsererror" ? "error while parsing" : dom.documentElement.nodeName);

var article = createReadableVersion(dom);
Expand Down
5 changes: 3 additions & 2 deletions contentScript/pageScrapper.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function notifyExtension() {
var serializer = new XMLSerializer();
var content = serializer.serializeToString(document);
//var serializer = new XMLSerializer();
//var content = serializer.serializeToString(document);
var content = document.documentElement.outerHTML;
browser.runtime.sendMessage({"dom": content});
}
notifyExtension();

0 comments on commit 67b626d

Please sign in to comment.