AutoCompleteForm

AScript!

目前為 2022-04-15 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name AutoCompleteForm
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.143
  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 handleGleamEntry = async (entry, accountData) => {
  119. const innerText = entry.innerHTML.toLowerCase()
  120. const continuBtn = entry.querySelector("button")
  121. console.log('continuBtn', continuBtn)
  122. if (continuBtn) {
  123. continuBtn.click()
  124. await sleep(5000)
  125. return
  126. }
  127.  
  128. const textareaItem = entry.querySelector("textarea")
  129. if (!textareaItem) {
  130. return
  131. }
  132. textareaItem.focus()
  133. if (
  134. innerText.indexOf("address") != -1 ||
  135. innerText.indexOf("wallet") != -1 ||
  136. innerText.indexOf("polygon") != -1 ||
  137. innerText.indexOf("ethereum") != -1 ||
  138. innerText.indexOf("bsc") != -1
  139. ) {
  140. document.execCommand('insertText', false, accountData.eth);
  141. } else if (innerText.indexOf("discord") != -1) {
  142. document.execCommand('insertText', false, accountData.discord);
  143. } else if (innerText.indexOf("twitter") != -1) {
  144. document.execCommand('insertText', false, `@${accountData.twitter}`);
  145. } else if (innerText.indexOf("color of the hat") != -1) {
  146. document.execCommand('insertText', false, "blue");
  147. } else {
  148. document.execCommand('insertText', false, accountData.email);
  149. }
  150.  
  151. await sleep(2000)
  152. const continueBtns = entry.getElementsByClassName("btn btn-primary")
  153. if (continueBtns && continueBtns.length) {
  154. continueBtns[0].click()
  155. await sleep(2000)
  156. }
  157. }
  158.  
  159. const autoClickGleam = async (accountData) => {
  160. if (!accountData) {
  161. return
  162. }
  163. const localUrl = window.document.location.href
  164. if (!localUrl || localUrl.indexOf("gleam.io") == -1) {
  165. return
  166. }
  167. console.log('gleam loading start')
  168. const entryList = document.getElementsByClassName("entry-method")
  169. console.log('all entry count', entryList.length)
  170. if (!entryList || !entryList.length) {
  171. return
  172. }
  173. for (let entry of entryList) {
  174. var observer = new MutationObserver(async function (mutations) {
  175. for (let mutation of mutations) {
  176.  
  177. const className = mutation.target.className
  178. console.log('entry class onChange', className, mutation)
  179. if (className.indexOf("completed-entry-method") != -1) {
  180. return
  181. }
  182.  
  183. if (className.indexOf("expanded") == -1) {
  184. console.log("no expanded")
  185. return
  186. }
  187.  
  188. await handleGleamEntry(mutation.target, accountData)
  189.  
  190.  
  191. }
  192. });
  193.  
  194. observer.observe(entry, {
  195. attributes: true,
  196. attributeFilter: ['class']
  197. });
  198. }
  199. console.log('gleam add watch done')
  200. for (let i = 0; i < entryList.length; i++) {
  201. const entry = entryList[i]
  202. const children = entry.children
  203. if (!children || !children.length) {
  204. continue
  205. }
  206. console.log(`entry ${i}, class ${entry.className}`)
  207.  
  208. if (entry.className.indexOf("completed-entry-method") != -1) {
  209. console.log("completed entry", entry.className)
  210. continue
  211. }
  212.  
  213. if (entry.className.indexOf("expanded") != -1) {
  214. console.log("expanded entry", i)
  215. await handleGleamEntry(entry, accountData)
  216. await sleep(10000)
  217. continue
  218. }
  219.  
  220. }
  221. for (let i = 0; i < entryList.length; i++) {
  222. const entry = entryList[i]
  223. const children = entry.children
  224. if (!children || !children.length) {
  225. continue
  226. }
  227. if (entry.className.indexOf("completed-entry-method") != -1) {
  228. console.log("completed entry", i, entry.className)
  229. continue
  230. }
  231.  
  232. if (entry.className.indexOf("expanded") != -1) {
  233. console.log("expanded entry second loop", i)
  234. await handleGleamEntry(entry, accountData)
  235. continue
  236. }
  237. const innerText = entry.innerHTML.toLowerCase()
  238. if (innerText.indexOf("invite") != -1 || innerText.indexOf("extra entries") != -1) {
  239. console.log("invite link")
  240. continue
  241. }
  242. if (innerText.indexOf("secret code") != -1) {
  243. console.log("skip secret code now")
  244. continue
  245. }
  246. console.log(`click entry ${i}`)
  247. children[0].click()
  248. await sleep(3000)
  249. }
  250. }
  251.  
  252. const acceptDiscord = () => {
  253. const localUrl = window.document.location.href
  254. if (!localUrl || (localUrl.indexOf("discord.com/invite/") == -1
  255. && localUrl.indexOf("discord.gg/") == -1)) {
  256. console.log('it is not a discord invite link')
  257. return
  258. }
  259. const btn = document.querySelector("button")
  260. if (!btn) {
  261. console.log('discord invite link has no button')
  262. return
  263. }
  264. btn.click()
  265.  
  266. let catchWin = window
  267.  
  268. setTimeout(() => {
  269. if (catchWin.document.body.innerHTML.indexOf("Continue to Discord") != -1) {
  270. catchWin.location.href = "https://google.com"
  271. }
  272.  
  273.  
  274. }, 5000)
  275. }
  276.  
  277.  
  278. (function () {
  279. 'use strict';
  280.  
  281. if (window.location.href.indexOf("google") != -1 && window.location.href.indexOf("formResponse") != -1) {
  282. console.log("google response form")
  283. return
  284. }
  285.  
  286. let windowLoaded = false
  287. let checkTimeout = 5 * 1000
  288. const checkWindowLoadingTimeoutFunc = async () => {
  289. console.log('check window timeout...')
  290. await sleep(checkTimeout)
  291. console.log('check window timeout...++++')
  292. if (!windowLoaded) {
  293. window.location.reload()
  294. }
  295. }
  296. checkWindowLoadingTimeoutFunc()
  297. window.onload = async () => {
  298. windowLoaded = true
  299. console.log('loading')
  300. await sleep(2000)
  301. let account = undefined
  302.  
  303. if (window.localStorage) {
  304. account = JSON.parse(window.localStorage.getItem("monkey_accountData"))
  305. }
  306. console.log('current account', account && account.eth)
  307. insertBtns(account)
  308. // answer questions
  309. answerSnatTest01()
  310. // click gleam
  311. autoClickGleam(account)
  312.  
  313. acceptDiscord()
  314.  
  315. const listWraper = document.getElementsByClassName("o3Dpx")[0]
  316. if (!listWraper) {
  317. return
  318. }
  319. const list = listWraper.children
  320. console.log(`list item len ${list.length}`)
  321. if (!list || !list.length) {
  322. return
  323. }
  324. for (let question of list) {
  325. const text = question.innerHTML.toLowerCase()
  326. let inputs = question.querySelectorAll("input")
  327. console.log('text', text.length, inputs, inputs.length)
  328. if (!inputs || inputs.length != 1) {
  329. inputs = question.querySelectorAll("textarea")
  330. if (!inputs || inputs.length != 1) {
  331. console.log('wrong inputs', inputs)
  332. continue
  333. }
  334. }
  335. const field = inputs[0]
  336. if (text.indexOf("email") != -1 || text.indexOf("邮件") != -1) {
  337. field.focus()
  338. document.execCommand('insertText', false, account.email);
  339. continue
  340. }
  341.  
  342. if (text.indexOf("wallet") != -1 || text.indexOf("address") != -1 || text.indexOf("钱包") != -1) {
  343. field.focus()
  344. document.execCommand('insertText', false, account.eth);
  345. continue
  346. }
  347.  
  348. if (text.indexOf("link") != -1 || text.indexOf("retweet") != -1) {
  349. if (text.indexOf("username") != -1) {
  350. field.focus()
  351. document.execCommand('insertText', false, `@${account.twitter}`);
  352. continue
  353. }
  354. field.focus()
  355. document.execCommand('insertText', false, account.twitterProfile);
  356. continue
  357. }
  358.  
  359. if (text.indexOf("telegram") != -1 || text.indexOf("twitter") != -1 || text.indexOf("推特") != -1 || text.indexOf("nickname") != -1) {
  360. field.focus()
  361. document.execCommand('insertText', false, `@${account.twitter}`);
  362. continue
  363. }
  364.  
  365. if (text.indexOf("discord") != -1) {
  366. field.focus()
  367. document.execCommand('insertText', false, account.discord);
  368. continue
  369. }
  370.  
  371. }
  372. }
  373. })();