有没有办法使用javascript将解压缩的扩展程序上传到chrome?

时间:2018-07-10 14:27:23

标签: javascript html google-chrome google-chrome-extension

我有一个chrome扩展程序生成器,它下载了多个文件。我希望它将所有文件放在一个新文件夹中,而不是全部下载到下载文件夹中,然后上传到chrome。如果有办法,那会很好,但是由于它会自动安装扩展程序,因此可能不起作用?这是代码:

<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>Extension Maker</title>
</head>

<body>
  <form>
    <h1>Extension maker for chrome</h1>
    <input id="name" size="22" placeholder="Extension name">
    <br>
    <input id="vers" size="22" placeholder="Version">
    <br>
    <textarea id="desc" placeholder="Description"></textarea>
    <br><br><br>
    <input type="checkbox" id="popup">Popup <input id="popup-html" placeholder="Popup html">
    <br>
    <input type="checkbox" id="urlo">Change contents of single page <input id="page-cont" placeholder="Page HTML">
    <select id="select">
      <option value="newtab">New Tab Page</option>
      <option value="bookmarks">Bookmarks Page</option>
      <option value="history">History Page</option>
    </select>
    <br>
    <input type="checkbox" id="js">Run JavaScript <input id="js" placeholder="JS">
    <br><br><br>
    <button onclick="downloadAll()" id="downloadbutton">Download</button>
  </form>
  <script>
    function download(filename, text) {
      var element = document.createElement('a');
      element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
      element.setAttribute('download', filename);

      element.style.display = 'none';
      document.body.appendChild(element);

      element.click();

      document.body.removeChild(element);
    };

    function downloadAll() {
      var first = document.getElementById("popup").checked;
      var second = document.getElementById("urlo").checked;
      var third = document.getElementById("js").checked;
      var name = document.getElementById("name").value;
      var vers = document.getElementById("vers").value;
      var desc = document.getElementById("desc").value;
      var pophtml = document.getElementById("popup-html").value;
      var manifeststart = "{     'name': " + name + ",     'version': " + vers + ",     'description': " + desc + ",               'manifest_version': 2   ";
      if (first === true) {
        var manifest = manifeststart + "'default_popup': 'popup.html',       'default_icon': {         '16': 'images/get_started16.png'       }     },}";
        var text = document.getElementById("popup-html").value;
        var filename = "popup.html";

        download(filename, text);
      };
      if (second === true) {
        var select = document.getElementById("select").value;
        var text = document.getElementById("select").value;
        var manifest = manifest + "'chrome_url_overrides' : { ' " + select + "': 'myPage.html' }";
        var text = document.getElementById("page-cont").value;
        var filename = "myPage.html";

        download(filename, text);
      };
      if (third === true) {
        var manifest = manifest + "'background': {'scripts': ['background.js'],'persistent': false }";
        var text = document.getElementById("js").value;
        var filename = "background.js";
        download(filename, text);
      };
      var manifest = manifest + ",    }";
      var text = manifest;
      var filename = "manifest.json";

      download(filename, text);
    };
  </script>
</body>

</html>

(还请告诉我代码是否有误)

这可能吗?预先感谢!

0 个答案:

没有答案