【问题标题】:How to test an editor add-on for Google Docs with the new Apps Script editor?如何使用新的 Apps 脚本编辑器测试 Google Docs 的编辑器插件?
【发布时间】:2022-01-24 01:32:58
【问题描述】:

我正在尝试为我制作的 Google Docs 测试一个简单的插件,但似乎 this page of documentation 与旧版 Apps 脚本编辑器有关,我不知道如何处理新版 Apps脚本编辑器。

  1. 我已阅读此topic,但他正在尝试部署 Workspace 插件(与编辑器插件不同)
  2. 我知道我可以简单地将我的代码复制粘贴到直接绑定到 Google Docs 的 Apps 脚本中,但这不是我想要的,我真的希望我的附加代码在它自己的、独立的 Apps 脚本项目中。
  3. 我的 Apps 脚本项目已链接到适当的 GCP 项目(计费和 oauth 同意屏幕正常)

我的代码,如果有帮助的话

const PASS = "PASSPHRASE";

function decrypt(text) {
  var cipher = new cCryptoGS.Cipher(PASS, 'aes');
  return cipher.decrypt(text)
}

function encrypt(text) {
  var cipher = new cCryptoGS.Cipher(PASS, 'aes');
  return cipher.encrypt(text)
}

function decryptDocument() {
  var doc = DocumentApp.getActiveDocument();
  var paragraphs = doc.getBody().getParagraphs();
  return paragraphs.reduce((previous, current) => {
    return previous + "\n" + decrypt(current.getText());
  }, ""); 
}

function onOpen() {
  DocumentApp.getUi()
      .createMenu('Décodeur')
      .addItem('Lancer le décodeur', 'showSidebar')
      .addToUi();
}

function showSidebar() {
  var html = HtmlService.createHtmlOutputFromFile('decoder')
      .setTitle('Décodeur');
  DocumentApp.getUi().showSidebar(html);
}
<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    <button onclick="decrypt()">Décoder le contenu</button>
    <div id="decodedText">
      </div>
  </body>
  <script>
    var running = false;

    function onSuccess(decodedText) {
      running = false;
      document.getElementById("decodedText").innerHTML = decodedText;
    }

    function onFailure(e) {
      running = false;
      console.error(e);
    }

    function cleanDiv() {
      document.getElementById("decodedText").innerHTML = "";
    }

    function decrypt() {
      running = true;
      google.script.run.withSuccessHandler(onSuccess)
        .withFailureHandler(onFailure)
        .decryptDocument();
    }
    </script>
</html>
{
  "timeZone": "America/New_York",
  "dependencies": {
    "libraries": [
      {
        "userSymbol": "cCryptoGS",
        "version": "4",
        "libraryId": "1IEkpeS8hsMSVLRdCMprij996zG6ek9UvGwcCJao_hlDMlgbWWvJpONrs"
      }
    ]
  },
  "exceptionLogging": "STACKDRIVER",
  "runtimeVersion": "V8"
}

【问题讨论】:

  • 有什么问题?
  • 看来你漏掉了这部分:“注意:你必须使用旧版编辑器来测试Editor Add-ons。要从新编辑器切换到旧版编辑器,请点击顶部的使用旧版编辑器编辑器屏幕。”
  • 天哪,我讨厌那些蓝色背景的音符,我从来没有见过它们......

标签: google-apps-script google-docs add-on


【解决方案1】:

彻底测试编辑器插件的唯一方法是使用 Google Workspace SDK 发布。

如果您想使用 Google Apps 脚本的“测试为插件”功能,您必须使用旧版编辑器。这可能适用于测试 onOpen 简单触发器等一些功能,但不适用于测试可安装触发器等其他功能。

显然您的编辑器插件没有使用可安装的触发器和其他无法使用“作为插件测试”测试的功能,它很可能足以测试您的插件的简单触发器 -开。

附:您的插件缺少 onInstall 简单触发器,该触发器通常用于在从打开的文档安装插件时调用 onOpen 触发器。

相关

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多