3
我正在尋找一種將我的選定文本添加到我的Chrome擴展中的框架/邊框(如Evernote Web Clipper:下圖)。Chrome擴展選定的文本
爲了做到這一點,我想捕捉選擇的HTML代碼,並添加當前選定的文本週圍的框架/邊框。但我不知道怎樣才能做到這一點...
這裏是我的代碼:
manifest.json的:
{
"name": "Selected Text",
"version": "0.1",
"description": "Selected Text",
"manifest_version": 2,
"browser_action": {
"default_title": "Selected Text",
"default_icon": "online.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs",
"<all_urls>"
],
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["popup.js"]
}
]
}
popup.js:
chrome.tabs.executeScript({
code: "window.getSelection().toString();"
}, function(selection) {
console.log(selection[0]);
if(selection[0].length > 0){
document.getElementById("text").value = selection[0];
}
});
彈出.html:
<!DOCTYPE html>
<html>
<head>
<script src="popup.js"></script>
<style>
body { width: 300px; }
textarea { width: 250px; height: 100px;}
</style>
</head>
<body>
<textarea id="text"> </textarea>
</body>
</html>
popup.html中文本區域的用法是什麼? – sabithpocker
@sabithpocker這只是一個臨時預覽。 – Steve23