我感觉我遗漏了一些非常明显的东西,但我一直在到处寻找,似乎无法完成这项工作。简而言之,我想把一个小的 Javascript 脚本变成一个 chrome 扩展,让它更容易使用。
该脚本只是从 textArea 读取文本,修改脚本并将其输出到 div 中。它在独立运行时可以与任何浏览器完美配合,但在作为 Chrome 扩展程序运行时似乎不想工作
这是文件(我基本上是在尝试转换示例):
谢谢!
清单.json
{
"manifest_version": 2,
"name": "One-click Kittens",
"description": "This extension demonstrates a 'browser action' with kittens.",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"https://secure.flickr.com/"
]
}
popup.html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<style>
body {
min-width: 357px;
overflow-x: hidden;
}
img {
margin: 5px;
border: 2px solid black;
vertical-align: middle;
width: 75px;
height: 75px;
}
</style>
<!--
- JavaScript and HTML must be in separate files: see our Content Security
- Policy documentation[1] for details and explanation.
-
- [1]: http://developer.chrome.com/extensions/contentSecurityPolicy.html
-->
<script src="popup.js"></script>
</head>
<body>
<textarea id="source">Text Entry.</textarea>
<button onclick="main()" id="buttons">Generate</button>
<div id="result">
</div>
</body>
</html>
popup.js
function main() {
var source = document.getElementById('source').value;
document.getElementById("result").innerHTML = source;
}