Created
May 24, 2019 08:55
-
-
Save R-omk/0556f5c442b669e33a65add89f6afb13 to your computer and use it in GitHub Desktop.
incognito external redirect
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
const getLink = node => { | |
if (!node) { | |
return undefined | |
} | |
return node.href ? node : getLink(node.parentNode) | |
} | |
const onClick = e => { | |
const link = getLink(e.target) | |
if (!link) { | |
return | |
} | |
e.preventDefault() | |
chrome.runtime.sendMessage({ | |
action: 'CREATE_INCOGNITO_WINDOW', | |
url: link.href | |
}) | |
} | |
document.addEventListener('DOMContentLoaded', () => { | |
if (document.location.href.indexOf('/external_redirect') == -1) { | |
return | |
} | |
var element = document.querySelectorAll(".block-external-redirect a"); | |
if (element[0]) { | |
element[0].onclick = onClick | |
} | |
}) |
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.runtime.onMessage.addListener(({ action, url }) => { | |
if (action === 'CREATE_INCOGNITO_WINDOW') { | |
chrome.windows.create({ | |
url, | |
incognito: true | |
}) | |
} | |
}) |
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
{ | |
"name": "incognito external redirect", | |
"description": "Open a link in Incognito mode from external redirect page", | |
"manifest_version": 2, | |
"version": "0.0.2", | |
"background": { | |
"scripts": [ | |
"background.js" | |
] | |
}, | |
"content_scripts": [ | |
{ | |
"matches": [ | |
"<all_urls>" | |
], | |
"js": [ | |
"app.js" | |
], | |
"run_at": "document_start" | |
} | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment