这个脚本可以在谷歌网站上运行吗?转换为appscript?

时间:2014-06-23 21:44:31

标签: 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;
}

1 个答案:

答案 0 :(得分:0)

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

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

你需要为你的电脑安装python

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