Last active
May 11, 2021 21:25
-
-
Save kmclaugh/8d71014b14f33c5035fae86328374969 to your computer and use it in GitHub Desktop.
Replacement for Chrome Extension's Inline-Install
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
var appDomainURL = "*://app.owlandscroll.com/*"; | |
var appDomainURLCononical = "https://app.owlandscroll.com"; | |
const makeAppActive = () => { | |
chrome.tabs.query({ url: config.appDomainURL }, tabs => { | |
if (tabs.length) { | |
var tab = tabs[0]; | |
chrome.tabs.sendMessage(tab.id, { sendingUserToApp: true }, function( | |
response | |
) { | |
console.log(response); | |
}); | |
chrome.tabs.update(tab.id, { selected: true }); | |
} else { | |
chrome.tabs.create({ url: appDomainURLCononical }); | |
} | |
}); | |
}; | |
/* | |
* Inject content scripts when the user installs the extension so the user doensn't have to refresh the page | |
*/ | |
chrome.runtime.onInstalled.addListener(function() { | |
//Get content scripts from manifest | |
chrome.manifest = chrome.app.getDetails(); | |
var scripts = chrome.manifest.content_scripts; | |
var appTab; | |
// Loop through all tabs of all windows... | |
chrome.windows.getAll({ populate: true }, function(windows) { | |
windows.map(function(window) { | |
window.tabs.map(function(tab) { | |
// ...loop through all content scripts urls matches... | |
scripts.map(function(script) { | |
script.matches.map(function(scriptUrl) { | |
// ...if the tab url matches a content script url... | |
if (tab.url.match(scriptUrl)) { | |
// ...inject all javasScripts from the content script into the tab... | |
if (script.js) { | |
script.js.map(function(javasScript) { | |
chrome.tabs.executeScript(tab.id, { file: javasScript }); | |
}); | |
} | |
// ...inject all css from the content script into the tab | |
if (script.css) { | |
script.css.map(function(css) { | |
chrome.tabs.insertCSS(tab.id, { file: css }); | |
}); | |
} | |
} | |
}); | |
}); | |
}); | |
}); | |
}); | |
makeAppActive(); | |
console.log("Extension and content scripts installed"); | |
}); |
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
/* content_scripts portion of our manifest.js */ | |
"content_scripts": [ | |
{ | |
"matches": ["https://read.amazon.com/notebook*", "https://read.amazon.com/kp/notebook*"], | |
"css": ["styles.css"], | |
"js": [ | |
"libs/jquery-3.3.1.min.js", | |
"parser.js", | |
"insertionMarkup.js", | |
"index.js" | |
], | |
"run_at": "document_end" | |
}, | |
{ | |
"matches": ["https://app.owlandscroll.com/*", "https://dev.owlandscroll.com/*" ], | |
"js": [ | |
"config.js", | |
"appMessages.js" | |
], | |
"run_at": "document_end" | |
} | |
] |
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
<a target="_blank" rel="noopener noreferrer" href="https://chrome.google.com/webstore/detail/ehncpahhfadkdfneafgehhdfjfiddpje"> | |
Install Extension | |
</a> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment