第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用 JS 使用隨機(jī)答案自動(dòng)填充 Google 表單

如何使用 JS 使用隨機(jī)答案自動(dòng)填充 Google 表單

FFIVE 2022-05-26 10:44:46
我想使用 JS 隨機(jī)填寫 100 個(gè) google 表單。有什么辦法嗎?有示例谷歌表格。我在 stackoverflow 或 web 上找不到任何東西,只有 python 或 java 解決方案。但如果可能的話,我當(dāng)然想用javascript來做。
查看完整描述

1 回答

?
慕碼人2483693

TA貢獻(xiàn)1860條經(jīng)驗(yàn) 獲得超9個(gè)贊

這是一個(gè)骯臟的腳本,可能是一個(gè)起點(diǎn)。它適用于您作為示例提供的特定表單。它用于document.querySelector定位表單元素。

只要您打開表單,它就會(huì)填寫、提交、返回、提交,一遍又一遍。

要使用它:

  • 在 Google Chrome 中安裝TamperMonkey擴(kuò)展

  • 單擊瀏覽器中出現(xiàn)的圖標(biāo),選擇“儀表板”

  • 創(chuàng)建一個(gè)新腳本,將所有內(nèi)容替換為下面的代碼

  • Ctrl + S 保存

  • 在選項(xiàng)卡中打開表單并觀察它的工作

代碼:

// ==UserScript==

// @name         GoogleForm Spammer

// @namespace    http://tampermonkey.net/

// @version      0.1

// @description  Spam a Google Form

// @author       You

// @match        https://docs.google.com/forms/*

// @grant        unsafeWindow

// ==/UserScript==


(function() {

  window.addEventListener('load', function() {

    if (window.location.pathname.indexOf('/forms/d') === 0) { // If we're on the form page

      submitRandomForm();

    } else if (window.location.pathname.indexOf('/forms/u') === 0) { // If we're on the "submitted" page

      goBackToForm();

    }


    function submitRandomForm() {

      // Size

      var radios     = document.querySelectorAll(".appsMaterialWizToggleRadiogroupRadioButtonContainer"),

          radioIndex = Math.floor(Math.random() * radios.length);

      radios[radioIndex].click();


      // Print

      var checkboxes    = document.querySelectorAll(".appsMaterialWizTogglePapercheckboxCheckbox"),

          checkboxIndex = Math.floor(Math.random() * checkboxes.length);

      checkboxes[checkboxIndex].click();


      // Age (between 16 and 45)

      var age = Math.floor(Math.random() * 30) + 16;

      document.querySelector(".quantumWizTextinputPaperinputInput").value = age;


      // Submit

      document.querySelector(".freebirdFormviewerViewCenteredContent .appsMaterialWizButtonPaperbuttonLabel").click();

    }


    function goBackToForm() {

      window.location.href = 'https://docs.google.com/forms/d/e/1FAIpQLSd7GueJGytOiQpkhQzo_dCU0oWwbk3L1htKblBO1m14VHSpHw/viewform';

    }

  });

})();

這是一個(gè)更清潔的方法。您在頂部聲明表單 URL、表單字段,并且對(duì)于其中的一些,一個(gè)函數(shù)將根據(jù)您的需要返回一個(gè)隨機(jī)值。


要嘗試這個(gè),請(qǐng)保存該腳本,然后嘗試訪問此表單:


// ==UserScript==

// @name         GoogleForm Spammer

// @namespace    http://tampermonkey.net/

// @version      0.1

// @description  Spam a Google Form

// @author       You

// @match        https://docs.google.com/forms/*

// @grant        none

// ==/UserScript==


var formUrl = 'https://docs.google.com/forms/d/e/1FAIpQLSdQ9iT7isDU8IIbyg-wowB-9HGzyq-xu2NyzsOeG0j8fhytmA/viewform';

var formSchema = [

    {type: 'radio'},      // A

    {type: 'radio'},      // B

    {type: 'checkbox'},   // C

    {type: 'checkbox'},   // D

    {type: 'short_text', func: generateAnswerE },   // E

    {type: 'paragraph', func: generateParagraph },  // F

];


function generateAnswerE() {

  // Let's say we want a random number

  return Math.floor(Math.random() * 30) + 16;

}


function generateParagraph() {

  // Just for the example

  return "Hello world";

}


(function() {

  window.addEventListener('load', function() {

    if (window.location.pathname.indexOf('/forms/d') === 0) { // If we're on the form page

      submitRandomForm();

    } else if (window.location.pathname.indexOf('/forms/u') === 0) { // If we're on the "submitted" page

      window.location.href = formUrl;

    }


    function submitRandomForm() {

      var formItems = document.querySelectorAll('.freebirdFormviewerViewItemsItemItem');


      for (var i = 0; i < formSchema.length; i++) {

        var field = formSchema[i],

            item  = formItems[i];

        switch(field.type) {

            case 'radio':

                var radios     = item.querySelectorAll(".appsMaterialWizToggleRadiogroupRadioButtonContainer"),

                    radioIndex = Math.floor(Math.random() * radios.length);

                radios[radioIndex].click();

                break;

            case 'checkbox':

                var checkboxes    = item.querySelectorAll(".appsMaterialWizTogglePapercheckboxCheckbox"),

                    checkboxIndex = Math.floor(Math.random() * checkboxes.length);

                checkboxes[checkboxIndex].click();

                break;

            case 'short_text':

                item.querySelector(".quantumWizTextinputPaperinputInput").value = field.func();

                break;

            case 'paragraph':

                item.querySelector(".quantumWizTextinputPapertextareaInput").value = field.func();

                break;

        }

      }


      // Submit

      document.querySelector(".freebirdFormviewerViewCenteredContent .appsMaterialWizButtonPaperbuttonLabel").click();

    }

  });

})();


查看完整回答
反對(duì) 回復(fù) 2022-05-26
  • 1 回答
  • 0 關(guān)注
  • 195 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)