Skip to content

Instantly share code, notes, and snippets.

@n0mimono
Created August 8, 2024 09:50
Show Gist options
  • Save n0mimono/3728319586956e63505abb172c148de6 to your computer and use it in GitHub Desktop.
Save n0mimono/3728319586956e63505abb172c148de6 to your computer and use it in GitHub Desktop.
Script Injection
const _addEventListener = addEventListener
EventTarget.prototype.addEventListener = function (type, listener) {
switch (type) {
case 'visibilitychange':
_addEventListener.apply(this, [
type,
() => console.log(`${type} is disabled`)
])
break
default:
console.log(`${type} is enabled`)
_addEventListener.apply(this, arguments)
break
}
}
// inject script
const script = document.createElement("script");
script.src = chrome.runtime.getURL("js/content.js");
(document.head || document.documentElement).insertAdjacentElement('afterbegin', script)
{
"name": "__MSG_appName__",
"version": "0.1",
"manifest_version": 3,
"description": "__MSG_appDesc__",
"default_locale": "ja",
"icons": {
"128": "img/icon_128.png"
},
"content_scripts": [
{
"matches": [
"https://google.com/*"
],
"js": [
"js/main.js"
],
"run_at": "document_start"
}
],
"web_accessible_resources": [
{
"resources": [
"js/*"
],
"matches": [
"<all_urls>"
]
}
],
"offline_enabled": true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment