Advertisement
Guest User

Untitled

a guest
May 19th, 2019
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.78 KB | None | 0 0
  1. (function() {
  2.  
  3. "use strict";
  4.  
  5. /** Constants. */
  6. var CLICK = 'click';
  7. var BUTTON = 'button';
  8.  
  9.  
  10. /** State. */
  11. var state = {};
  12.  
  13. state.clicks = {
  14. current: 0,
  15. total: 0
  16. };
  17.  
  18. state.cursor = {
  19. // image: 'https://repl.it/public/images/icon-square.png',
  20. message: 'Your REPL creating ability has improved',
  21. owned: 1,
  22. cost: {
  23. base: 100,
  24. rate: 2
  25. },
  26. output: {
  27. base: 2,
  28. current: 1
  29. }
  30. };
  31.  
  32. /** @see {@link https://coderpatsy.bitbucket.io/cookies/cookies.html} */
  33. state.generators = {
  34. evalbot: {
  35. image: 'https://repl.it/public/images/bot.png', // 'https://repl.it/public/images/evalbot/evalbot_43.png',
  36. message: 'Evalbot is creating REPLs via Slack',
  37. owned: 0,
  38. delay: 10,
  39. cost: {
  40. base: 15,
  41. rate: 1.2
  42. },
  43. output: {
  44. base: 10,
  45. current: 0
  46. }
  47. },
  48.  
  49. katyadee: {
  50. image: 'https://repl.it/public/images/katya.png',
  51. message: 'Katya Delaney is fostering the Repl.it community',
  52. owned: 0,
  53. delay: 1,
  54. cost: {
  55. base: 1e2, // 100
  56. rate: 1.15
  57. },
  58. output: {
  59. base: 1,
  60. current: 0
  61. }
  62. },
  63.  
  64. basicer: {
  65. image: 'https://repl.it/public/images/rob.png',
  66. message: 'Rob Blanckaert is engineering REPLs',
  67. owned: 0,
  68. delay: 1,
  69. cost: {
  70. base: 11e2, // 1,100
  71. rate: 1.15
  72. },
  73. output: {
  74. base: 8,
  75. current: 0
  76. }
  77. },
  78.  
  79. timmy_i_chen: {
  80. image: 'https://repl.it/public/images/tim.png',
  81. message: 'Tim Chen joined Repl.it as the Chief Snack Officer--worker productivity increases',
  82. owned: 0,
  83. delay: 1,
  84. cost: {
  85. base: 12e3, // 12,000
  86. rate: 1.15
  87. },
  88. output: {
  89. base: 47,
  90. current: 0
  91. }
  92. },
  93.  
  94. masfrost: {
  95. image: 'https://repl.it/public/images/faris.jpg',
  96. message: 'Faris Masad enjoys breaking REPLs for fun',
  97. owned: 0,
  98. delay: 1,
  99. cost: {
  100. base: 13e4, // 130,000
  101. rate: 1.15
  102. },
  103. output: {
  104. base: 260,
  105. current: 0
  106. }
  107. },
  108.  
  109. turbio: {
  110. image: 'https://repl.it/public/images/mason.png',
  111. message: 'Mason Clayton is hacking on REPLs',
  112. owned: 0,
  113. delay: 1,
  114. cost: {
  115. base: 14e5, // 1,400,000
  116. rate: 1.15
  117. },
  118. output: {
  119. base: 14e2, // 1,400
  120. current: 0
  121. }
  122. },
  123.  
  124. hayaodeh: {
  125. image: 'https://repl.it/public/images/haya.jpg',
  126. message: 'Haya Odeh is envisioning the next product of Repl.it',
  127. owned: 0,
  128. delay: 1,
  129. cost: {
  130. base: 2e7, // 20,000,000
  131. rate: 1.15
  132. },
  133. output: {
  134. base: 78e2, // 7,800
  135. current: 0
  136. }
  137. },
  138.  
  139. amasad: {
  140. image: 'https://repl.it/public/images/amjad.jpg',
  141. message: 'Amjad Masad has architected a new infrastructure that scales Repl.it indefinitely at minimal cost',
  142. owned: 0,
  143. delay: 1,
  144. cost: {
  145. base: 33e7, // 330,000,000
  146. rate: 1.15
  147. },
  148. output: {
  149. base: 44e3, // 44,000
  150. current: 0
  151. }
  152. }
  153. };
  154.  
  155. state.messages = {
  156. 1: 'Humans: *exist*',
  157. 5: 'Communication allows other humans to yeet',
  158. 10: 'Milestone: Ten REPLs have been created',
  159. 25: 'You share your REPLs on Hacker News to get feedback',
  160. 50: 'YC partner: "an online REPL is not really a startup -- it\'s just a fun toy"',
  161. 75: 'A public API for Repl.it has been released',
  162. 100: 'Milestone: One hundred REPLs have been created',
  163. 150: 'Added feature that allows users to embed REPLs on other sites--traffic increases',
  164. 200: 'The Repl.it service is monetized by selling the code evaluation infrastructure as an API',
  165. 300: 'You raise a seed round with the backing of Roy Bahat from Bloomberg Beta',
  166. 400: 'The autocomplete feature is released, improving user experience--power users increase',
  167. 500: 'API docs for Repl.it are published--developers begin to explore the features',
  168. 600: 'You create a tool for computer science teachers to manage their classrooms',
  169. 700: 'Scheduled assignments have been added to Repl.it Classroom',
  170. 800: 'Due dates have been added to scheduled assignments--teachers rejoice but students despair',
  171. 900: 'Added the ability to import packages for any language',
  172. 1000: 'Milestone: One thousand REPLs have been created',
  173. 1100: 'Repl.it starts to form a small following',
  174. 1250: 'Introduced linting support for languages--users start to get lazy',
  175. 1500: 'Improved vertical scaling of the Repl.it service due to OutOfMemoryError',
  176. 1750: 'Switched to horizontal scaling to minimize single point of failure',
  177. 2000: 'More languages have been added to Repl.it',
  178. 2500: 'Set up Codedeploy to automate auto scaling of REPLs',
  179. 3000: 'Switched devops automation to Ansible--now REPLs can be launched faster than before',
  180. 3500: 'Improved REPL debugging experience',
  181. 4000: 'Introduced live file updates--users call this black magic',
  182. 5000: 'Added collaboration feature--users now use Repl.it as a dating site alternative',
  183. 6000: 'Haskell has been added as a REPL supported language',
  184. 7000: 'Clojure has been added as a REPL supported language',
  185. 8000: 'Users are creating videos tutorials on YouTube and Twitch.tv, which broadens the audience for Repl.it',
  186. 9000: 'Repl.it Multiplayer is out',
  187. 10000: 'Milestone: Ten thousand REPLs have been created',
  188. 11000: 'A large following starts to form for Repl.it',
  189. 12000: 'Repl.it is finally accepted into Y Combinator after many rejections',
  190. 13000: 'Repl.it has graduated from Y Combinator',
  191. 14000: 'Repl.it just raised $4.5M from venture capitalists',
  192. 15000: 'Repl.it Discord server is blowing up',
  193. 16000: 'Repl.it hosts its first ever code jam',
  194. 17000: 'The REPL IDE now takes less than 2 seconds to load',
  195. 18000: 'Work is done to improve the Repl.it container orchestration system',
  196. 19000: 'HTTPS-ready custom domains are available for web/app REPLs--users cancel their GoDaddy hosting',
  197. 20000: 'Workspace update: introduced automatic formatter for REPL',
  198. 30000: 'Workspace update: support uploading files to REPL',
  199. 40000: 'Workspace update: allow downloading files from REPL',
  200. 50000: 'All coding interviews are administered on Repl.it',
  201. 60000: 'Repl.it infrastructure now does continuous deployment',
  202. 70000: 'Added plugin support to REPL IDE--3rd-party developers celebrate',
  203. 80000: 'REPLs now autosave--users remark that this is witchcraft',
  204. 90000: 'REPLs now display the history of revisions',
  205. 100000: 'Milestone: One hundred thousand REPLs have been created',
  206. 110000: 'Repl.it rises up the ranks of Alexa',
  207. 200000: 'Repl.it is the largest unicorn to date',
  208. 500000: 'Repl.it went through one of the largest IPO in history--it is now a publicly traded company',
  209. 600000: 'Stockholders of Repl.it have all become millionaires',
  210. 700000: 'Repl.it has announced its own coin called replcoin',
  211. 800000: 'replcoin has surpassed the value of bitcoin by 10x',
  212. 900000: 'replcoin has become the primary currency of the world',
  213. 1000000: 'Milestone: One million REPLs have been created',
  214. 2000000: 'Repl.it is now mainstream',
  215. 3000000: 'Stockholders Repl.it have all become billionaires',
  216. 4000000: 'Economists state that with Repl.it around, a recession will no longer occur',
  217. 5000000: 'Repl.it has become self-aware',
  218. 6000000: 'Repl.it takes over all of manufacturing',
  219. 7000000: 'Futurists say that there is nothing that Repl.it cannot do',
  220. 8000000: 'Environmental scientists say that Repl.it is reversing global warming',
  221. 9000000: 'Studies show that creating REPLs reverses aging',
  222. 10000000: 'Milestone: Ten million REPLs have been created',
  223. 11000000: 'All education has been replaced with Repl.it',
  224. 20000000: 'Repl.it has cured cancer',
  225. 30000000: 'Repl.it solved world hunger',
  226. 40000000: 'World peace has been achieved by Repl.it',
  227. 50000000: 'Repl.it infrastructure moves from the cloud to the moon',
  228. 60000000: 'Repl.it becomes the primary religion of planet Earth',
  229. 70000000: 'Quantum technology allows Repl.it to create wormholes',
  230. 80000000: 'Scientists say that Repl.it will lead humanity to the singularity',
  231. 90000000: 'Repl.it unearths the secrets to immortality',
  232. 100000000: 'Milestone: One hundred million REPLs have been created',
  233. 200000000: 'Repl.it explores the solar system',
  234. 300000000: 'Repl.it explores the quantum realm',
  235. 400000000: 'Repl.it explores the quantum realm',
  236. 500000000: 'Repl.it explores time travel via its history feature',
  237. 1000000000: 'Milestone: One billion REPLs have been created',
  238. 2000000000: 'Repl.it has turned into a black hole',
  239. 3000100000: '...'
  240. };
  241.  
  242. // set `next` value for cursor `cost` and `output`
  243. state.cursor.cost.next = state.cursor.cost.base;
  244. state.cursor.output.next = state.cursor.output.base;
  245.  
  246. // set `next` value for generators `cost` and `output`
  247. Object.keys(state.generators).forEach(function(id) {
  248. var generator = state.generators[id];
  249. generator.cost.next = generator.cost.base;
  250. generator.output.next = generator.output.base;
  251. });
  252.  
  253. /** Elements. */
  254. var elements = {
  255. button: document.getElementById('button'),
  256. counter: document.getElementById('counter'),
  257. cursor: document.getElementById('upgrade'),
  258. message: document.getElementById('message'),
  259. store: document.getElementById('store')
  260. };
  261.  
  262. Object.keys(state.generators).forEach(function(id) {
  263. var generatorNode = elements.cursor.cloneNode(true);
  264. generatorNode.id = id;
  265. var button = generatorNode.querySelector(BUTTON);
  266. button.title = '@' + id;
  267. button.style.backgroundImage = 'url("' + state.generators[id].image + '")';
  268. elements.store.appendChild(generatorNode);
  269. });
  270.  
  271. /** Helpers. */
  272.  
  273. /**
  274. * @param {Number} base
  275. * @param {Number} rate
  276. * @param {Number} owned
  277. * @return {Number}
  278. */
  279. function calculateNextCost(base, rate, owned) {
  280. return Math.floor(base * Math.pow(rate, owned));
  281. };
  282.  
  283. /**
  284. * @param {String} id
  285. * @return {HTMLElement}
  286. */
  287. function getElementById(id) {
  288. return elements[id] ? elements[id] : elements[id] = document.getElementById(id);
  289. };
  290.  
  291. /**
  292. * @param {Number} clicks
  293. * @param {Number} seconds
  294. * @return {String}
  295. */
  296. function formatGeneratorOutput(clicks, seconds) {
  297. // N per N second(s)
  298. return [
  299. clicks ? '+' : '',
  300. clicks.toLocaleString(),
  301. ' / ',
  302. seconds.toLocaleString(),
  303. seconds === 1 ? ' second' : ' seconds'
  304. ].join('');
  305. };
  306.  
  307. /** Views. */
  308. var views = {
  309. renderCounter: function() {
  310. elements.counter.innerText = state.clicks.current.toLocaleString();
  311. },
  312.  
  313. renderCursor: function() {
  314. var cursorRow = elements.cursor;
  315. var cursor = state.cursor;
  316. cursorRow.querySelector('.owned').innerText = (cursor.owned - 1).toLocaleString();
  317. cursorRow.querySelector('.cost').innerText = cursor.cost.next.toLocaleString();
  318. cursorRow.querySelector('.output-current').innerText = '+' + cursor.output.current.toLocaleString() + ' / click';
  319. cursorRow.querySelector('.output-next').innerText = '+' + cursor.output.next.toLocaleString() + ' / click';
  320. },
  321.  
  322. /**
  323. * @param {String} id
  324. */
  325. renderGenerator: function(id) {
  326. var generator = state.generators[id];
  327. var generatorRow = getElementById(id);
  328. generatorRow.querySelector('.owned').innerText = generator.owned.toLocaleString();
  329. generatorRow.querySelector('.cost').innerText = generator.cost.next.toLocaleString();
  330. generatorRow.querySelector('.output-current').innerText = formatGeneratorOutput(generator.output.current, generator.delay);
  331. generatorRow.querySelector('.output-next').innerText = formatGeneratorOutput(generator.output.next, generator.delay);
  332. },
  333.  
  334. renderGenerators: function() {
  335. Object.keys(state.generators).forEach(function(id) {
  336. views.renderGenerator(id);
  337. });
  338. },
  339.  
  340. /**
  341. * @param {String} [text]
  342. */
  343. renderMessage: function(text) {
  344. var total = state.clicks.total;
  345. var message;
  346.  
  347. if (text) {
  348. message = text;
  349. } else {
  350. // check for exact match in messages table
  351. if (state.messages[total]) {
  352. message = state.messages[total];
  353. delete state.messages[total];
  354. } else {
  355. // otherwise compare number of first message
  356. for (var key in state.messages) {
  357. if (total >= key) {
  358. message = state.messages[key];
  359. delete state.messages[key];
  360. }
  361. break;
  362. }
  363. }
  364. }
  365.  
  366. if (!message) {
  367. return;
  368. }
  369.  
  370. message = message.toLocaleString();
  371. if (message !== elements.message.innerText) {
  372. elements.message.innerText = message;
  373. }
  374. }
  375. };
  376.  
  377. /** Actions. */
  378. var actions = {
  379. /**
  380. * @param {Number} number
  381. * @param {Boolean} [skipTotal]
  382. */
  383. increment: function(number, skipTotal) {
  384. var clicks = state.clicks;
  385. clicks.current += number;
  386. /*LOCALSTORAGE*/
  387. localStorage.setItem('state', state=${state};
  388.  
  389. if (!skipTotal) {
  390. clicks.total += number;
  391. views.renderMessage();
  392. }
  393.  
  394. views.renderCounter();
  395. var cursorButton = elements.cursor.querySelector(BUTTON);
  396. cursorButton.disabled = clicks.current < state.cursor.cost.next;
  397. var generators = state.generators;
  398.  
  399. Object.keys(generators).forEach(function(id) {
  400. var generatorRow = getElementById(id);
  401. var generatorButton = generatorRow.querySelector(BUTTON);
  402. generatorButton.disabled = clicks.current < generators[id].cost.next;
  403. });
  404. },
  405.  
  406. /**
  407. * @param {Number} clicks
  408. */
  409. decrement: function(clicks) {
  410. actions.increment(-clicks, true);
  411. /*LOCALSTORAGE*/
  412. localStorage.setItem('state', state=${state};
  413. },
  414. updateCursor: function() {
  415. var cursor = state.cursor;
  416. var cost = cursor.cost;
  417. var output = cursor.output;
  418. var owned = ++cursor.owned;
  419. cost.next = calculateNextCost(cost.base, cost.rate, owned - 1);
  420. output.current = output.next;
  421. output.next = Math.round(output.base * owned);
  422. views.renderCursor();
  423. },
  424.  
  425. /**
  426. * @param {String} id
  427. */
  428. updateGenerator: function(id) {
  429. var generator = state.generators[id];
  430. var cost = generator.cost,
  431. output = generator.output;
  432. var owned = ++generator.owned;
  433. cost.next = calculateNextCost(cost.base, cost.rate, owned);
  434. output.current = output.next;
  435. output.next = Math.round(output.base * (owned + 1));
  436. views.renderGenerator(id);
  437. }
  438. };
  439.  
  440. /** Events. */
  441.  
  442. // click button
  443. elements.button.addEventListener(CLICK, function() {
  444. actions.increment(state.cursor.output.current);
  445. });
  446.  
  447. // upgrade cursor
  448. elements.cursor.querySelector(BUTTON).addEventListener(CLICK, function() {
  449. if (state.clicks.current >= state.cursor.cost.next) {
  450. var cursor = state.cursor;
  451. views.renderMessage(cursor.message);
  452. actions.decrement(cursor.cost.next);
  453. actions.updateCursor();
  454. }
  455. });
  456.  
  457. // purchase generator
  458. Object.keys(state.generators).forEach(function(id) {
  459. var generator = state.generators[id];
  460. var generatorRow = getElementById(id);
  461.  
  462. generatorRow.querySelector(BUTTON).addEventListener(CLICK, function() {
  463. if (generator.message) {
  464. views.renderMessage(generator.message);
  465. delete generator.message;
  466. }
  467.  
  468. if (state.clicks.current >= generator.cost.next) {
  469. actions.decrement(generator.cost.next);
  470. actions.updateGenerator(id);
  471.  
  472. if (generator.interval) {
  473. generator.interval.callback = function() {
  474. actions.increment(generator.output.current);
  475. };
  476. } else {
  477. generator.interval = {
  478. output: generator.output.current,
  479. callback: function() {
  480. actions.increment(generator.output.current);
  481. }
  482. };
  483. setInterval(generator.interval.callback, generator.delay * 1000);
  484. }
  485. }
  486. });
  487. });
  488.  
  489. /** Bootstrap. */
  490. views.renderCounter();
  491. views.renderCursor();
  492. views.renderGenerators();
  493.  
  494. })();
  495.  
  496.  
  497.  
  498. /*LOCALSTORAGE*/
  499. window.addEventListener('DOMContentLoaded', (event) => {
  500.  
  501. document.getElementById('state').value = state;
  502. });
  503. /**
  504. var HeartsBackground = {
  505.  
  506. heartHeight: 60,
  507. heartWidth: 64,
  508. hearts: [],
  509. heartImage: 'http://i58.tinypic.com/ntnw5.png',
  510. maxHearts: 8,
  511. minScale: 0.4,
  512. draw: function() {
  513. this.setCanvasSize();
  514. this.ctx.clearRect(0, 0, this.w, this.h);
  515. for (var i = 0; i < this.hearts.length; i++) {
  516. var heart = this.hearts[i];
  517. heart.image = new Image();
  518. heart.image.style.height = heart.height;
  519. heart.image.src = this.heartImage;
  520. this.ctx.globalAlpha = heart.opacity;
  521. this.ctx.drawImage (heart.image, heart.x, heart.y, heart.width, heart.height);
  522. }
  523. this.move();
  524. },
  525. move: function() {
  526. for(var b = 0; b < this.hearts.length; b++) {
  527. var heart = this.hearts[b];
  528. heart.y += heart.ys;
  529. if(heart.y > this.h) {
  530. heart.x = Math.random() * this.w;
  531. heart.y = -1 * this.heartHeight;
  532. }
  533. }
  534. },
  535. setCanvasSize: function() {
  536. this.canvas.width = window.innerWidth;
  537. this.canvas.height = window.innerHeight;
  538. this.w = this.canvas.width;
  539. this.h = this.canvas.height;
  540. },
  541. initialize: function() {
  542. this.canvas = $('#canvas')[0];
  543.  
  544. if(!this.canvas.getContext)
  545. return;
  546.  
  547. this.setCanvasSize();
  548. this.ctx = this.canvas.getContext('2d');
  549.  
  550. for(var a = 0; a < this.maxHearts; a++) {
  551. var scale = (Math.random() * (1 - this.minScale)) + this.minScale;
  552. this.hearts.push({
  553. x: Math.random() * this.w,
  554. y: Math.random() * this.h,
  555. ys: Math.random() + 1,
  556. height: scale * this.heartHeight,
  557. width: scale * this.heartWidth,
  558. opacity: scale
  559. });
  560. }
  561.  
  562. setInterval($.proxy(this.draw, this), 30);
  563. }
  564. };
  565.  
  566. $(document).ready(function(){
  567. HeartsBackground.initialize();
  568. });
  569.  
  570. **/
  571.  
  572. var darkEnabled = false;
  573. $(document).ready(function() {
  574. $("#dark").on("click", switchDarkMode);
  575. $("#reset").on("click", reset);
  576. }
  577. );
  578.  
  579. function switchDarkMode(){
  580. darkEnabled = !darkEnabled;
  581. if(darkEnabled){
  582. $("body").addClass("darkmode");
  583. $("td").addClass("darkmode-table");
  584. $("div[class~='panel-body']").addClass("darkmode-panel");
  585. $("div[class~='panel-heading']").addClass("darkmode-panel-head");
  586. $("header").addClass("darkmode-header");
  587. $("div[class~='jumbotron']").addClass("darkmode-jumbotron");
  588. } else {
  589. $("body").removeClass("darkmode");
  590. $("td").removeClass("darkmode-table");
  591. $("div[class~='panel-body']").removeClass("darkmode-panel");
  592. $("div[class~='panel-heading']").removeClass("darkmode-panel-head");
  593. $("header").removeClass("darkmode-header");
  594. $("div[class~='jumbotron']").removeClass("darkmode-jumbotron");
  595. }
  596. }
  597.  
  598. function reset(){
  599. $("body").removeClass("darkmode");
  600. }
  601.  
  602. document.getElementById('clicker-img').ondragstart = function() { return false; };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement