Created
July 2, 2015 03:35
-
-
Save tmplinshi/89193e4cc48a7c7ceb94 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| { | |
| "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 | |
| } |
This file contains hidden or 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
| 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