javascript - 这个脚本可以在谷歌网站上运行吗?转换为应用程序脚本?

标签 javascript google-apps-script google-sites

我很确定 google 不允许此代码的 javascript 版本在 google 网站上运行...此代码可以在 appscript 中使用吗?我需要做哪些改变? 代码:http://jsfiddle.net/E8SyF/

var links = ["http://www.google.com/", "http://www.cnn.com/", "http://www.bbc.com/", "http://www.nbc.com/"];
var visited = [];
var button = document.getElementById('btn');
window.onload = function () {
    if (localStorage.clickcount >= 3) {
        document.getElementById('btn').className = 'maxques';
    }
};
button.addEventListener('click', function () {
    if (typeof (Storage) !== "undefined") {
        if (localStorage.clickcount) {
            localStorage.clickcount = Number(localStorage.clickcount) + 1;
        } else {
            localStorage.clickcount = 0;
        }
        if (localStorage.clickcount == 2) {
            document.getElementById('btn').className = 'maxques';
        }
        if (localStorage.clickcount >= 3) {
            document.getElementById('btn').className = 'maxques';
            console.log(localStorage.clickcount);
            alert('You have completed this category');
            return;
        }
    }
    if (visited.length == 2) {
        document.getElementById('btn').className = 'maxques';
    }
    if (visited.length == 3) {
        alert('You have completed this category');
        return;
    }
    var random, url;

    do {
        random = Math.floor(Math.random() * 4);
        url = links[random];
    } while (contains(visited, url));
    alert('Opening: ' + 'question ' + '#' + random);
    visited.push(url);

    var win = window.open(url, '_blank', "height=800,width=800");
    win.focus();
});

function contains(array, value) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] == value) return true;
    }
    return false;
}

最佳答案

您可以将 Google 协作平台上的脚本 (javascript) 与应用引擎集成。 https://developers.google.com/appengine/?csw=1

您可以下载此应用程序,将您的脚本放入云中并与您的 Google 协作平台进行通信。

您需要为您的计算机安装python

http://obtiva.com/blog/50-deploying-a-javascript-application-to-google-appengine-in-30-minutes

关于javascript - 这个脚本可以在谷歌网站上运行吗?转换为应用程序脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24375100/

相关文章:

javascript - Mongoose :找到最近的文件

google-apps-script - 获取所有 Google Script 触发器并删除它们

html - 谷歌小部件链接

google-drive-api - 通过 API 发布在新的 Google 协作平台上创建的网站?

javascript - 如何将实时 Google 表格数据嵌入到 Google 协作平台中

javascript - 将图像 src 与正则表达式匹配直到出现空格 - Javascript

javascript - 将 gatsby 元素从 css 转换为 scss,遇到丢失网格预处理的问题

javascript - 将 PHP 数组数据发送到 javascript

google-apps-script - 如何使用 Google Apps Script 中的 url 下载文件

javascript - 使用 Google Apps 脚本展平 JSON 数组