[英]fetch javascript input/output from google sheet
I have the code below on Apps script but keep getting 'ReferenceError: setInterval is not defined on line 17'.我在 Apps 脚本上有以下代码,但不断收到“ReferenceError:setInterval 未在第 17 行定义”。 Not sure how to fix this but it does load when i use the scipt below in a cell in google sheets and set it up to output to another - it runs apart from that error.不知道如何解决这个问题,但是当我在谷歌表格的一个单元格中使用下面的 scipt 并将其设置为 output 到另一个时,它确实会加载 - 它与该错误分开运行。 not sure if it's because i have it set up wrong or because google apps script doesn't like the code不确定是因为我设置错误还是因为谷歌应用程序脚本不喜欢代码
function scart() {// ==UserScript==
setInterval(function() {
var possibleClasses = [".listenArtworkWrapper", ".listenInfo"],
sizes = { 't500x500': '500x500', 'original': 'original size' },
regexp = /t\d{3}x\d{3}/gi;
$('.modal__content:not(.appeared)')
.addClass('appeared')
.each(handleModal);
function handleModal() {
var imageURL;
for (var i = 0; i < possibleClasses.length; i++) {
if ($(possibleClasses[i] + " .image__full").length > 0) {
imageURL = $(possibleClasses[i] + " .image__full").css('background-image');
}
}
if (!imageURL) {
logError('No suitable selector found!');
} else {
imageURL = /url\("(.+)"\)/.exec(imageURL)[1];
}
$(".modal__content .image__full").parent().remove();
$(".modal__content .imageContent").append("<img style='width: 500px; height: 500px; margin-bottom: 15px;' src='" + imageURL.replace(regexp, 't500x500') + "'>");
Object.keys(sizes).forEach(function (size) {
var url = imageURL.replace(regexp, size);
$.ajax({
type: 'HEAD',
url: url,
complete: function(xhr) {
if (xhr.status !== 200) {
return;
}
$(".modal__content .imageContent").append(
makeButton(url, sizes[size])
);
}
});
});
}
function makeButton(url, sizeLabel) {
var $btn = $('<button />')
.css({ margin: '10px auto 0 auto', display: 'block', width: '100%'})
.attr('class', 'sc-button sc-button-medium sc-button-responsive')
.text('Download ' + sizeLabel);
$btn.on('click', function(e) {
e.preventDefault();
download(url);
});
return $btn;
}
function download(url) {
url = url.split('?')[0];
if (!url.startsWith('http')) {
url = window.location.protocol + (url.startsWith('//') ? '' : '//') + url;
}
var fileNameParts = url.split('/');
var fileName = fileNameParts[fileNameParts.length - 1];
var options = {
url: url,
name: fileName,
onerror: function (e) {
logError('Download failed. Reason: ' + e.error);
}
};
GM_download(options);
}
function logError(message) {
var details = {
title: GM_info.script.name,
text: message,
};
GM_notification(details);
console.error('%c' + GM_info.script.name + '%c: ' + message, 'font-weight: bold', 'font-weight: normal');
}
}, 250); }, 250);
} }
setInterval
is not actually a function within Google App Script. setInterval
实际上不是 Google App Script 中的 function。 You'll have to utilize the other built-in features.您必须使用其他内置功能。 I typically use Utilities.sleep(timeout)
to make this work.我通常使用Utilities.sleep(timeout)
来完成这项工作。 You can see more here .你可以在这里看到更多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.