Skip to content
A node module that uses Google's Puppeteer library to visit your Stack Overflow profile and check the progress of the badge you are currently tracking.
Branch: master
Clone or download
Latest commit 986dbab Jul 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.editorconfig Initial Commit Jul 3, 2019
.gitignore Initial Commit Jul 3, 2019
.travis.yml Initial Commit Jul 3, 2019
index.js Initial Commit Jul 3, 2019
license.md Initial Commit Jul 3, 2019
package-lock.json Initial Commit Jul 3, 2019
package.json Initial Commit Jul 3, 2019
readme.md Initial Commit Jul 3, 2019

readme.md

Stack Fanatic

npm package version Travis build status npm package downloads code style license

A node module that uses Google's Puppeteer library to visit your Stack Overflow profile and check the progress of the badge you are currently tracking.

Installation

npm install stack-fanatic

Usage

Options

The following options can be passed to any functions (however none of them are required):

  • debug - A boolean stating wether or not debugging information should be displayed in the console (Default: false)

  • loginEmail - A string containing the email address asssociated with the StackOverflow account that you would like to log in to.

  • loginPassword - A string containing the password for the StackOverflow account that you would like to log in to.

  • puppeteerOpts - An object containing any options you wish to pass to the puppeteer.launch() function. (Sets the user agent to Google Chrome and the user data directory to ./userData by default)

  • site - A string containing the URL for the Stack Exchange site that you would like to pull badge info from. Should include the protocol at the beginning and no trailing slash. (Default: https://stackoverflow.com)

check(options)

Visits your StackOverflow profile page and returns a promise that resolves with information about your tracked badge.

Note: The login function will automatically be ran if loginEmail and loginPassword are passed as options and you are not currently logged in.

const stackFanatic = require('stack-fanatic')

stackFanatic
  .check({
    loginEmail: 'example@email.com',
    loginPassword: 'password1234',
    site: 'https://stackoverflow.com'
  })
  .then(res => {
    console.log('Badge Name:', res.badge)
    console.log('Badge Type:', res.type)
    console.log('Current Progress:', res.now)
    console.log('Percent Completed:', res.percent)
  })
  .catch(err => {
    console.log(err.message)
  })

Example Response

{
  badge: 'Fanatic',
  max: 100,
  min: 0,
  now: 20,
  percent: 20,
  profile: 'https://stackoverflow.com/users/5463842/kodie-grantham',
  type: 'Gold'
}

login(options)

Logs into a StackOverflow account and returns a promise that resolves with true or false depending on if the login was successful or not.

Note: After you are logged in, your session info will be saved in ./userData so that you can run the check function without having to log in again.

const stackFanatic = require('stack-fanatic')

stackFanatic
  .login({
    loginEmail: 'example@email.com',
    loginPassword: 'password1234'
  })
  .then(loggedIn => {
    if (loggedIn) {
      console.log('Yay! You are logged in! :D')
    } else {
      console.log('Aw dang! You are not logged in. :(')
    }
  })
  .catch(err => {
    console.log(err.message)
  })

Tips/Tricks

Check badge progress without logging in

Just set site to the URL of your Stack Overflow profile and make sure that you have ?tab=topactivity at the end of it.

While you're at it, set Puppeteer's userDataDir option to false so that no session data or cache is saved.

stackFanatic
  .check({
    site: 'https://stackoverflow.com/users/5463842/kodie-grantham?tab=topactivity',
    puppeteerOpts: {
      userDataDir: false
    }
  })

Related

License

MIT. See the LICENSE file for more info.

You can’t perform that action at this time.