Skip to content

Instantly share code, notes, and snippets.

@R-omk
Created May 24, 2019 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save R-omk/0556f5c442b669e33a65add89f6afb13 to your computer and use it in GitHub Desktop.
Save R-omk/0556f5c442b669e33a65add89f6afb13 to your computer and use it in GitHub Desktop.
incognito external redirect
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
}
})
chrome.runtime.onMessage.addListener(({ action, url }) => {
if (action === 'CREATE_INCOGNITO_WINDOW') {
chrome.windows.create({
url,
incognito: true
})
}
})
{
"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