我正在嘗試為我制作的 Google Docs 測驗一個簡單的附加組件,但此檔案頁面似乎與舊版 Apps 腳本編輯器有關,我無法找到如何使用新的 Apps 腳本編輯器.
- 我已閱讀此主題,但他正在嘗試部署 Workspace 附加組件(與編輯器附加組件不同)
- 我知道我可以簡單地將我的代碼復制粘貼到直接系結到 Google Docs 的 Apps 腳本中,但這不是我想要的,我真的希望我的附加代碼在它自己的、獨立的 Apps 腳本專案中。
- 我的 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"
}
uj5u.com熱心網友回復:
徹底測驗編輯器插件的唯一方法是使用 Google Workspace SDK 發布。
如果您想使用 Google Apps 腳本的“作為插件測驗”功能,您必須使用舊版編輯器。這可能適合測驗一些功能,如onOpen 簡單觸發器, 但不適用于測驗其他功能,如可安裝觸發器。
很明顯,您的編輯器附加組件沒有使用可安裝的觸發器和其他無法通過“作為附加組件測驗”進行測驗的功能,很可能足以測驗您的附加組件的簡單觸發器。
PS 您的附加組件缺少onInstall簡單的觸發器,onOpen當從打開的檔案安裝附加組件時,該觸發器通常用于呼叫觸發器。
有關的
- 可安裝的觸發器因測驗加載項而失敗
- Google 表格編輯器附加組件的“作為附加組件測驗”是否已損壞?
- 測驗 Google Sheet 插件觸發器
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/391004.html
