Gustav Bylund

+46 (0)73 026 26 86 hello@gustavbylund.se maistho

Cookie Clicker Cheats

Cheat bookmarklet for cookie clicker

Bookmarklet

Drag the following link to your bookmark bar!

Cookies

Or add this code to a bookmark:

javascript:(()=>{(async function(){Game.mods?.CookieMonster||Game.LoadMod("https://cookiemonsterteam.github.io/CookieMonster/dist/CookieMonster.js"),await new Promise(o=>{const a=setInterval(()=>{Game.mods.CookieMonster&&Game.mods.cookieMonsterFramework&&window.cookieMonsterFrameworkData?.isInitializing===!1&&(o(),clearInterval(a))},1e3)});function r(o){const a=e=>([t,i])=>({canBuy:Game.cookies>=i.price,buyFn:()=>Game.Objects[t].buy(e),color:i.colour,type:"building"}),s=()=>([e,t])=>({canBuy:Game.Upgrades[e].canBuy()&&["cookie",""].includes(Game.Upgrades[e].pool),color:t.colour,buyFn:()=>Game.Upgrades[e].buy(),type:"upgrade"}),n=[...Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings.PPRigidelMode?[]:Object.entries(o.Objects1).map(a(1)),...Object.entries(o.Objects10).map(a(10)),...Object.entries(o.Objects100).map(a(100)),...Object.entries(o.Upgrades).map(s())].filter(e=>e.canBuy&&(e.color==="Blue"||e.color==="Green"||e.color==="Gray"));return n.sort((e,t)=>e.color.localeCompare(t.color)),n.length?(n[0].buyFn(),!0):!1}window.maisthoCheats?(window.maisthoCheats.forEach(o=>clearInterval(o)),delete window.maisthoCheats,Game.Notify("Autoclicking Disabled","Press the bookmarklet again to activate autoclicking",[10,6],3,!0)):(window.maisthoCheats=[setInterval(()=>Game.ClickCookie(),25),setInterval(()=>Game.shimmers.forEach(o=>["golden","reindeer"].includes(o.type)&&o.pop()),1e3),setInterval(()=>{window.CookieMonsterData&&r(window.CookieMonsterData)},4e3)],Game.Notify("Autoclicking Enabled","Press the bookmarklet again to disable autoclicking",[10,6],3,!0))})();})();

Full code available below:

interface BuildingData {
  bonus: number
  colour: string
  pp: number
  price: number
}

interface UpgradeData {
  bonus?: number
  bonusMouse: number
  colour: string
  pp: number | null
}

interface CookieMonsterData {
  Objects1: Record<string, BuildingData>
  Objects10: Record<string, BuildingData>
  Objects100: Record<string, BuildingData>
  Upgrades: Record<string, UpgradeData>
}

declare interface Window {
  maisthoCheats?: any[] | undefined
  cookieMonsterFrameworkData?: { isInitializing?: boolean } | undefined
  CookieMonsterData?: CookieMonsterData
}

declare const Game: any
;(async function () {
  if (!Game.mods?.CookieMonster) {
    Game.LoadMod(
      'https://cookiemonsterteam.github.io/CookieMonster/dist/CookieMonster.js',
    )
  }

  await new Promise<void>((r) => {
    const timer = setInterval(() => {
      if (
        Game.mods.CookieMonster &&
        Game.mods.cookieMonsterFramework &&
        window.cookieMonsterFrameworkData?.isInitializing === false
      ) {
        r()
        clearInterval(timer)
      }
    }, 1000)
  })

  function purchaseBestIfPossible(data: CookieMonsterData): boolean {
    const buildingMapFn =
      (amount: number) =>
      ([k, v]: [string, BuildingData]) => {
        return {
          canBuy: Game.cookies >= v.price,
          buyFn: () => Game.Objects[k].buy(amount),
          color: v.colour,
          type: 'building',
        } as const
      }
    const upgradeMapFn =
      () =>
      ([k, v]: [string, UpgradeData]) => {
        return {
          canBuy:
            Game.Upgrades[k].canBuy() &&
            ['cookie', ''].includes(Game.Upgrades[k].pool),
          color: v.colour,
          buyFn: () => Game.Upgrades[k].buy(),
          type: 'upgrade',
        } as const
      }
    const objects: {
      canBuy: boolean
      buyFn: () => void
      color: string
      type: 'upgrade' | 'building'
    }[] = [
      // Don't consider 1-stacks if PPRigidelMode is on
      ...(Game.mods.cookieMonsterFramework.saveData.cookieMonsterMod.settings
        .PPRigidelMode
        ? []
        : Object.entries(data.Objects1).map(buildingMapFn(1))),
      ...Object.entries(data.Objects10).map(buildingMapFn(10)),
      ...Object.entries(data.Objects100).map(buildingMapFn(100)),
      ...Object.entries(data.Upgrades).map(upgradeMapFn()),
    ].filter(
      (obj) =>
        obj.canBuy &&
        (obj.color === 'Blue' || obj.color === 'Green' || obj.color === 'Gray'),
    )

    objects.sort((a, b) => a.color.localeCompare(b.color)) // Luckily, blue < gray < green
    if (objects.length) {
      objects[0].buyFn()
      return true
    }
    return false
  }

  if (window.maisthoCheats) {
    window.maisthoCheats.forEach((c) => clearInterval(c))
    delete window.maisthoCheats
    Game.Notify(
      'Autoclicking Disabled',
      'Press the bookmarklet again to activate autoclicking',
      [10, 6],
      3,
      true,
    )
  } else {
    window.maisthoCheats = [
      // Autoclicker
      setInterval(() => Game.ClickCookie(), 25),

      // Auto golden clicker
      setInterval(
        () =>
          Game.shimmers.forEach(
            (shimmer: any) =>
              ['golden', 'reindeer'].includes(shimmer.type) && shimmer.pop(),
          ),
        1000,
      ),

      // Auto buyer
      setInterval(() => {
        if (!window.CookieMonsterData) {
          return
        }
        purchaseBestIfPossible(window.CookieMonsterData)
      }, 4000),
    ]

    Game.Notify(
      'Autoclicking Enabled',
      'Press the bookmarklet again to disable autoclicking',
      [10, 6],
      3,
      true,
    )
  }
})()