1 回答
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();
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();
}
});
})();
添加回答
舉報(bào)
