Skip to content

Instantly share code, notes, and snippets.

@jkaipr
jkaipr / foreground.js
Created December 21, 2021 10:03
Spyder - Chrome extension listening to page loading and user input events
// This script gets injected into any opened page
// whose URL matches the pattern defined in the manifest
// (see "content_script" key).
// Several foreground scripts can be declared
// and injected into the same or different pages.
const sendMessageToBackground = (message) => {
chrome.runtime.sendMessage({ message });
}

Keybase proof

I hereby claim:

  • I am jkaipr on github.
  • I am jiri_rf (https://keybase.io/jiri_rf) on keybase.
  • I have a public key ASAb4oVT8WIYhVSc0eDFwTdphtDux3soUfUaMJDzwCV4jwo

To claim this, I am signing this object:

@jkaipr
jkaipr / appendScriptTagsToPage.js
Created March 29, 2019 12:52
Adding script tags fetched from backend to page
function appendScriptTags(htmlString, target) {
const scriptSrcRegexp = /<script src="([^\s]*)"/g;
let match = scriptSrcRegexp.exec(htmlString);
while (match != null) {
const matchedSrc = match[1];
const authScriptTag = document.createElement("script");
authScriptTag.src = matchedSrc;
authScriptTag.async = true;
authScriptTag.defer = true;