如何获取Google表单的JS脚本?

Bra*_*rad 3 javascript google-apps-script google-forms google-apps-script-editor

我拥有一个谷歌表格,我怎么能得到它的js脚本?

我单击脚本编辑器,但没有相应的js我可以找到.

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

- 2017年8月20日更新

假设我拥有这样一个表单: Sample Form.

如何获取此表单的相应Google脚本?

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());
}
Run Code Online (Sandbox Code Playgroud)

Chr*_*ras 5

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

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

Google Forms 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, ....
Run Code Online (Sandbox Code Playgroud)