Last active
July 20, 2018 02:42
-
-
Save christianwish/27d997c92576d2b2204b9033e123b65d to your computer and use it in GitHub Desktop.
inject js by chrome extension
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": "inject script", | |
"description": "", | |
"version": "1.0", | |
"permissions": [ | |
"tabs", "http://*/*", "https://*/*" | |
], | |
"browser_action": { | |
"default_title": "Set this page's color.", | |
"default_icon": "icon.png", | |
"default_popup": "popup.html" | |
}, | |
"manifest_version": 2, | |
"web_accessible_resources": ["script.js"] | |
} |
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
<!doctype html> | |
<html> | |
<head> | |
<title>Set Page Color Popup</title> | |
<style> | |
body { | |
overflow: hidden; | |
margin: 0px; | |
padding: 0px; | |
background: white; | |
} | |
</style> | |
<script src="popup.js"></script> | |
</head> | |
<body> | |
<button id="inject">inject</button> | |
</body> | |
</html> |
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
// Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
// Use of this source code is governed by a BSD-style license that can be | |
// found in the LICENSE file. | |
function insert() { | |
chrome.tabs.query({ | |
active: true, | |
lastFocusedWindow: true | |
}, function(tabs) { | |
// and use that tab to fill in out title and url | |
var tab = tabs[0]; | |
chrome.tabs.executeScript(tab.ib, { | |
file: 'script.js' | |
}); | |
}); | |
} | |
function click(e) { | |
insert(); | |
} | |
document.addEventListener('DOMContentLoaded', function () { | |
var button = document.querySelectorAll('#inject'); | |
button.addEventListener('click', click); | |
}); |
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
(function() { | |
// just place a div at top right | |
var div = document.createElement('div'); | |
div.style.position = 'fixed'; | |
div.style.top = 0; | |
div.style.right = 0; | |
div.textContent = 'Injected!'; | |
document.body.appendChild(div); | |
alert('inserted self... giggity'); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment