AutoCompleteForm

AScript!

当前为 2022-04-16 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name AutoCompleteForm
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.14.6
  5. // @description AScript!
  6. // @author You
  7. // @match https://docs.google.com/forms/*
  8. // @match https://app.poap.xyz/*
  9. // @match https://gleam.io/*
  10. // @match https://discord.com/invite/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=google.com
  12. // @grant none
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. function sleep(ms = 0) {
  17. return new Promise(r => setTimeout(r, ms));
  18. }
  19.  
  20. function createBtn(name, text, top) {
  21. var btn = document.createElement('button');
  22. btn.innerText = name;
  23. btn.style.position = 'fixed';
  24. btn.style.top = `${top}px`;
  25. btn.style.left = `20%`;
  26. btn.style.width = '80px'
  27. btn.style.height = '45px'
  28. btn.addEventListener('click', () => {
  29. // 创建输入框
  30. var textarea = document.createElement('textarea');
  31. document.body.appendChild(textarea);
  32. // 隐藏此输入框
  33. textarea.style.position = 'absolute';
  34. textarea.style.clip = 'rect(0 0 0 0)';
  35. // 赋值
  36. textarea.value = text;
  37. // 选中
  38. textarea.select();
  39. // 复制
  40. document.execCommand('copy', true);
  41. console.log(`copy ${name}: ${text} success`)
  42. });
  43. return btn;
  44.  
  45. }
  46.  
  47.  
  48. const insertBtns = (accountData) => {
  49. if (!accountData) {
  50. return
  51. }
  52. const btnSpace = 65
  53. console.log('currentAddress', accountData.eth)
  54. let btnIndex = 1
  55. const emailBtn = createBtn("Email", accountData.email, btnIndex * btnSpace + 20);
  56. btnIndex++
  57. const discordBtn = createBtn("Discord", accountData.discord, btnIndex * btnSpace + 20);
  58. btnIndex++
  59. const ethBtn = createBtn("ETH", accountData.eth, btnIndex * btnSpace + 20);
  60. btnIndex++
  61. const solBtn = createBtn("SOL", accountData.sol, btnIndex * btnSpace + 20);
  62. btnIndex++
  63. const twitterBtn = createBtn("Twitter", accountData.twitter, btnIndex * btnSpace + 20);
  64. btnIndex++
  65. const twitterProfileBtn = createBtn("TwitterLink", accountData.twitterProfile, btnIndex * btnSpace + 20);
  66. btnIndex++
  67. var wrapper = document.body;
  68. wrapper.appendChild(emailBtn);
  69. wrapper.appendChild(discordBtn);
  70. wrapper.appendChild(discordBtn);
  71. wrapper.appendChild(ethBtn);
  72. wrapper.appendChild(solBtn);
  73. wrapper.appendChild(twitterBtn);
  74. wrapper.appendChild(twitterProfileBtn);
  75. }
  76.  
  77. const answerSnatTest01 = () => {
  78. if (document.title != '响指测验卷-01') {
  79. return
  80. }
  81. console.log("start answer snat test 01....")
  82. const spans = document.getElementsByClassName("aDTYNe snByac")
  83. for (let spanItem of spans) {
  84. const text = spanItem.textContent
  85. console.log('text', text)
  86. if (!text || !text.length) {
  87. continue
  88. }
  89.  
  90. if (
  91. text.indexOf("The end of Feb—Gift for Meta Cowboy") != -1 ||
  92. text.indexOf("股份授权证明机制") != -1 ||
  93. text.indexOf("Eat to Earn") != -1 ||
  94. text.indexOf("4个") != -1 ||
  95. text.indexOf("跟管理员撒娇") != -1 ||
  96. text.indexOf("加入未成年人防沉迷系统") != -1 ||
  97. text.indexOf("绑定金系统") != -1 ||
  98. text.indexOf("陈奕迅") != -1 ||
  99. text.indexOf("用于激励生态") != -1 ||
  100. text.indexOf("生态使用参与凭证") != -1 ||
  101. text.indexOf("进行交易兑换") != -1 ||
  102. text.indexOf("参与治理凭证") != -1 ||
  103. text.indexOf("参与治理凭证") != -1 ||
  104. text.indexOf("Volmex") != -1 ||
  105. text.indexOf("Lv8 身份的用户") != -1 ||
  106. text.indexOf("SubDAO") != -1 ||
  107. text.indexOf("StarSharks") != -1 ||
  108. text.indexOf("Good Luck Games") != -1 ||
  109. text.indexOf("10") != -1
  110. ) {
  111. spanItem.click()
  112. continue
  113. }
  114. }
  115. console.log("answer snat test 01 done")
  116. }
  117.  
  118. const answerMoleHack = () => {
  119. if (document.title.indexOf('MoleHack: NFT 2.0 Finale Quiz') == -1) {
  120. return
  121. }
  122. console.log("start answer MoleHack....")
  123. const spans = document.getElementsByClassName("aDTYNe snByac")
  124. for (let spanItem of spans) {
  125. const text = spanItem.textContent
  126. console.log('text', text)
  127. if (!text || !text.length) {
  128. continue
  129. }
  130.  
  131. if (
  132. text.indexOf("NFT 2.0") != -1 ||
  133. text.indexOf("Project Galaxy") != -1
  134. ) {
  135. spanItem.click()
  136. continue
  137. }
  138. }
  139. console.log("answer snat test 01 done")
  140. }
  141.  
  142. const handleGleamEntry = async (entry, accountData) => {
  143. const innerText = entry.innerHTML.toLowerCase()
  144. const continuBtn = entry.querySelector("button")
  145. console.log('continuBtn', continuBtn)
  146. if (continuBtn) {
  147. continuBtn.click()
  148. await sleep(5000)
  149. return
  150. }
  151.  
  152. const textareaItem = entry.querySelector("textarea")
  153. if (!textareaItem) {
  154. console.log('no textarea')
  155. return
  156. }
  157. textareaItem.focus()
  158. if (
  159. innerText.indexOf("address") != -1 ||
  160. innerText.indexOf("wallet") != -1 ||
  161. innerText.indexOf("polygon") != -1 ||
  162. innerText.indexOf("ethereum") != -1 ||
  163. innerText.indexOf("bsc") != -1
  164. ) {
  165. document.execCommand('insertText', false, accountData.eth);
  166. } else if (innerText.indexOf("discord") != -1) {
  167. document.execCommand('insertText', false, accountData.discord);
  168. } else if (innerText.indexOf("speakers were featured") != -1) {
  169. document.execCommand('insertText', false, "5");
  170. } else if (innerText.indexOf("twitter") != -1) {
  171. document.execCommand('insertText', false, `@${accountData.twitter}`);
  172. } else if (innerText.indexOf("color of the hat") != -1) {
  173. document.execCommand('insertText', false, "blue");
  174. } else {
  175. document.execCommand('insertText', false, accountData.email);
  176. }
  177.  
  178. await sleep(2000)
  179. const continueBtns = entry.getElementsByClassName("btn btn-primary")
  180. if (continueBtns && continueBtns.length) {
  181. continueBtns[0].click()
  182. await sleep(2000)
  183. }
  184. }
  185.  
  186. class ActionPromise {
  187. constructor(_id, _timeout) {
  188. this.id = _id
  189. this.timeout = _timeout || 10000
  190. console.log(`new actionPromise id ${this.id}, timeout ${this.timeout}`)
  191. let entryResolve
  192. const entryPromise = new Promise((resolve, reject) => {
  193. entryResolve = resolve
  194. })
  195. const entryWaitfunc = async () => {
  196. return entryPromise
  197. }
  198. this.entryResolve = entryResolve
  199. this.entryPromise = entryPromise
  200. this.entryWaitfunc = entryWaitfunc
  201. }
  202. async wait() {
  203. let catchThis = this
  204. setTimeout(() => {
  205. if (catchThis.done) {
  206. return
  207. }
  208. console.log(`action ${catchThis.id} timeout`)
  209. catchThis.done = true
  210. catchThis.entryResolve()
  211. }, this.timeout)
  212. await this.entryWaitfunc()
  213. }
  214. resolve() {
  215. this.done = true
  216. this.entryResolve()
  217. }
  218.  
  219. }
  220.  
  221. const preFillWallet = async (accountData) => {
  222. if (!accountData) {
  223. return
  224. }
  225. const inputWraps = document.getElementsByClassName("input boolean form-group additional-checkbox")
  226. if (!inputWraps || !inputWraps.length) {
  227. console.log('no inputWraps')
  228. return
  229. }
  230. for (let item of inputWraps) {
  231. const inputItem = item.querySelector("input")
  232. console.log("click input", inputItem)
  233. inputItem.click()
  234. }
  235.  
  236. const walletInputs = document.getElementsByName("bep20_wallet_address")
  237. if (!walletInputs || !walletInputs.length) {
  238. return
  239. }
  240. console.log('walletInputs', walletInputs[0], accountData.eth)
  241. await sleep(6000)
  242. walletInputs[0].focus()
  243.  
  244. document.execCommand('insertText', false, accountData.eth);
  245.  
  246. }
  247.  
  248. const autoClickGleam = async (accountData) => {
  249. if (!accountData) {
  250. return
  251. }
  252. const localUrl = window.document.location.href
  253. if (!localUrl || localUrl.indexOf("gleam.io") == -1) {
  254. return
  255. }
  256. if (document.body.innerHTML.indexOf("agree to the following") != -1) {
  257. console.log("pre fill wallet")
  258. await preFillWallet(accountData)
  259. await sleep(15000)
  260. }
  261. console.log('gleam loading start')
  262. const entryList = document.getElementsByClassName("entry-method")
  263. console.log('all entry count', entryList.length)
  264. if (!entryList || !entryList.length) {
  265. return
  266. }
  267. let waitGroup = {}
  268. for (let entry of entryList) {
  269.  
  270. waitGroup[entry.id] = new ActionPromise(entry.id, 5000)
  271. console.log("add entry wait group", entry.id)
  272. var observer = new MutationObserver(async function (mutations) {
  273. for (let mutation of mutations) {
  274.  
  275. const className = mutation.target.className
  276. console.log('entry class onChange', className, mutation.target.id, mutation)
  277. if (className.indexOf("completed-entry-method") != -1) {
  278. const ap = waitGroup[entry.id]
  279. if (!ap.done) {
  280. ap.resolve()
  281. }
  282. return
  283. }
  284.  
  285. if (className.indexOf("expanded") == -1) {
  286. console.log("no expanded")
  287. return
  288. }
  289.  
  290. await handleGleamEntry(mutation.target, accountData)
  291. }
  292. });
  293.  
  294. observer.observe(entry, {
  295. attributes: true,
  296. attributeFilter: ['class']
  297. });
  298. }
  299.  
  300. console.log('gleam add watch done')
  301. for (let i = 0; i < entryList.length; i++) {
  302. const entry = entryList[i]
  303. const children = entry.children
  304. if (!children || !children.length) {
  305. continue
  306. }
  307. console.log(`entry ${i}, class ${entry.className}`)
  308.  
  309. if (entry.className.indexOf("completed-entry-method") != -1) {
  310. console.log("completed entry", entry.className)
  311. continue
  312. }
  313.  
  314. if (entry.className.indexOf("expanded") != -1) {
  315. console.log("expanded entry", i)
  316. await handleGleamEntry(entry, accountData)
  317. await sleep(10000)
  318. continue
  319. }
  320.  
  321. }
  322. for (let i = 0; i < entryList.length; i++) {
  323. const entry = entryList[i]
  324. const children = entry.children
  325. if (!children || !children.length) {
  326. continue
  327. }
  328. if (entry.className.indexOf("completed-entry-method") != -1) {
  329. console.log("completed entry", i, entry.className)
  330. continue
  331. }
  332.  
  333. if (entry.className.indexOf("expanded") != -1) {
  334. console.log("expanded entry second loop", i)
  335. // await handleGleamEntry(entry, accountData)
  336. continue
  337. }
  338. const innerText = entry.innerHTML.toLowerCase()
  339. if (innerText.indexOf("extra entries") != -1) {
  340. console.log("extra entries")
  341. continue
  342. }
  343. if (innerText.indexOf("secret code") != -1) {
  344. console.log("skip secret code now")
  345. continue
  346. }
  347. console.log(`click entry ${i}, ${entry.id}`)
  348. children[0].click()
  349. console.log("waiting...")
  350. await waitGroup[entry.id].wait()
  351. console.log("waiting... done")
  352.  
  353. }
  354. }
  355.  
  356. const acceptDiscord = () => {
  357. const localUrl = window.document.location.href
  358. if (!localUrl || (localUrl.indexOf("discord.com/invite/") == -1
  359. && localUrl.indexOf("discord.gg/") == -1)) {
  360. console.log('it is not a discord invite link')
  361. return
  362. }
  363. const btn = document.querySelector("button")
  364. if (!btn) {
  365. console.log('discord invite link has no button')
  366. return
  367. }
  368. btn.click()
  369.  
  370. let catchWin = window
  371.  
  372. setTimeout(() => {
  373. if (catchWin.document.body.innerHTML.indexOf("Continue to Discord") != -1) {
  374. catchWin.location.href = "https://google.com"
  375. }
  376.  
  377.  
  378. }, 5000)
  379. }
  380.  
  381.  
  382. (function () {
  383. 'use strict';
  384.  
  385. if (window.location.href.indexOf("google") != -1 && window.location.href.indexOf("formResponse") != -1) {
  386. console.log("google response form")
  387. return
  388. }
  389.  
  390. let windowLoaded = false
  391. let checkTimeout = 5 * 1000
  392. const checkWindowLoadingTimeoutFunc = async () => {
  393. console.log('check window timeout...')
  394. await sleep(checkTimeout)
  395. console.log('check window timeout...++++')
  396. if (!windowLoaded) {
  397. window.location.reload()
  398. }
  399. }
  400. checkWindowLoadingTimeoutFunc()
  401. window.onload = async () => {
  402. windowLoaded = true
  403. console.log('loading')
  404. await sleep(2000)
  405. let account = undefined
  406.  
  407. if (window.localStorage) {
  408. account = JSON.parse(window.localStorage.getItem("monkey_accountData"))
  409. }
  410. console.log('current account', account && account.eth)
  411. insertBtns(account)
  412. // answer questions
  413. answerSnatTest01()
  414. // answer molehack
  415. answerMoleHack()
  416. // click gleam
  417. autoClickGleam(account)
  418.  
  419. acceptDiscord()
  420.  
  421. const listWraper = document.getElementsByClassName("o3Dpx")[0]
  422. if (!listWraper) {
  423. return
  424. }
  425. const list = listWraper.children
  426. console.log(`list item len ${list.length}`)
  427. if (!list || !list.length) {
  428. return
  429. }
  430. for (let question of list) {
  431. const text = question.innerHTML.toLowerCase()
  432. let inputs = question.querySelectorAll("input")
  433. console.log('text', text.length, inputs, inputs.length)
  434. if (!inputs || inputs.length != 1) {
  435. inputs = question.querySelectorAll("textarea")
  436. if (!inputs || inputs.length != 1) {
  437. console.log('wrong inputs', inputs)
  438. continue
  439. }
  440. }
  441. const field = inputs[0]
  442. if (text.indexOf("email") != -1 || text.indexOf("邮件") != -1) {
  443. field.focus()
  444. document.execCommand('insertText', false, account.email);
  445. continue
  446. }
  447.  
  448. if (text.indexOf("wallet") != -1 || text.indexOf("address") != -1 || text.indexOf("钱包") != -1) {
  449. field.focus()
  450. document.execCommand('insertText', false, account.eth);
  451. continue
  452. }
  453.  
  454. if (text.indexOf("link") != -1 || text.indexOf("retweet") != -1) {
  455. if (text.indexOf("username") != -1) {
  456. field.focus()
  457. document.execCommand('insertText', false, `@${account.twitter}`);
  458. continue
  459. }
  460. field.focus()
  461. document.execCommand('insertText', false, account.twitterProfile);
  462. continue
  463. }
  464.  
  465. if (text.indexOf("telegram") != -1 || text.indexOf("twitter") != -1 || text.indexOf("推特") != -1 || text.indexOf("nickname") != -1) {
  466. field.focus()
  467. document.execCommand('insertText', false, `@${account.twitter}`);
  468. continue
  469. }
  470.  
  471. if (text.indexOf("discord") != -1) {
  472. field.focus()
  473. document.execCommand('insertText', false, account.discord);
  474. continue
  475. }
  476. if (text.indexOf("ideas") != -1) {
  477. field.focus()
  478. document.execCommand('insertText', false, 'no');
  479. continue
  480. }
  481.  
  482. }
  483. }
  484. })();