Code Monkey home page Code Monkey logo

daily-dose's Introduction

Daily Dose Chrome Extension

daily dose icon Get your daily dose of motivation with this chrome extension

Description

Sometimes you need a little dose of positivity or motivation throughout your day. This chrome extension will randomly show you cute/motivational gifs while your using Chrome to help brighten your day and improve your productivity!

Features

Motivational stickers appear in your browser's active tab throughout the day

sticker appearance GIF

After clicking a sticker, a sound is played and the sticker is added to your collection

// Determines if/where a sticker should appear
function stickerAppearance() {
  // Pick random location on screen for sticker to appear
  let yPosition = Math.floor(Math.random() * screen.height);
  let xPosition = Math.floor(Math.random() * screen.width);
  if (yPosition > 300) {
    yPosition = yPosition - 300;
  }
  if (xPosition > 300) {
    xPosition = xPosition - 300;
  }

  const numCollectableGifs = 9;
  // Frequency of gif showing up
  let chance = Math.random();
  // Pick random collectable gif id
  let gifId = selectRandom(1, numCollectableGifs);

  if (chance < 0.5) {
    // Display sticker
    let div = document.createElement("DIV");
    div.id = "cat";
    imgURL = chrome.extension.getURL("images/collect" + gifId + ".gif");
    img.src = imgURL;
    div.style.setProperty("--top-placement", yPosition + "px", "important");
    div.style.setProperty("--left-placement", xPosition + "px", "important");
    div.appendChild(img);
    document.body.appendChild(div);
    div.addEventListener("click", stickerClick);
  }
}

// Selects random int inclusive
function selectRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

// Called when sticker is clicked
function stickerClick() {
  // Play sounds when sicker clicked
  const sound = new Audio();
  sound.src = chrome.extension.getURL("sounds/meow.mp3");
  sound.volume = 0.1;
  sound.play();

  // Replace sticker with heart animation on click
  img.src = chrome.extension.getURL("images/clicked.gif");
  window.setTimeout(function clearImage() {
    img.removeAttribute("src");
  }, 700);

  // Add sticked to collection using Chrome's storage API
  chrome.storage.sync.get("stickers", function (profileObj) {
    var profile = profileObj;
    // console.log("profile " + profile);
    // Check if any stickers have been saved
    if (Object.keys(profile).length === 0) {
      // Add string of imgURL
      chrome.storage.sync.set({ stickers: [imgURL] }, function () {
        // console.log("added to storage");
      });
      var key = imgURL;
      var file = {};
      file[key] = 1;
      chrome.storage.sync.set(file, function () {
        // console.log(imgURL + ":" + 1);
      });
    } else {
      // Seen multiple stickers --> add new sticker
      if (jQuery.inArray(imgURL, profile["stickers"], 0) > -1) {
        chrome.storage.sync.get(imgURL, function (timesSeen) {
          var key = imgURL;
          var file = {};
          file[key] = timesSeen[imgURL] + 1;
          chrome.storage.sync.set(file, function () {
            // console.log(file);
          });
        });
      } else {
        var stickers = profile["stickers"];
        stickers.push(imgURL);
        chrome.storage.sync.set({ stickers: stickers }, () => {
          // console.log("added sticker to storage");
        });
        var key = imgURL;
        var file = {};
        file[key] = 1;
        chrome.storage.sync.set(file, function () {
          // console.log(file);
        });
      }
    }
  });
}

Custom new tab page where you can view the stickers you've collected

Chrome extension popup with a heart image to show how many times you've clicked on that sticker

Permissions

  • Replace the page you see when opening a new tab
  • Read your browsing history

Technologies

  • Chrome's Storage API
  • JavaScript
  • jQuery
  • HTML
  • CSS

Future Work

  • Options page
    • Turn on/off for specifc website
    • Change new tab background
  • Todos widget on new tab page
  • Add bookmarks widget to new tab page

Credits

daily-dose's People

Contributors

sara-ls avatar jamesnghiem avatar jasonjyeung avatar pkmnfreak avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.