我从谷歌工作表创建新脚本,但是当我调试它时,我收到错误“超过最大堆栈深度(第48行,文件”代码“)。”我已经将触发事件设置为时间驱动,但仍然是错误。
这是我的剧本:
function onOpen() {
SpreadsheetApp.getActiveSpreadsheet().addMenu("➪ Auto Dink", [
{
name: "Setting & Run",
functionName: "setting_"
}, {
name: "Stop",
functionName: "stop"
} , {
name: "Help",
functionName: "help"
}
]);
SpreadsheetApp.getUi().createAddonMenu() // Or DocumentApp or FormApp.
.addItem('Show sidebar', 'showSidebar')
.addToUi();
showSidebar();
}
function showSidebar() {
var html = HtmlService.createHtmlOutputFromFile('howtouse')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Cara Penggunaan')
.setWidth(300);
SpreadsheetApp.getUi() // Or DocumentApp or FormApp.
.showSidebar(html);
}
function toggleTrigger_(enableTrigger) {
var triggers = ScriptApp.getProjectTriggers();
for (var i = 0; i < triggers.length; i++) {
ScriptApp.deleteTrigger(triggers[i]);
}
if (enableTrigger) {
ScriptApp.newTrigger('dink')
.timeBased().everyHours(1).create();
}
}
function dink(email, pwd, cname, ccontent) {
var props = PropertiesService.getDocumentProperties(),
email = props.getProperty("username_t"),
pwd = props.getProperty("password_t"),
cname = 0,
ccontent = 0;
AutoDink.dink(email, pwd, cname, ccontent);
}
function getRules_() {
return PropertiesService.getDocumentProperties().getProperties();
}
function setting_() {
var t = HtmlService.createTemplateFromFile("setting");
t.rules = JSON.stringify(getRules_());
var html = t.evaluate()
.setWidth(560)
.setHeight(230)
.setSandboxMode(HtmlService.SandboxMode.IFRAME);
SpreadsheetApp.getActive().show(html);
}
function saveRule(json) {
try {
var props = PropertiesService.getDocumentProperties();
props.setProperty('username_t', json.username_t);
props.setProperty('password_t', json.password_t);
props.setProperty('cname', 0);
props.setProperty('ccontent', 0);
var email = props.getProperty("username_t"),
pwd = props.getProperty("password_t"),
cname = props.getProperty("cname"),
ccontent = props.getProperty("ccontent");
var last_link = '0';
toggleTrigger_(true);
var status = AutoDink.dink(email, pwd, cname, ccontent, last_link);
var ss = SpreadsheetApp.getActive();
if(status == "" || status == undefined){
//ss.toast("Proses auto promosi telah dijalankan dan akan melakukan promosi setiap 1 jam sekali.");
} else {
ss.toast(status);
}
return "success";
} catch (f) {
var ss = SpreadsheetApp.getActive();
toggleTrigger_(false);
ss.toast("Proses menyimpan setting gagal, silakan dicoba kembali.");
Logger.log("Error: " + f.toString());
return f.toString();
}
return "gagal";
}
function stop() {
toggleTrigger_(false);
var sheet_log = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Log'),
tz = SpreadsheetApp.getActive().getSpreadsheetTimeZone();
SpreadsheetApp.getActive().toast("Proses auto dink telah dihentikan.");
var newRow = [Utilities.formatDate(new Date(), tz, "dd-MMM-yy HH:mm:ss"), "Auto Dink dihentikan"];
var newData = [newRow];
sheet_log.insertRowBefore(2).getRange(2, 1, 1, 2).setValues(newData).setBackground("white").setFontColor("black");
return;
}
function help() {
var html = HtmlService.createHtmlOutputFromFile('help')
.setTitle("Help")
.setWidth(560)
.setHeight(250)
SpreadsheetApp.getActive().show(html);
}
你能帮我解决这个错误吗? 谢谢