AutoCompleteForm

AScript!

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

  1. // ==UserScript==
  2. // @name AutoCompleteForm
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.141
  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. if (entry.className.indexOf("completed-entry-method") != -1) {
  207. console.log("completed entry", entry.className)
  208. continue
  209. }
  210.  
  211. if (entry.className.indexOf("expanded") != -1) {
  212. console.log("expanded entry", i)
  213. await handleGleamEntry(entry, accountData)
  214. continue
  215. }
  216.  
  217. }
  218. for (let i = 0; i < entryList.length; i++) {
  219. const entry = entryList[i]
  220. const children = entry.children
  221. if (!children || !children.length) {
  222. continue
  223. }
  224. if (entry.className.indexOf("completed-entry-method") != -1) {
  225. console.log("completed entry", entry.className)
  226. continue
  227. }
  228.  
  229. if (entry.className.indexOf("expanded") != -1) {
  230. console.log("expanded entry", i)
  231. await handleGleamEntry(entry, accountData)
  232. continue
  233. }
  234. const innerText = entry.innerHTML.toLowerCase()
  235. if (innerText.indexOf("invite") != -1 || innerText.indexOf("extra entries") != -1) {
  236. console.log("invite link")
  237. continue
  238. }
  239. if (innerText.indexOf("secret code") != -1) {
  240. console.log("skip secret code now")
  241. continue
  242. }
  243. console.log('click entry===')
  244. children[0].click()
  245. await sleep(3000)
  246. }
  247. }
  248.  
  249. const acceptDiscord = () => {
  250. const localUrl = window.document.location.href
  251. if (!localUrl || (localUrl.indexOf("discord.com/invite/") == -1
  252. && localUrl.indexOf("discord.gg/") == -1)) {
  253. console.log('it is not a discord invite link')
  254. return
  255. }
  256. const btn = document.querySelector("button")
  257. if (!btn) {
  258. console.log('discord invite link has no button')
  259. return
  260. }
  261. btn.click()
  262.  
  263. let catchWin = window
  264.  
  265. setTimeout(() => {
  266. if (catchWin.document.body.innerHTML.indexOf("Continue to Discord") != -1) {
  267. catchWin.location.href = "https://google.com"
  268. }
  269.  
  270.  
  271. }, 5000)
  272. }
  273.  
  274.  
  275. (function () {
  276. 'use strict';
  277.  
  278. if (window.location.href.indexOf("google") != -1 && window.location.href.indexOf("formResponse") != -1) {
  279. console.log("google response form")
  280. return
  281. }
  282.  
  283. let windowLoaded = false
  284. let checkTimeout = 5 * 1000
  285. const checkWindowLoadingTimeoutFunc = async () => {
  286. console.log('check window timeout...')
  287. await sleep(checkTimeout)
  288. console.log('check window timeout...++++')
  289. if (!windowLoaded) {
  290. window.location.reload()
  291. }
  292. }
  293. checkWindowLoadingTimeoutFunc()
  294. window.onload = async () => {
  295. windowLoaded = true
  296. console.log('loading')
  297. await sleep(2000)
  298. let account = undefined
  299.  
  300. if (window.localStorage) {
  301. account = JSON.parse(window.localStorage.getItem("monkey_accountData"))
  302. }
  303. console.log('current account', account && account.eth)
  304. insertBtns(account)
  305. // answer questions
  306. answerSnatTest01()
  307. // click gleam
  308. autoClickGleam(account)
  309.  
  310. acceptDiscord()
  311.  
  312. const listWraper = document.getElementsByClassName("o3Dpx")[0]
  313. if (!listWraper) {
  314. return
  315. }
  316. const list = listWraper.children
  317. console.log(`list item len ${list.length}`)
  318. if (!list || !list.length) {
  319. return
  320. }
  321. for (let question of list) {
  322. const text = question.innerHTML.toLowerCase()
  323. let inputs = question.querySelectorAll("input")
  324. console.log('text', text.length, inputs, inputs.length)
  325. if (!inputs || inputs.length != 1) {
  326. inputs = question.querySelectorAll("textarea")
  327. if (!inputs || inputs.length != 1) {
  328. console.log('wrong inputs', inputs)
  329. continue
  330. }
  331. }
  332. const field = inputs[0]
  333. if (text.indexOf("email") != -1 || text.indexOf("邮件") != -1) {
  334. field.focus()
  335. document.execCommand('insertText', false, account.email);
  336. continue
  337. }
  338.  
  339. if (text.indexOf("wallet") != -1 || text.indexOf("address") != -1 || text.indexOf("钱包") != -1) {
  340. field.focus()
  341. document.execCommand('insertText', false, account.eth);
  342. continue
  343. }
  344.  
  345. if (text.indexOf("link") != -1 || text.indexOf("retweet") != -1) {
  346. if (text.indexOf("username") != -1) {
  347. field.focus()
  348. document.execCommand('insertText', false, `@${account.twitter}`);
  349. continue
  350. }
  351. field.focus()
  352. document.execCommand('insertText', false, account.twitterProfile);
  353. continue
  354. }
  355.  
  356. if (text.indexOf("telegram") != -1 || text.indexOf("twitter") != -1 || text.indexOf("推特") != -1 || text.indexOf("nickname") != -1) {
  357. field.focus()
  358. document.execCommand('insertText', false, `@${account.twitter}`);
  359. continue
  360. }
  361.  
  362. if (text.indexOf("discord") != -1) {
  363. field.focus()
  364. document.execCommand('insertText', false, account.discord);
  365. continue
  366. }
  367.  
  368. }
  369. }
  370. })();