Skip to content

Instantly share code, notes, and snippets.

@ytoune
Last active December 11, 2020 01:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytoune/83f28a6d887fab64dd830aba6f29a7dd to your computer and use it in GitHub Desktop.
Save ytoune/83f28a6d887fab64dd830aba6f29a7dd to your computer and use it in GitHub Desktop.
PHP関数名しりとりをチートで倒す

PHP関数名しりとりをチートして倒します

コード

下記を開発者向けコンソールに入れます

(async () => {

/** @type {Record<string, [string, string]>} */
const data = await fetch("/regex.json").then(r => r.json())
/** @type {Record<string, boolean>} */
const sayed = {}
const sleep = (/** @type {number} */ s) => new Promise(r => setTimeout(r, s))

const action = async () => {
  const ipt = document.querySelector("input")
  if (!ipt) return console.log("no ipt")
  const divs = [...document.querySelectorAll(".text-center")]
    .some(s => s.textContent.match(/^記録/iu))
  if (divs) return console.log("exists div")
  const list = [...document.querySelectorAll(".rounded-xl > .p-2")]
    .map(r => (r.textContent || '').trim())
  list.forEach(s => sayed[s] = true)
  const startWords = Object.values(data).filter(s => !sayed[s]).reduce((r, p) => {
    const s = p[0].slice(0, 1).toLowerCase()
    return { ...r, [s]: (r[s] || 0) + 1 }
  }, {})
  /** 次の選択肢の数を数える */
  const rate = (/** @type {string} */ word) => startWords[word.slice(-1).toLowerCase()] || 0
  const w = ipt.placeholder.trim().slice(0, 1)
  const ws = Object.values(data).map(s => s[0])
    .filter(k => !sayed[k] && k.startsWith(w) && /[a-z]$/ui.test(k))
  if (!ws.length) return console.log("no words", { ws, w })
  ws.sort((q, w) => rate(q) - rate(w))
  ipt.value = ws[0] // 次の選択肢がもっとも少ないワードを選ぶ
  // ipt.value = ws[Math.floor(Math.random() * ws.length)] // ランダムにすると長く続いて面白い
  ipt.dispatchEvent(new CustomEvent("input", { bubbles: true }))
  await sleep(5)
  ipt.closest("form").dispatchEvent(new CustomEvent("submit", { bubbles: true }))
  await sleep(500)
  action()
}

action()

})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment