5

我有一个谷歌表单,我怎样才能得到它的 js 脚本?

我单击脚本编辑器,但找不到相应的 js。

我已经在互联网上搜索过,但没有预期的答案。

-- 2017 年 8 月 20 日更新

假设我拥有这样的表格: Sample Form

我怎样才能得到这个表格对应的谷歌脚本?

IE,

function myFunction() {
    // Create a new form, then add a checkbox question, a multiple choice question,
    // a page break, then a date question and a grid of questions.
    var form = FormApp.create('Sample Form');
    var sect1 = form.addSectionHeaderItem();
    var item = form.addCheckboxItem();
    item.setTitle('What condiments would you like on your hot dog?');
    item.setChoices([item.createChoice('Ketchup'), item.createChoice('Mustard'), item.createChoice('Relish')]);
    var item2 = form.addMultipleChoiceItem().setTitle('Do you prefer cats or dogs?');
    //    .setChoiceValues(['Cats','Dogs'])
    //    .showOtherOption(true);
    var sect2 = form.addSectionHeaderItem();
    form.addPageBreakItem().setTitle('Getting to know you');
    form.addDateItem().setTitle('When were you born?');
    var sect3 = form.addSectionHeaderItem();
    var break2 = form.addPageBreakItem().setTitle('Getting to know you 2');

    var choice1 = item2.createChoice('cat', FormApp.PageNavigationType.CONTINUE);
    var choice2 = item2.createChoice('dog', break2);
    item2.setChoices([choice1, choice2]);

    form.addGridItem().setTitle('Rate your interests').setRows(['Cars', 'Computers', 'Celebrities']).setColumns(['Boring', 'So-so', 'Interesting']);
    Logger.log('Published URL: ' + form.getPublishedUrl());
    Logger.log('Editor URL: ' + form.getEditUrl());
}
4

2 回答 2

6

谷歌脚本编辑器是谷歌允许人们使他们的表单(和许多其他谷歌服务)更加灵活和可定制的一种方式。您甚至可以使用 Google 脚本创建附加组件。但是没有每个表单的默认用户脚本。所有表单都从没有用户 Google 脚本开始,您可以通过编写一些新脚本来添加更多功能。

现在,如果您想获取该表单的 javascript 源代码,那么您可以使用Chrome 中的开发人员工具(Windows 中的 F12 键)并转到源代码,您将看到 Google 用于表单的所有脚本:

谷歌表单 JS

如果您左键单击表单并查看其源代码,您会看到更多与 Google 表单拥有的数据相关的小脚本块:

<script>_docs_flag_initialData={ ....
<script>;this.gbar_={CONFIG:[[[0,"www.gstatic.com", ....
<script type="text/javascript">var FB_PUBLIC_LOAD_DATA_ = [null,[null, ....
于 2017-08-19T08:25:15.937 回答
2

另一种方法是自己创建一个 html 表单并将请求发送到 Google Apps Script Web 应用程序。如果你想试试看这个例子:https ://gist.github.com/mhawksey/1276293

问候,彼得

于 2017-08-23T21:42:21.163 回答