-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
13b16d5
commit 056c7ae
Showing
4 changed files
with
72 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* TODO: | ||
* FASTER check whitelisted URL | ||
*/ | ||
|
||
(() => { | ||
const aHandler = (node) => { | ||
const config = {subtree: false, childList: false, attributes: true}; | ||
|
||
const setTarget = (node) => { | ||
if (node.href.indexOf(window.location.href) !== 0) | ||
node.target = "_blank"; | ||
|
||
node.target = "_blank"; | ||
|
||
/* disabled for performance reason */ | ||
// browser.runtime.sendMessage({msg: "isWhitelisted", url: node.href}) | ||
// .then((response) => { | ||
// if (response.result === false) | ||
// node.target = "_blank"; | ||
// }) | ||
// .catch (() => node.target = "_blank"); | ||
}; | ||
|
||
const mutHandler = (mutations, observer) => { | ||
const a = mutations[0].target; | ||
observer.disconnect(); | ||
setTarget(a); | ||
observer.observe(a, config); | ||
}; | ||
|
||
setTarget(node); | ||
(new MutationObserver(mutHandler)).observe(node, config); | ||
}; | ||
|
||
const anchors = Array.from(document.getElementsByTagName("a")); | ||
anchors.forEach((a) => aHandler(a)); | ||
|
||
const documentObserver = new MutationObserver((mutations) => { | ||
mutations.forEach((m) => { | ||
const nodes = Array.from(m.addedNodes); | ||
nodes.forEach((n) => { | ||
if (n.nodeName === "A") | ||
aHandler(n); | ||
}); | ||
}); | ||
}); | ||
})(); |
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
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