forked from ariesdevil/markdown-clipper
-
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a base element to the DOM with current URL
This makes the DOM parse with a correct base URI instead of the extension's base URI, which fixes #1
- Loading branch information
Showing
2 changed files
with
24 additions
and
9 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
function notifyExtension() { | ||
//var serializer = new XMLSerializer(); | ||
//var content = serializer.serializeToString(document); | ||
// if the document doesn't have a "base" element make one | ||
// this allows the DOM parser in future steps to fix relative uris | ||
if (document.head.getElementsByTagName('base').length == 0) { | ||
let baseEl = document.createElement('base'); | ||
// use the current uri | ||
baseEl.setAttribute('href', window.location.href); | ||
document.head.append(baseEl); | ||
} | ||
|
||
// get the content of the page as a string | ||
var content = document.documentElement.outerHTML; | ||
browser.runtime.sendMessage({ type: "clip", dom: content, url:window.location.href}); | ||
|
||
// send a message that the content should be clipped | ||
browser.runtime.sendMessage({ type: "clip", dom: content}); | ||
} | ||
notifyExtension(); |