Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function() {
- "use strict";
- /** Constants. */
- var CLICK = 'click';
- var BUTTON = 'button';
- /** State. */
- var state = {};
- state.clicks = {
- current: 0,
- total: 0
- };
- state.cursor = {
- // image: 'https://repl.it/public/images/icon-square.png',
- message: 'Your REPL creating ability has improved',
- owned: 1,
- cost: {
- base: 100,
- rate: 2
- },
- output: {
- base: 2,
- current: 1
- }
- };
- /** @see {@link https://coderpatsy.bitbucket.io/cookies/cookies.html} */
- state.generators = {
- evalbot: {
- image: 'https://repl.it/public/images/bot.png', // 'https://repl.it/public/images/evalbot/evalbot_43.png',
- message: 'Evalbot is creating REPLs via Slack',
- owned: 0,
- delay: 10,
- cost: {
- base: 15,
- rate: 1.2
- },
- output: {
- base: 10,
- current: 0
- }
- },
- katyadee: {
- image: 'https://repl.it/public/images/katya.png',
- message: 'Katya Delaney is fostering the Repl.it community',
- owned: 0,
- delay: 1,
- cost: {
- base: 1e2, // 100
- rate: 1.15
- },
- output: {
- base: 1,
- current: 0
- }
- },
- basicer: {
- image: 'https://repl.it/public/images/rob.png',
- message: 'Rob Blanckaert is engineering REPLs',
- owned: 0,
- delay: 1,
- cost: {
- base: 11e2, // 1,100
- rate: 1.15
- },
- output: {
- base: 8,
- current: 0
- }
- },
- timmy_i_chen: {
- image: 'https://repl.it/public/images/tim.png',
- message: 'Tim Chen joined Repl.it as the Chief Snack Officer--worker productivity increases',
- owned: 0,
- delay: 1,
- cost: {
- base: 12e3, // 12,000
- rate: 1.15
- },
- output: {
- base: 47,
- current: 0
- }
- },
- masfrost: {
- image: 'https://repl.it/public/images/faris.jpg',
- message: 'Faris Masad enjoys breaking REPLs for fun',
- owned: 0,
- delay: 1,
- cost: {
- base: 13e4, // 130,000
- rate: 1.15
- },
- output: {
- base: 260,
- current: 0
- }
- },
- turbio: {
- image: 'https://repl.it/public/images/mason.png',
- message: 'Mason Clayton is hacking on REPLs',
- owned: 0,
- delay: 1,
- cost: {
- base: 14e5, // 1,400,000
- rate: 1.15
- },
- output: {
- base: 14e2, // 1,400
- current: 0
- }
- },
- hayaodeh: {
- image: 'https://repl.it/public/images/haya.jpg',
- message: 'Haya Odeh is envisioning the next product of Repl.it',
- owned: 0,
- delay: 1,
- cost: {
- base: 2e7, // 20,000,000
- rate: 1.15
- },
- output: {
- base: 78e2, // 7,800
- current: 0
- }
- },
- amasad: {
- image: 'https://repl.it/public/images/amjad.jpg',
- message: 'Amjad Masad has architected a new infrastructure that scales Repl.it indefinitely at minimal cost',
- owned: 0,
- delay: 1,
- cost: {
- base: 33e7, // 330,000,000
- rate: 1.15
- },
- output: {
- base: 44e3, // 44,000
- current: 0
- }
- }
- };
- state.messages = {
- 1: 'Humans: *exist*',
- 5: 'Communication allows other humans to yeet',
- 10: 'Milestone: Ten REPLs have been created',
- 25: 'You share your REPLs on Hacker News to get feedback',
- 50: 'YC partner: "an online REPL is not really a startup -- it\'s just a fun toy"',
- 75: 'A public API for Repl.it has been released',
- 100: 'Milestone: One hundred REPLs have been created',
- 150: 'Added feature that allows users to embed REPLs on other sites--traffic increases',
- 200: 'The Repl.it service is monetized by selling the code evaluation infrastructure as an API',
- 300: 'You raise a seed round with the backing of Roy Bahat from Bloomberg Beta',
- 400: 'The autocomplete feature is released, improving user experience--power users increase',
- 500: 'API docs for Repl.it are published--developers begin to explore the features',
- 600: 'You create a tool for computer science teachers to manage their classrooms',
- 700: 'Scheduled assignments have been added to Repl.it Classroom',
- 800: 'Due dates have been added to scheduled assignments--teachers rejoice but students despair',
- 900: 'Added the ability to import packages for any language',
- 1000: 'Milestone: One thousand REPLs have been created',
- 1100: 'Repl.it starts to form a small following',
- 1250: 'Introduced linting support for languages--users start to get lazy',
- 1500: 'Improved vertical scaling of the Repl.it service due to OutOfMemoryError',
- 1750: 'Switched to horizontal scaling to minimize single point of failure',
- 2000: 'More languages have been added to Repl.it',
- 2500: 'Set up Codedeploy to automate auto scaling of REPLs',
- 3000: 'Switched devops automation to Ansible--now REPLs can be launched faster than before',
- 3500: 'Improved REPL debugging experience',
- 4000: 'Introduced live file updates--users call this black magic',
- 5000: 'Added collaboration feature--users now use Repl.it as a dating site alternative',
- 6000: 'Haskell has been added as a REPL supported language',
- 7000: 'Clojure has been added as a REPL supported language',
- 8000: 'Users are creating videos tutorials on YouTube and Twitch.tv, which broadens the audience for Repl.it',
- 9000: 'Repl.it Multiplayer is out',
- 10000: 'Milestone: Ten thousand REPLs have been created',
- 11000: 'A large following starts to form for Repl.it',
- 12000: 'Repl.it is finally accepted into Y Combinator after many rejections',
- 13000: 'Repl.it has graduated from Y Combinator',
- 14000: 'Repl.it just raised $4.5M from venture capitalists',
- 15000: 'Repl.it Discord server is blowing up',
- 16000: 'Repl.it hosts its first ever code jam',
- 17000: 'The REPL IDE now takes less than 2 seconds to load',
- 18000: 'Work is done to improve the Repl.it container orchestration system',
- 19000: 'HTTPS-ready custom domains are available for web/app REPLs--users cancel their GoDaddy hosting',
- 20000: 'Workspace update: introduced automatic formatter for REPL',
- 30000: 'Workspace update: support uploading files to REPL',
- 40000: 'Workspace update: allow downloading files from REPL',
- 50000: 'All coding interviews are administered on Repl.it',
- 60000: 'Repl.it infrastructure now does continuous deployment',
- 70000: 'Added plugin support to REPL IDE--3rd-party developers celebrate',
- 80000: 'REPLs now autosave--users remark that this is witchcraft',
- 90000: 'REPLs now display the history of revisions',
- 100000: 'Milestone: One hundred thousand REPLs have been created',
- 110000: 'Repl.it rises up the ranks of Alexa',
- 200000: 'Repl.it is the largest unicorn to date',
- 500000: 'Repl.it went through one of the largest IPO in history--it is now a publicly traded company',
- 600000: 'Stockholders of Repl.it have all become millionaires',
- 700000: 'Repl.it has announced its own coin called replcoin',
- 800000: 'replcoin has surpassed the value of bitcoin by 10x',
- 900000: 'replcoin has become the primary currency of the world',
- 1000000: 'Milestone: One million REPLs have been created',
- 2000000: 'Repl.it is now mainstream',
- 3000000: 'Stockholders Repl.it have all become billionaires',
- 4000000: 'Economists state that with Repl.it around, a recession will no longer occur',
- 5000000: 'Repl.it has become self-aware',
- 6000000: 'Repl.it takes over all of manufacturing',
- 7000000: 'Futurists say that there is nothing that Repl.it cannot do',
- 8000000: 'Environmental scientists say that Repl.it is reversing global warming',
- 9000000: 'Studies show that creating REPLs reverses aging',
- 10000000: 'Milestone: Ten million REPLs have been created',
- 11000000: 'All education has been replaced with Repl.it',
- 20000000: 'Repl.it has cured cancer',
- 30000000: 'Repl.it solved world hunger',
- 40000000: 'World peace has been achieved by Repl.it',
- 50000000: 'Repl.it infrastructure moves from the cloud to the moon',
- 60000000: 'Repl.it becomes the primary religion of planet Earth',
- 70000000: 'Quantum technology allows Repl.it to create wormholes',
- 80000000: 'Scientists say that Repl.it will lead humanity to the singularity',
- 90000000: 'Repl.it unearths the secrets to immortality',
- 100000000: 'Milestone: One hundred million REPLs have been created',
- 200000000: 'Repl.it explores the solar system',
- 300000000: 'Repl.it explores the quantum realm',
- 400000000: 'Repl.it explores the quantum realm',
- 500000000: 'Repl.it explores time travel via its history feature',
- 1000000000: 'Milestone: One billion REPLs have been created',
- 2000000000: 'Repl.it has turned into a black hole',
- 3000100000: '...'
- };
- // set `next` value for cursor `cost` and `output`
- state.cursor.cost.next = state.cursor.cost.base;
- state.cursor.output.next = state.cursor.output.base;
- // set `next` value for generators `cost` and `output`
- Object.keys(state.generators).forEach(function(id) {
- var generator = state.generators[id];
- generator.cost.next = generator.cost.base;
- generator.output.next = generator.output.base;
- });
- /** Elements. */
- var elements = {
- button: document.getElementById('button'),
- counter: document.getElementById('counter'),
- cursor: document.getElementById('upgrade'),
- message: document.getElementById('message'),
- store: document.getElementById('store')
- };
- Object.keys(state.generators).forEach(function(id) {
- var generatorNode = elements.cursor.cloneNode(true);
- generatorNode.id = id;
- var button = generatorNode.querySelector(BUTTON);
- button.title = '@' + id;
- button.style.backgroundImage = 'url("' + state.generators[id].image + '")';
- elements.store.appendChild(generatorNode);
- });
- /** Helpers. */
- /**
- * @param {Number} base
- * @param {Number} rate
- * @param {Number} owned
- * @return {Number}
- */
- function calculateNextCost(base, rate, owned) {
- return Math.floor(base * Math.pow(rate, owned));
- };
- /**
- * @param {String} id
- * @return {HTMLElement}
- */
- function getElementById(id) {
- return elements[id] ? elements[id] : elements[id] = document.getElementById(id);
- };
- /**
- * @param {Number} clicks
- * @param {Number} seconds
- * @return {String}
- */
- function formatGeneratorOutput(clicks, seconds) {
- // N per N second(s)
- return [
- clicks ? '+' : '',
- clicks.toLocaleString(),
- ' / ',
- seconds.toLocaleString(),
- seconds === 1 ? ' second' : ' seconds'
- ].join('');
- };
- /** Views. */
- var views = {
- renderCounter: function() {
- elements.counter.innerText = state.clicks.current.toLocaleString();
- },
- renderCursor: function() {
- var cursorRow = elements.cursor;
- var cursor = state.cursor;
- cursorRow.querySelector('.owned').innerText = (cursor.owned - 1).toLocaleString();
- cursorRow.querySelector('.cost').innerText = cursor.cost.next.toLocaleString();
- cursorRow.querySelector('.output-current').innerText = '+' + cursor.output.current.toLocaleString() + ' / click';
- cursorRow.querySelector('.output-next').innerText = '+' + cursor.output.next.toLocaleString() + ' / click';
- },
- /**
- * @param {String} id
- */
- renderGenerator: function(id) {
- var generator = state.generators[id];
- var generatorRow = getElementById(id);
- generatorRow.querySelector('.owned').innerText = generator.owned.toLocaleString();
- generatorRow.querySelector('.cost').innerText = generator.cost.next.toLocaleString();
- generatorRow.querySelector('.output-current').innerText = formatGeneratorOutput(generator.output.current, generator.delay);
- generatorRow.querySelector('.output-next').innerText = formatGeneratorOutput(generator.output.next, generator.delay);
- },
- renderGenerators: function() {
- Object.keys(state.generators).forEach(function(id) {
- views.renderGenerator(id);
- });
- },
- /**
- * @param {String} [text]
- */
- renderMessage: function(text) {
- var total = state.clicks.total;
- var message;
- if (text) {
- message = text;
- } else {
- // check for exact match in messages table
- if (state.messages[total]) {
- message = state.messages[total];
- delete state.messages[total];
- } else {
- // otherwise compare number of first message
- for (var key in state.messages) {
- if (total >= key) {
- message = state.messages[key];
- delete state.messages[key];
- }
- break;
- }
- }
- }
- if (!message) {
- return;
- }
- message = message.toLocaleString();
- if (message !== elements.message.innerText) {
- elements.message.innerText = message;
- }
- }
- };
- /** Actions. */
- var actions = {
- /**
- * @param {Number} number
- * @param {Boolean} [skipTotal]
- */
- increment: function(number, skipTotal) {
- var clicks = state.clicks;
- clicks.current += number;
- /*LOCALSTORAGE*/
- localStorage.setItem('state', state=${state};
- if (!skipTotal) {
- clicks.total += number;
- views.renderMessage();
- }
- views.renderCounter();
- var cursorButton = elements.cursor.querySelector(BUTTON);
- cursorButton.disabled = clicks.current < state.cursor.cost.next;
- var generators = state.generators;
- Object.keys(generators).forEach(function(id) {
- var generatorRow = getElementById(id);
- var generatorButton = generatorRow.querySelector(BUTTON);
- generatorButton.disabled = clicks.current < generators[id].cost.next;
- });
- },
- /**
- * @param {Number} clicks
- */
- decrement: function(clicks) {
- actions.increment(-clicks, true);
- /*LOCALSTORAGE*/
- localStorage.setItem('state', state=${state};
- },
- updateCursor: function() {
- var cursor = state.cursor;
- var cost = cursor.cost;
- var output = cursor.output;
- var owned = ++cursor.owned;
- cost.next = calculateNextCost(cost.base, cost.rate, owned - 1);
- output.current = output.next;
- output.next = Math.round(output.base * owned);
- views.renderCursor();
- },
- /**
- * @param {String} id
- */
- updateGenerator: function(id) {
- var generator = state.generators[id];
- var cost = generator.cost,
- output = generator.output;
- var owned = ++generator.owned;
- cost.next = calculateNextCost(cost.base, cost.rate, owned);
- output.current = output.next;
- output.next = Math.round(output.base * (owned + 1));
- views.renderGenerator(id);
- }
- };
- /** Events. */
- // click button
- elements.button.addEventListener(CLICK, function() {
- actions.increment(state.cursor.output.current);
- });
- // upgrade cursor
- elements.cursor.querySelector(BUTTON).addEventListener(CLICK, function() {
- if (state.clicks.current >= state.cursor.cost.next) {
- var cursor = state.cursor;
- views.renderMessage(cursor.message);
- actions.decrement(cursor.cost.next);
- actions.updateCursor();
- }
- });
- // purchase generator
- Object.keys(state.generators).forEach(function(id) {
- var generator = state.generators[id];
- var generatorRow = getElementById(id);
- generatorRow.querySelector(BUTTON).addEventListener(CLICK, function() {
- if (generator.message) {
- views.renderMessage(generator.message);
- delete generator.message;
- }
- if (state.clicks.current >= generator.cost.next) {
- actions.decrement(generator.cost.next);
- actions.updateGenerator(id);
- if (generator.interval) {
- generator.interval.callback = function() {
- actions.increment(generator.output.current);
- };
- } else {
- generator.interval = {
- output: generator.output.current,
- callback: function() {
- actions.increment(generator.output.current);
- }
- };
- setInterval(generator.interval.callback, generator.delay * 1000);
- }
- }
- });
- });
- /** Bootstrap. */
- views.renderCounter();
- views.renderCursor();
- views.renderGenerators();
- })();
- /*LOCALSTORAGE*/
- window.addEventListener('DOMContentLoaded', (event) => {
- document.getElementById('state').value = state;
- });
- /**
- var HeartsBackground = {
- heartHeight: 60,
- heartWidth: 64,
- hearts: [],
- heartImage: 'http://i58.tinypic.com/ntnw5.png',
- maxHearts: 8,
- minScale: 0.4,
- draw: function() {
- this.setCanvasSize();
- this.ctx.clearRect(0, 0, this.w, this.h);
- for (var i = 0; i < this.hearts.length; i++) {
- var heart = this.hearts[i];
- heart.image = new Image();
- heart.image.style.height = heart.height;
- heart.image.src = this.heartImage;
- this.ctx.globalAlpha = heart.opacity;
- this.ctx.drawImage (heart.image, heart.x, heart.y, heart.width, heart.height);
- }
- this.move();
- },
- move: function() {
- for(var b = 0; b < this.hearts.length; b++) {
- var heart = this.hearts[b];
- heart.y += heart.ys;
- if(heart.y > this.h) {
- heart.x = Math.random() * this.w;
- heart.y = -1 * this.heartHeight;
- }
- }
- },
- setCanvasSize: function() {
- this.canvas.width = window.innerWidth;
- this.canvas.height = window.innerHeight;
- this.w = this.canvas.width;
- this.h = this.canvas.height;
- },
- initialize: function() {
- this.canvas = $('#canvas')[0];
- if(!this.canvas.getContext)
- return;
- this.setCanvasSize();
- this.ctx = this.canvas.getContext('2d');
- for(var a = 0; a < this.maxHearts; a++) {
- var scale = (Math.random() * (1 - this.minScale)) + this.minScale;
- this.hearts.push({
- x: Math.random() * this.w,
- y: Math.random() * this.h,
- ys: Math.random() + 1,
- height: scale * this.heartHeight,
- width: scale * this.heartWidth,
- opacity: scale
- });
- }
- setInterval($.proxy(this.draw, this), 30);
- }
- };
- $(document).ready(function(){
- HeartsBackground.initialize();
- });
- **/
- var darkEnabled = false;
- $(document).ready(function() {
- $("#dark").on("click", switchDarkMode);
- $("#reset").on("click", reset);
- }
- );
- function switchDarkMode(){
- darkEnabled = !darkEnabled;
- if(darkEnabled){
- $("body").addClass("darkmode");
- $("td").addClass("darkmode-table");
- $("div[class~='panel-body']").addClass("darkmode-panel");
- $("div[class~='panel-heading']").addClass("darkmode-panel-head");
- $("header").addClass("darkmode-header");
- $("div[class~='jumbotron']").addClass("darkmode-jumbotron");
- } else {
- $("body").removeClass("darkmode");
- $("td").removeClass("darkmode-table");
- $("div[class~='panel-body']").removeClass("darkmode-panel");
- $("div[class~='panel-heading']").removeClass("darkmode-panel-head");
- $("header").removeClass("darkmode-header");
- $("div[class~='jumbotron']").removeClass("darkmode-jumbotron");
- }
- }
- function reset(){
- $("body").removeClass("darkmode");
- }
- document.getElementById('clicker-img').ondragstart = function() { return false; };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement