I'm trying to test a simple add-on for Google Docs that I've made but it seems that this page of documentation is related to the legacy Apps Script editor, and I cannot find out how to do with the new Apps Script editor.
- I have read this topic, but he's trying to deploy a Workspace add-on (which is different to editor add-on)
- I know that I could simply copy-paste my code into an Apps Script directly bound to a Google Docs, but that's not what I want, I really want my add-on code in its own, independant, Apps Script project.
- My Apps Script project is linked to a proper GCP project (with billing and oauth consent screen ok)
My code, if it helps
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"
}