代码之家  ›  专栏  ›  技术社区  ›  Bowen Xu

如何获取谷歌表单的JS脚本?

  •  5
  • Bowen Xu  · 技术社区  · 7 年前

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

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

    --

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

    我如何获得此表单的相应谷歌脚本?

    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());
    }
    
    2 回复  |  直到 7 年前
        1
  •  6
  •   Christos Lytras    7 年前

    谷歌脚本编辑器是谷歌允许人们使其表单(和许多其他谷歌服务)更加灵活和可定制的一种方式。你甚至可以使用谷歌脚本创建附加组件。但世上没有 默认用户脚本

    现在,如果您想获取该表单的javascript源代码,那么可以使用

    Google Forms JS

    如果你用鼠标左键点击表单并查看其源代码,你会看到更多与谷歌表单数据相关的小脚本块:

    <script>_docs_flag_initialData={ ....
    <script>;this.gbar_={CONFIG:[[[0,"www.gstatic.com", ....
    <script type="text/javascript">var FB_PUBLIC_LOAD_DATA_ = [null,[null, ....
    
        2
  •  2
  •   p3sn    7 年前