Google Chrome の拡張機能の作成方法を学び始めたばかりです。これまでのところ、私は非常に基本的な理解を持っているので、小さなことを試してみたかった.
現在、特定のページが読み込まれるたびに、特定のページの特定の div に画像を追加しようとしています。拡張機能は正しく読み込まれますが、JavaScript コードが実行されないようで、画像が読み込まれません。
これは私がこれまで持っている manifest.json ファイルです:
{
"manifest_version": 2,
"name": "Icon Creator",
"description": "Creates a custom icon for page",
"version": "1.0",
"content_scripts": [
{
"matches": ["file:///home/tijko/documents/learning/javascript/test_page.html"],
"css": ["sample.css"],
"js":["trial.js"]
}
],
"icons": {"icon": "icon.jpg"},
"web_accessible_resources":["trial.js"]
}
そしてJavaScript:
var test = function() {
custom_icon = document.createElement("img");
target = document.getElementById("location");
custom_icon.src = "icon.png";
target.appendChild(custom_icon);
}
test()