Chrome 拡張機能を使う


  • 備忘録

sample

manifest.json
{
  "name": "hoge",
  "version": "0.0.1",
  "manifest_version": 2,
  "description": "Chrome Extensions Test.",
  "content_scripts": [
    {
      "matches": ["http://xxx.xxx.xxx.xxx/chromeExt/*"],
      "js": [
        "scripts/jquery-3.2.1.min.js",
        "scripts/main.js"
      ],
      "run_at": "document_idle"
    }
  ]
}
index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Chrome Extensions Test</title>
  </head>
  <body>
    <div id="main"></div>
  </body>
</html>
scripts/main.js
$(function() {
  var extHtml = '<input type="button" id="extBtn" value="Download">';
  var main = $("#main");
  main.append(extHtml);

  $("#extBtn").on("click", function() {
    console.log("extBtn clicked.");
  });
});

参考リンク