Files
ackify-ce/examples/google/appscript/Code.gs
Benjamin 3aaf1b25f8 docs: migrate to AGPL-3.0-or-later and add COPYRIGHT
- Replace SSPL with GNU AGPLv3 (LICENSE)
- Add COPYRIGHT with attribution
- Update Dockerfile label, README(s), BUILD.md
- Add SPDX headers across repo

refacto: remove redundant descriptive comments; keep only meaningful rationales
- Convert doc-comments to GoDoc style without colons
- Keep only security/algorithm rationales (CSRF state, CSP, chain hash, Bresenham)

tests: harden OAuth handlers tests (state missing/invalid) and fix fakes
- Add VerifyState token checks; ensure CreateAuthURL used
- Clean noisy comments in tests

docs: align docker-compose and scripts headers
2025-09-27 17:39:17 +02:00

99 lines
3.4 KiB
JavaScript

// SPDX-License-Identifier: AGPL-3.0-or-later
function onOpen() {
DocumentApp.getUi()
.createMenu("Signatures")
// .addItem("Confirmer la lecture de ce document", "openSignature")
.addItem("Afficher la barre latérale", "showSignatures")
.addToUi();
}
function getSidebarHtml() {
var doc = DocumentApp.getActiveDocument();
var docId = doc.getId();
var url = "https://sign.neodtx.com/embed?doc=" + encodeURIComponent(docId);
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
return response.getContentText();
}
function openSignature() {
var doc = DocumentApp.getActiveDocument();
var docId = doc.getId();
var url = "https://sign.neodtx.com/sign?doc=" + encodeURIComponent(docId);
var html = '<style>html,body{height:100%;margin:0;padding:0}</style>' +
'<iframe src="' + url + '" ' +
'style="border:0;width:100%;height:100vh;" ' +
'sandbox="allow-scripts allow-popups allow-same-origin allow-forms"></iframe>';
var output = HtmlService.createHtmlOutput(html);
DocumentApp.getUi().showModalDialog(output, 'Confirmer la lecture du document');
}
function showSignatures() {
var doc = DocumentApp.getActiveDocument();
var docId = doc.getId();
var url = "https://sign.neodtx.com/embed?doc=" + encodeURIComponent(docId);
var response = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
var html = response.getContentText();
var modifiedHtml = html + `
<script>
document.addEventListener('DOMContentLoaded', function() {
// Fonction pour rafraîchir le sidebar
function refreshSidebar() {
google.script.run.withSuccessHandler(function(newHtml){
document.body.innerHTML = newHtml;
// Réinjecte les listeners après rafraîchissement
addLinkListeners();
}).getSidebarHtml();
}
// Ajoute les listeners sur tous les liens
function addLinkListeners() {
document.querySelectorAll('a[href]').forEach(function(link){
link.addEventListener('click', function(e){
e.preventDefault();
// Ajoute un listener focus sur window
function onFocus() {
window.removeEventListener('focus', onFocus); // on supprime après déclenchement
refreshSidebar();
}
window.addEventListener('focus', onFocus);
window.open(link.href, '_blank');
});
});
}
addLinkListeners(); // initial call
});
</script>
`;
var output = HtmlService.createHtmlOutput(modifiedHtml)
.setTitle("Signatures")
.setXFrameOptionsMode(HtmlService.XFrameOptionsMode.ALLOWALL)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
DocumentApp.getUi().showSidebar(output);
}
// function showSignatures() {
// var doc = DocumentApp.getActiveDocument();
// var docId = doc.getId();
// var url = "https://sign.neodtx.com/embed?doc=" + encodeURIComponent(docId);
// // On insère un iframe pointant sur ton embed
// var html = '<style>html,body{height:100%;margin:0;padding:0}</style>' +
// '<iframe src="' + url + '" ' +
// 'style="border:0;width:100%;height:100vh;" ' +
// 'sandbox="allow-scripts allow-popups allow-same-origin allow-forms"></iframe>';
// var output = HtmlService.createHtmlOutput(html)
// .setTitle("Signatures du document")
// .setWidth(360); // largeur sidebar (modifiable)
// DocumentApp.getUi().showSidebar(output);
// }