Skip to content

Instantly share code, notes, and snippets.

@tmplinshi
Created July 2, 2015 03:35
Show Gist options
  • Select an option

  • Save tmplinshi/89193e4cc48a7c7ceb94 to your computer and use it in GitHub Desktop.

Select an option

Save tmplinshi/89193e4cc48a7c7ceb94 to your computer and use it in GitHub Desktop.
{
"description" : "test description",
"name" : "test name",
"version" : "1.0",
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["myscript.js"],
"run_at": "document_end"
}
],
"permissions": ["clipboardWrite"],
"browser_action": {
"default_title": "test title",
"default_icon": "test-0.png"
},
"manifest_version": 2
}
chrome.extension.sendMessage({}, function(response) {
var readyStateCheckInterval = setInterval(function() {
if (document.readyState === "complete") {
clearInterval(readyStateCheckInterval);
// ----------------------------------------------------------
// This part of the script triggers when page is done loading
console.log("Hello. This message was sent from scripts/inject.js");
alert('complete');
copyTextToClipboard( document.body.innerHTML );
// ----------------------------------------------------------
}
}, 10);
});
// 需要在 manifest.json 中设置 clipboardWrite 权限
function copyTextToClipboard(text) {
var copyFrom = document.createElement("textarea");
copyFrom.textContent = text;
var body = document.getElementsByTagName('body')[0];
body.appendChild(copyFrom);
copyFrom.select();
document.execCommand('copy');
body.removeChild(copyFrom);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment