Skip to content

Instantly share code, notes, and snippets.

@eluttner
Created November 24, 2017 21:14
Show Gist options
  • Save eluttner/6d836ddf4f6e9ac562d9ceedf43d56e4 to your computer and use it in GitHub Desktop.
Save eluttner/6d836ddf4f6e9ac562d9ceedf43d56e4 to your computer and use it in GitHub Desktop.
chrome-read-page-extension
  1. when on toptal page
  2. click on the extension
  3. click on the button load data (can be onload for now)
  4. fill the form with data from the page
chrome.runtime.sendMessage("nkohjkjhdcoklcopgnefoopkpggbmgcj", {data: "hello"},
function(response) {
console.log("RESPONSE");
console.log(response);
});
{
"manifest_version": 2,
"name": "Test",
"description": "read page data",
"version": "1.1",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["*://*.toptal.com/*"],
"js": ["contentscript.js"]
}
],
"externally_connectable": {
"matches": ["*://*.toptal.com/*"]
},
"permissions": [
"activeTab",
"identity",
"tabs"
]
}
<!doctype html>
<html>
<head>
<title>read page</title>
<style type="text/css">
body {
margin: 10px;
padding: 10px;
white-space: nowrap;
width: 250px;
height: 400px;
}
h1 {
font-size: 15px;
}
#container {
align-items: center;
justify-content: space-between;
}
.column {
float: left;
width: 50%;
}
/* Clear floats after the columns */
.row:after {
content: "";
display: table;
clear: both;
}
</style>
<script src="popup.js"></script>
</head>
<body>
<h1>Read Page</h1>
<input class="row" type="button" id="pull-data" value="Pull data"/>
<hr/>
<div id="container" class="column">
<span class="row">text</span>
<input class="row" type="text" id="text-from-page" />
</div>
</body>
</html>
console.log("ABCD");
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(request)
console.log(sender)
});
document.addEventListener('DOMContentLoaded', function () {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var current = tabs[0];
url = current.url;
console.log(url);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment