{"text":"'use strict'; \/\/ dont touch\nthis.command = []; \/\/ dont touch\nthis.commandName = []; \/\/ dont touch\nthis.gamemodeId = []; \/\/ dont touch\nthis.gamemode = []; \/\/ dont touch\nthis.addToHelp = []; \/\/ dont touch\n\/\/ [General]\nthis.name = \"Statistics\"; \/\/ Name of plugin REQUIRED\nthis.author = \"LegitSoulja\"; \/\/ author REQUIRED\nthis.description = 'Register Server Statistics'; \/\/ Desciprtion\nthis.compatVersion = ''; \/\/ compatable with (optional)\nthis.version = '1.0.0'; \/\/ version REQUIRED\nthis.addToHelp[1] = \"stats : Amounts of times your server updated stats\";\nthis.commandName[1] = \"stats\";\nthis.command[1] = function(gameServer, config) {\n say(\"Checks > \" + checks);\n return;\n};\n\/\/ INSERT PLUGIN BELOW\nconst fs = require('fs');\nconst http = require('http');\nconst request = require('request');\nthis.config = {\n serverName: \"New Server\",\n alerts: 1\n};\nthis.configfile = 'config.ini';\nvar checks = 0;\nvar sendOut = {\n serverName: \"New Server\",\n serverBots: 0,\n serverPort: 0,\n gamemode: 0,\n statPort: 0,\n serverPlayers: 0,\n gameUID: \"\",\n recentPlayer: \"null\",\n ip: \"\"\n};\nvar enabled = false;\n\/\/ [Functions]\nthis.init = function(gameServer, config) {\n this.gameServer = gameServer;\n this.config = config;\n \/\/ check network\n require('dns')\n .resolve('www.google.com', function(err) {\n if (err) {\n say(\"No network connectivity for Statistics\");\n return;\n }\n });\n checkUpdate(this.version, function(callback) {\n \n if (callback) {\n say(\"Preparing update..\");\n var uc = [];\n uc[1] = \"update\";\n uc[2] = \"Statistics\";\n gameServer.consoleService.execCommand(\"plugin\", uc);\n return;\n \n }else{\n \n say(\"No recent updates :)\");\n enabled = true;\n function refresh() {\n getIP(function(callback) {\n sendOut.ip = callback.toString();\n });\n getPlayers(gameServer, function(callback) {\n sendOut.serverPlayers = callback;\n });\n getBots(gameServer, function(callback) {\n sendOut.serverBots = callback;\n });\n sendOut.serverName = config.serverName;\n sendOut.gameUID = gameServer.uid;\n sendOut.serverPort = gameServer.config.serverPort;\n sendOut.statPort = gameServer.config.serverStatsPort;\n sendOut.gamemode = gameServer.config.serverGamemode;\n checkUpdate();\n setTimeout(function() {\n \/\/console.log(JSON.stringify({data: sendOut}));\n request.post('http:\/\/stats.ogarul.tk\/grab.php', {\n form: {\n hash: JSON.stringify({\n data: sendOut\n })\n }\n }, function(e, r, b) {\n if (e) {\n console.log(\"Could not send data\");\n }\n else {\n if (b) {\n if (config.alerts === 1) {\n say(b);\n }\n }\n }\n });\n }, 5000);\n return;\n }\n setInterval(function() {\n refresh();\n }, 10000);\n refresh();\n \n }\n });\n \n};\nthis.beforespawn = function(player) {\n if(enabled)\n if (typeof player.socket.remoteAddress != 'undefined') {\n sendOut.recentPlayer = player.name;\n }\n return true;\n};\nvar checkUpdate = function(version, callback) {\n request(\"http:\/\/raw.githubusercontent.com\/AJS-development\/OgarUL-Plugin-Library\/master\/Statistics\/version.json\", function(e, r, b) {\n if(callback && typeof(callback) == 'function'){\n \n var parse = JSON.parse(b);\n if (parse.version !== version) {\n console.log(\"Found new update \" + version + \" > \" + parse.version);\n return callback(true);\n }\n return callback(false);\n \n }\n });\n};\nvar getPlayers = function(gameServer, callback) {\n var players = 0;\n for (var i in gameServer.clients) {\n if (typeof gameServer.clients[i].remoteAddress != 'undefined') {\n players++;\n }\n }\n return callback(players);\n};\nvar getBots = function(gameServer, callback) {\n var bots = 0;\n for (var i in gameServer.clients) {\n if (typeof gameServer.clients[i].remoteAddress == 'undefined') {\n bots++;\n }\n }\n return callback(bots);\n};\nvar getIP = function(callback) {\n request(\"http:\/\/stats.ogarul.tk\/getip.php\", function(e, r, b) {\n if (!e) {\n var p = JSON.parse(b);\n return callback(p.ip);\n }\n });\n return;\n};\nthis.onsecond = function(gameServer) {};\nvar say = function(log, gameServer) {\n console.log(\"[Statistics] \" + log);\n return;\n};\nmodule.exports = this; \/\/ dont touch\nUpdate index.js'use strict'; \/\/ dont touch\nthis.command = []; \/\/ dont touch\nthis.commandName = []; \/\/ dont touch\nthis.gamemodeId = []; \/\/ dont touch\nthis.gamemode = []; \/\/ dont touch\nthis.addToHelp = []; \/\/ dont touch\n\/\/ [General]\nthis.name = \"Statistics\"; \/\/ Name of plugin REQUIRED\nthis.author = \"LegitSoulja\"; \/\/ author REQUIRED\nthis.description = 'Register Server Statistics'; \/\/ Desciprtion\nthis.compatVersion = ''; \/\/ compatable with (optional)\nthis.version = '1.0.1'; \/\/ version REQUIRED\nthis.addToHelp[1] = \"stats : Amounts of times your server updated stats\";\nthis.commandName[1] = \"stats\";\nthis.command[1] = function(gameServer, config) {\n say(\"Checks > \" + checks);\n return;\n};\n\/\/ INSERT PLUGIN BELOW\nconst fs = require('fs');\nconst http = require('http');\nconst request = require('request');\nthis.config = {\n serverName: \"New Server\",\n alerts: 1\n};\nthis.configfile = 'config.ini';\nvar checks = 0;\nvar sendOut = {\n serverName: \"New Server\",\n serverBots: 0,\n serverPort: 0,\n gamemode: 0,\n statPort: 0,\n serverPlayers: 0,\n gameUID: \"\",\n recentPlayer: \"null\",\n ip: \"\"\n};\nvar enabled = false;\n\/\/ [Functions]\nthis.init = function(gameServer, config) {\n this.gameServer = gameServer;\n this.config = config;\n \/\/ check network\n require('dns')\n .resolve('www.google.com', function(err) {\n if (err) {\n say(\"No network connectivity for Statistics\");\n return;\n }\n });\n checkUpdate(this.version, function(callback) {\n \n if (callback) {\n say(\"Preparing update..\");\n var uc = [];\n uc[1] = \"update\";\n uc[2] = \"Statistics\";\n gameServer.consoleService.execCommand(\"plugin\", uc);\n return;\n \n }else{\n \n say(\"No recent updates :)\");\n enabled = true;\n function refresh() {\n getIP(function(callback) {\n sendOut.ip = callback.toString();\n });\n getPlayers(gameServer, function(callback) {\n sendOut.serverPlayers = callback;\n });\n getBots(gameServer, function(callback) {\n sendOut.serverBots = callback;\n });\n sendOut.serverName = config.serverName;\n sendOut.gameUID = gameServer.uid;\n sendOut.serverPort = gameServer.config.serverPort;\n sendOut.statPort = gameServer.config.serverStatsPort;\n sendOut.gamemode = gameServer.config.serverGamemode;\n checkUpdate();\n setTimeout(function() {\n \/\/console.log(JSON.stringify({data: sendOut}));\n request.post('http:\/\/stats.ogarul.tk\/grab.php', {\n form: {\n hash: JSON.stringify({\n data: sendOut\n })\n }\n }, function(e, r, b) {\n if (e) {\n console.log(\"Could not send data\");\n }\n else {\n if (b) {\n if (config.alerts === 1) {\n say(b);\n }\n }\n }\n });\n }, 5000);\n return;\n }\n setInterval(function() {\n refresh();\n }, 10000);\n refresh();\n \n }\n });\n \n};\nthis.beforespawn = function(player) {\n if(enabled)\n if (typeof player.socket.remoteAddress != 'undefined') {\n sendOut.recentPlayer = player.name;\n }\n return true;\n};\nvar checkUpdate = function(version, callback) {\n request(\"http:\/\/raw.githubusercontent.com\/AJS-development\/OgarUL-Plugin-Library\/master\/Statistics\/version.json\", function(e, r, b) {\n if(callback && typeof(callback) == 'function'){\n \n var parse = JSON.parse(b);\n if (parse.version !== version) {\n console.log(\"Found new update \" + version + \" > \" + parse.version);\n return callback(true);\n }\n return callback(false);\n \n }\n });\n};\nvar getPlayers = function(gameServer, callback) {\n var players = 0;\n for (var i in gameServer.clients) {\n if (typeof gameServer.clients[i].remoteAddress != 'undefined') {\n players++;\n }\n }\n return callback(players);\n};\nvar getBots = function(gameServer, callback) {\n var bots = 0;\n for (var i in gameServer.clients) {\n if (typeof gameServer.clients[i].remoteAddress == 'undefined') {\n bots++;\n }\n }\n return callback(bots);\n};\nvar getIP = function(callback) {\n request(\"http:\/\/stats.ogarul.tk\/getip.php\", function(e, r, b) {\n if (!e) {\n var p = JSON.parse(b);\n return callback(p.ip);\n }\n });\n return;\n};\nthis.onsecond = function(gameServer) {};\nvar say = function(log, gameServer) {\n console.log(\"[Statistics] \" + log);\n return;\n};\nmodule.exports = this; \/\/ dont touch\n<|endoftext|>"} {"text":"$(document).ready(function() {\n\tvar limit = 60;\n\tvar template = Handlebars.compile($(\"#items-template\").html());\n\tvar $loading = $(\"#wrap_loading\");\n\tvar $grid = $(\"#grid\");\n\tvar infiniteGridService = new eg.InfiniteGridService($grid);\n\n\tfunction getOffset(pos) {\n\t\tvar offset = 0;\n\n\t\tif (pos === \"first\") {\n\t\t\toffset = $(\"#grid\").find(\".item\").first().data(\"offset\");\n\t\t\toffset = parseInt(offset, 10) - limit;\n\t\t} else if (pos === \"last\") {\n\t\t\toffset = $(\"#grid\").find(\".item\").last().data(\"offset\");\n\t\t\toffset = parseInt(offset, 10) + 1;\n\t\t}\n\t\treturn offset;\n\t};\n\n\t\/*\n\t 아이템의 클릭시 persist 데이터를 저장\n\t *\/\n\t$grid.on(\"click\", \"a\", function() {\n\t\tinfiniteGridService.store();\n\t});\n\n\n\tinfiniteGridService.on({\n\t\t\/*\n\t\t \"append\" 이벤트 핸들러\n\t\t 스크롤 다운 중 최하단 아이템이 화면에 보여질 때(threshold로 보정 가능)\n\t\t threshold가 300이면 최하단 아이템이 화면에 보여지기 300px 전에 이벤트 발생\n\t\t 로딩바를 보이고 appendAjax 메소드를 호출해 서버에 데이터를 요청함\n\t\t 응답데이터를 #grid에 append 함\n\t\t *\/\n\t\t\"append\" : function() {\n\t\t\tvar html = template(data.getItems(getOffset(\"last\"), limit));\n\t\t\tinfiniteGridService.append(html);\n\t\t},\n\t\t\/*\n\t\t \"preppend\" 이벤트 핸들러\n\t\t 스크롤 업 중 최상단 아이템이 화면에 보여질 때(threshold로 보정 가능)\n\t\t threshold가 300이면 최하단 아이템이 화면에 보여지기 300px 전에 이벤트 발생\n\t\t 로딩바를 보이고 prependAjax 메소드를 호출해 서버에 데이터를 요청\n\t\t 응답데이터가 #grid에 preppend 되고 스크롤 위치가 보정\n\t\t *\/\n\t\t\"prepend\" : function() {\n\t\t\tvar offset = getOffset(\"first\");\n\t\t\tif (offset > 0) {\n\t\t\t\tvar html = template(data.getItems(offset, limit));\n\t\t\t\tinfiniteGridService.prepend(html);\n\t\t\t}\n\t\t},\n\t\t\/*\n\t\t \"layoutComplete\" 이벤트 핸들러\n\t\t append, preppend가 완료되면 발생\n\t\t 이벤트 파라미터를 통해 append인지 prepend인지 확인 가능\n\t\t 로딩바 감춤\n\t\t *\/\n\t\t\"layoutComplete\" : function(e) {\n\t\t\t$loading.hide();\n\t\t}\n\t});\n\n\t\/*\n\t persist 데이터를 복원함\n\t 복원하지 못한다면 새로운 데이터 추가\n\t *\/\n\tif (!infiniteGridService.restore()) {\n\t\tvar html = template(data.getItems(1, limit));\n\t\tinfiniteGridService.append(html);\n\t}\n});update style$(document).ready(function() {\n\t\/\/ 컨텐츠의 위치를 찾는 함수\n\tfunction getOffset(pos) {\n\t\tvar offset = 0;\n\t\tif (pos === \"first\") {\n\t\t\toffset = $grid.find(\".item\").first().data(\"offset\");\n\t\t\toffset = parseInt(offset, 10) - limit;\n\t\t} else if (pos === \"last\") {\n\t\t\toffset = $grid.find(\".item\").last().data(\"offset\");\n\t\t\toffset = parseInt(offset, 10) + 1;\n\t\t}\n\t\treturn offset;\n\t};\n\n\tvar limit = 60;\n\tvar template = Handlebars.compile($(\"#items-template\").html());\n\tvar $loading = $(\"#wrap_loading\");\n\tvar $grid = $(\"#grid\");\n\tvar infiniteGridService = new eg.InfiniteGridService($grid).on({\n\t\t\/*\n\t\t \"append\" 이벤트 핸들러\n\t\t 스크롤 다운 중 최하단 아이템이 화면에 보여질 때(threshold로 보정 가능)\n\t\t threshold가 300이면 최하단 아이템이 화면에 보여지기 300px 전에 이벤트 발생\n\t\t 응답데이터를 #grid에 append 함\n\t\t *\/\n\t\t\"append\" : function() {\n\t\t\tvar html = template(data.getItems(getOffset(\"last\"), limit));\n\t\t\tinfiniteGridService.append(html);\n\t\t},\n\t\t\/*\n\t\t \"preppend\" 이벤트 핸들러\n\t\t 스크롤 업 중 최상단 아이템이 화면에 보여질 때(threshold로 보정 가능)\n\t\t threshold가 300이면 최하단 아이템이 화면에 보여지기 300px 전에 이벤트 발생\n\t\t 응답데이터가 #grid에 preppend 되고 스크롤 위치가 보정\n\t\t *\/\n\t\t\"prepend\" : function() {\n\t\t\tvar offset = getOffset(\"first\");\n\t\t\tif (offset > 0) {\n\t\t\t\tvar html = template(data.getItems(offset, limit));\n\t\t\t\tinfiniteGridService.prepend(html);\n\t\t\t}\n\t\t},\n\t\t\/*\n\t\t \"layoutComplete\" 이벤트 핸들러\n\t\t append, preppend가 완료되면 발생\n\t\t 이벤트 파라미터를 통해 append인지 prepend인지 확인 가능\n\t\t 로딩바 감춤\n\t\t *\/\n\t\t\"layoutComplete\" : function(e) {\n\t\t\t$loading.hide();\n\t\t}\n\t});\n\n\t\/*\n\t 아이템의 클릭시 persist 데이터를 저장\n\t *\/\n\t$grid.on(\"click\", \"a\", function() {\n\t\tinfiniteGridService.store();\n\t});\n\n\t\/*\n\t persist 데이터를 복원함\n\t 복원하지 못한다면 새로운 데이터 추가\n\t *\/\n\tif (!infiniteGridService.restore()) {\n\t\tvar html = template(data.getItems(1, limit));\n\t\tinfiniteGridService.append(html);\n\t}\n});<|endoftext|>"} {"text":"(function() {\n'use strict';\n\nvar ids = [\n\t'essay', \n\t'blog', \n\t'story_content', \n\t'body-content', \n\t'story_content', \n\t'storyContent', \n\t'contentBody', \n\t'hldcontent', \n\t'contentColumn', \n\t'content', \n\t'article-container', \n\t'articleFullText', \n\t'main_text', \n\t'main',\n\t'Blog1',\n\t'constrictor',\n\t'pageLeftColumn'\n];\n\nvar stripAll = function(tag) {\n\tvar elements = document.getElementsByTagName(tag);\n\telements = Array.prototype.slice.call(elements);\n\telements.forEach(function(element){\n\t\telement.parentNode.removeChild(element);\n\t});\n\t\n};\n\nvar clearStyle = function(element) {\n\tif (element) {\n\t\telement.className = '';\n\t\telement.removeAttribute('style');\n\t}\n};\n\nvar stripToJust = function(element, after) {\n\tvar parentNode = element.parentNode,\n\tchildren = parentNode.childNodes,\n\tnc = children.length,\n\ti, child, toDelete = [];\n\n\tfor (i=0; i 1) {\n\tarticles = filterOutListItemArticles(articles);\n}\nswitch (articles.length) {\n\tcase 0:\n\tif (content) {\n\t\tstripToJust(content);\n\t}\n\tbreak;\n\tcase 1:\n\t\tstripToJust(articles[0]);\n\t\tbreak;\n\tdefault:\n\t\tstripToJust(largestArticle(articles));\n\t\tbreak;\n}\nwindow.zapIt = stripToJust;\nstyleBody();\n\n})();Updated to cope with re-design of http:\/\/www.sitepoint.com added code to enable debugging if you add #debug-ps to the page URL before clicking the Page Shaver bookmarklet.(function() {\n'use strict';\n\nif (window.location.hash === '#debug-ps') {\n \/*jshint debug:true *\/\n debugger;\n}\n\nvar ids = [\n\t'essay',\n\t'blog',\n\t'story_content',\n\t'body-content',\n\t'story_content',\n\t'storyContent',\n\t'contentBody',\n\t'hldcontent',\n\t'contentColumn',\n\t'content',\n\t'article-container',\n\t'articleFullText',\n\t'main_text',\n\t'main',\n\t'Blog1',\n\t'constrictor',\n\t'pageLeftColumn'\n];\n\nvar classes = [\n 'ArticleCopy' \/\/ www.sitepoint.com\n];\n\nvar stripAll = function(tag) {\n\tvar elements = document.getElementsByTagName(tag);\n\telements = Array.prototype.slice.call(elements);\n\telements.forEach(function(element){\n\t\telement.parentNode.removeChild(element);\n\t});\n\n};\n\nvar clearStyle = function(element) {\n\tif (element) {\n\t\telement.className = '';\n\t\telement.removeAttribute('style');\n\t}\n};\n\nvar stripToJust = function(element, after) {\n\tvar parentNode = element.parentNode,\n\tchildren = parentNode.childNodes,\n\tnc = children.length,\n\ti, child, toDelete = [];\n\n\tfor (i=0; i 1) {\n\tarticles = filterOutListItemArticles(articles);\n}\n\nvar findByClasses = function() {\n\n for (var i=0; i"} {"text":"\nfunction Route(sourceMAC, targetMAC, deployRate = 1) {\n this.sourceMAC = sourceMAC;\n this.targetMAC = targetMAC;\n this.deployRate = deployRate;\n\n this.sendCount = 0;\n this.receivedCount = 0;\n this.receivedStepCount = 0;\n this.efficiency = 0;\n\n this.reset = function reset() {\n this.sendCount = 0;\n this.receivedCount = 0;\n this.receivedStepCount = 0;\n this.efficiency = 0;\n }\n}\n\nfunction createSim(graph) {\n var self = {};\n\n self.sim_steps_total = 0;\n self.sim_duration = 0;\n self.routes = {};\n\n function shuffleArray(a) {\n for (let i = a.length; i; i--) {\n let j = Math.floor(Math.random() * i);\n [a[i - 1], a[j]] = [a[j], a[i - 1]];\n }\n }\n\n self.reset = function reset() {\n var intNodes = graph.getIntNodes();\n for (var i = 0; i < intNodes.length; i++) {\n intNodes[i].o.reset();\n }\n\n for (var id in routes) {\n routes[id].reset();\n }\n\n self.sim_steps_total = 0;\n self.sim_duration = 0;\n\n updateSimStatistics();\n }\n\n function updateSimStatistics() {\n var intNodes = graph.getIntNodes();\n var intLinks = graph.getIntLinks();\n\n var packetsBroadcastCount = 0;\n var packetsUnicastCount = 0;\n var routesSendCount = 0;\n var routesReceivedCount = 0;\n var routesTransitCount = 0;\n var routesCount = 0;\n\n var routing_efficiency_sum = 0;\n var routing_efficiency_count = 0;\n\n function countPackets(packet) {\n if (packet.destinationMAC === BROADCAST_MAC) {\n packetsBroadcastCount += 1;\n } else {\n packetsUnicastCount += 1;\n\n var id = packet.sourceMAC + '=>' + packet.destinationMAC;\n routesTransitCount += (id in self.routes);\n }\n }\n\n for (var i in intNodes) {\n var node = intNodes[i].o;\n node.incoming.forEach(countPackets);\n node.outgoing.forEach(countPackets);\n }\n\n for (var id in self.routes) {\n var route = self.routes[id];\n routesCount += 1;\n routesSendCount += route.sendCount;\n routesReceivedCount += route.receivedCount;\n\n if (!isNaN(route.efficiency)) {\n routing_efficiency_sum += route.efficiency;\n routing_efficiency_count += 1;\n }\n \/\/ console.log(route.sourceMAC + ' => ' + route.targetMAC + ', e: ' + e);\n }\n\n \/\/ Convert to medium percent\n var routingEfficiency = 100 * routing_efficiency_sum \/ routing_efficiency_count;\n\n $$('sim_steps_total').nodeValue = self.sim_steps_total;\n $$('sim_duration').nodeValue = (self.sim_duration \/ 1000);\n\n $$('packets_unicast_count').nodeValue = packetsUnicastCount\n $$('packets_broadcast_count').nodeValue = packetsBroadcastCount;\n\n function percent(value) {\n var p = (100 * value \/ routesSendCount);\n return isNaN(p) ? '' : (' (' + p + '%)');\n };\n\n $$('routes_count').nodeValue = routesCount;\n $$('routes_packets_send').nodeValue = routesSendCount;\n $$('routes_packets_received').nodeValue = routesReceivedCount + percent(routesReceivedCount);\n $$('routes_packets_transit').nodeValue = routesTransitCount + percent(routesTransitCount);\n var routesLostCount = (routesSendCount - routesReceivedCount - routesTransitCount);\n $$('routes_packets_lost').nodeValue = routesLostCount + percent(routesLostCount);\n\n $$('routing_efficiency').nodeValue = routingEfficiency;\n }\n\n function append(parent, name, content = '') {\n var e = document.createElement(name);\n if (content.length) {\n var text = document.createTextNode(content)\n e.appendChild(text);\n }\n parent.appendChild(e);\n return e;\n }\n\n function updateRoutesTable() {\n var tbody = $('sim_routes');\n\n \/\/ Remove all elements\n while (tbody.firstChild) {\n tbody.removeChild(tbody.firstChild);\n }\n\n for (key in self.routes) {\n var route = self.routes[key];\n var tr = append(tbody, 'tr');\n var source_td = append(tr, 'td', route.sourceMAC.slice(-5));\n var target_td = append(tr, 'td', route.targetMAC.slice(-5));\n append(tr, 'td', route.deployRate.toString());\n append(tr, 'td', route.sendCount.toString());\n append(tr, 'td', route.receivedCount.toString());\n append(tr, 'td', route.efficiency.toString() + '%');\n\n source_td.title = route.sourceMAC\n target_td.title = route.targetMAC;\n }\n }\n\n self.delRoutes = function delRoutes() {\n function delRoute(sourceNode, targetNode) {\n var id = sourceNode.mac + '=>' + targetNode.mac;\n delete routes[id];\n updateSimStatistics();\n }\n\n var intNodes = graph.getSelectedIntNodes();\n if (intNodes.length == 0) {\n alert('Select one source and at least one target node.');\n return;\n }\n\n var sourceNode = intNodes[0].o;\n for (var i = 1; i < intNodes.length; i += 1) {\n var targetNode = intNodes[i].o;\n delRoute(sourceNode, targetNode);\n }\n updateRoutesTable();\n }\n\n self.addRoutes = function addRoutes() {\n function addRoute(sourceNode, targetNode) {\n var id = sourceMAC + '=>' + targetMAC;\n if (!(id in self.routes)) {\n self.routes[id] = new Route(sourceMAC, targetMAC, 1);\n updateSimStatistics();\n }\n }\n\n var intNodes = graph.getSelectedIntNodes();\n if (intNodes.length == 0) {\n alert('Select one source and at least one target node.');\n return;\n }\n\n var sourceMAC = intNodes[0].o.mac;\n for (var i = 1; i < intNodes.length; i += 1) {\n var targetMAC = intNodes[i].o.mac;\n addRoute(sourceMAC, targetMAC);\n }\n updateRoutesTable();\n }\n\n function deployPackets_() {\n var nodes = graph.getIntNodes();\n var nodeMap = {};\n nodes.forEach(function(e) {\n nodeMap[e.o.mac] = e.o;\n });\n\n for (var id in self.routes) {\n var route = self.routes[id];\n if (randomBoolean(route.deployRate)) {\n var srcMAC = route.sourceMAC;\n var dstMAC = route.targetMAC;\n nodeMap[srcMAC].incoming.push(\n new Packet(srcMAC, srcMAC, srcMAC, dstMAC, self.sim_steps_total)\n );\n route.sendCount += 1\n }\n }\n\n updateRoutesTable();\n updateSimStatistics();\n }\n\n self.deployPackets = function deployPackets() {\n deployPackets_();\n graph.redraw();\n }\n\n function updateRouteEfficiency() {\n var intNodes = graph.getIntNodes();\n var intLinks = graph.getIntLinks();\n var dijkstra = createDijkstra(intNodes, intLinks);\n\n for (var id in self.routes) {\n var route = self.routes[id];\n var sourceIntNode = intNodes.find(function(e) { return e.o.mac === route.sourceMAC; });\n var targetIntNode = intNodes.find(function(e) { return e.o.mac === route.targetMAC; });\n var shortestDistance = dijkstra.getShortestDistance(sourceIntNode, targetIntNode);\n \/*\n * Efficiency as rate of optimal step count weighted by rate of received packets.\n * This means packets in transit are counted as lost packets.\n *\/\n route.efficiency = (route.receivedStepCount \/ (route.receivedCount * shortestDistance)) * (route.receivedCount \/ route.sendCount);\n }\n }\n\n self.step = function step(steps_id, deploy_id) {\n var steps = getInteger(steps_id);\n var deployPacketsEnabled = getBoolean(deploy_id);\n\n var intNodes = graph.getIntNodes();\n var intLinks = graph.getIntLinks();\n\n \/\/ Map internal node index to array of link objects\n var connections = {};\n\n intNodes.forEach(function(n) {\n connections[n.index] = [];\n });\n\n intLinks.forEach(function(l) {\n connections[l.source.index].push(l);\n connections[l.target.index].push(l);\n });\n\n function clonePacket(packet) {\n return JSON.parse(JSON.stringify(packet));\n }\n\n \/\/ Get other part of the link\n function getNeighbor(intLink, intNode) {\n return (intLink.source.index !== intNode.index) ? intLink.source : intLink.target;\n }\n\n var date = new Date();\n var simStartTime = date.getTime();\n\n \/\/ _very_ simple simulation\n var len = intNodes.length;\n for (var step = 0; step < steps; step += 1) {\n self.sim_steps_total += 1;\n\n if (deployPacketsEnabled) {\n deployPackets_();\n }\n\n shuffleArray(intNodes);\n\n \/\/ Step nodes\n for (var i = 0; i < len; i++) {\n var intNode = intNodes[i];\n intNode.o.step();\n }\n\n \/\/ Move packets over links\n for (var i = 0; i < len; i++) {\n var intNode = intNodes[i];\n var intLinks = connections[intNode.index];\n \/\/ Send outgoing packets over links\n for (var p = 0; p < intNode.o.outgoing.length; p++) {\n var packet = intNode.o.outgoing[p];\n if (packet.dstMAC === BROADCAST_MAC) {\n \/\/ Handle broadcast packet\n \/\/ Send cloned apcket to all neighbors\n for (var k = 0; k < intLinks.length; k++) {\n var intLink = intLinks[k];\n var intNeigh = getNeighbor(intLink, intNode);\n packet = clonePacket(packet);\n\n if (randomBoolean(intLink.quality \/ 100)) {\n intNeigh.o.incoming.push(packet);\n } else {\n \/\/ Packet is lost\n }\n }\n } else {\n \/\/ Handle unicast packet\n var targetFound = false;\n \/\/ Send to one neighbor\n for (var k = 0; k < intLinks.length; k++) {\n var intLink = intLinks[k];\n var intNeigh = getNeighbor(intLink, intNode);\n if (packet.dstMAC === intNeigh.o.mac) {\n targetFound = true;\n if (randomBoolean(intLink.quality \/ 100)) {\n intNeigh.o.incoming.push(packet);\n \/\/ Update route stats if packet reached final destination\n if (packet.destinationMAC === intNeigh.o.mac) {\n var id = packet.sourceMAC + '=>' + packet.destinationMAC;\n if (id in self.routes) {\n var route = self.routes[id];\n route.receivedCount += 1;\n route.receivedStepCount += (self.sim_steps_total - packet.step);\n }\n }\n }\n break;\n }\n\n if (!targetFound) {\n console.log('packet lost because next target not found: ' + packet.dstMAC);\n }\n }\n }\n }\n\n \/\/ All packets should have been handled\n intNode.o.outgoing = [];\n }\n }\n\n self.sim_duration = date.getTime() - simStartTime;\n\n updateRouteEfficiency();\n updateSimStatistics();\n\n graph.redraw();\n }\n\n return self;\n}fix efficiency nan display\nfunction Route(sourceMAC, targetMAC, deployRate = 1) {\n this.sourceMAC = sourceMAC;\n this.targetMAC = targetMAC;\n this.deployRate = deployRate;\n\n this.sendCount = 0;\n this.receivedCount = 0;\n this.receivedStepCount = 0;\n this.efficiency = NaN;\n\n this.reset = function reset() {\n this.sendCount = 0;\n this.receivedCount = 0;\n this.receivedStepCount = 0;\n this.efficiency = NaN;\n }\n}\n\nfunction createSim(graph) {\n var self = {};\n\n self.sim_steps_total = 0;\n self.sim_duration = 0;\n self.routes = {};\n\n function shuffleArray(a) {\n for (let i = a.length; i; i--) {\n let j = Math.floor(Math.random() * i);\n [a[i - 1], a[j]] = [a[j], a[i - 1]];\n }\n }\n\n self.reset = function reset() {\n var intNodes = graph.getIntNodes();\n for (var i = 0; i < intNodes.length; i++) {\n intNodes[i].o.reset();\n }\n\n for (var id in self.routes) {\n self.routes[id].reset();\n }\n\n self.sim_steps_total = 0;\n self.sim_duration = 0;\n\n updateSimStatistics();\n }\n\n function num(v, suffix = '') {\n return isNaN(v) ? '-' : (v.toString() + suffix);\n }\n\n function updateSimStatistics() {\n var intNodes = graph.getIntNodes();\n var intLinks = graph.getIntLinks();\n\n var packetsBroadcastCount = 0;\n var packetsUnicastCount = 0;\n var routesSendCount = 0;\n var routesReceivedCount = 0;\n var routesTransitCount = 0;\n var routesCount = 0;\n\n var routing_efficiency_sum = 0;\n var routing_efficiency_count = 0;\n\n function countPackets(packet) {\n if (packet.destinationMAC === BROADCAST_MAC) {\n packetsBroadcastCount += 1;\n } else {\n packetsUnicastCount += 1;\n\n var id = packet.sourceMAC + '=>' + packet.destinationMAC;\n routesTransitCount += (id in self.routes);\n }\n }\n\n for (var i in intNodes) {\n var node = intNodes[i].o;\n node.incoming.forEach(countPackets);\n node.outgoing.forEach(countPackets);\n }\n\n for (var id in self.routes) {\n var route = self.routes[id];\n routesCount += 1;\n routesSendCount += route.sendCount;\n routesReceivedCount += route.receivedCount;\n\n if (!isNaN(route.efficiency)) {\n routing_efficiency_sum += route.efficiency;\n routing_efficiency_count += 1;\n }\n }\n\n \/\/ Convert to medium percent\n var routingEfficiency = 100 * routing_efficiency_sum \/ routing_efficiency_count;\n\n $$('sim_steps_total').nodeValue = self.sim_steps_total;\n $$('sim_duration').nodeValue = (self.sim_duration \/ 1000);\n\n $$('packets_unicast_count').nodeValue = packetsUnicastCount\n $$('packets_broadcast_count').nodeValue = packetsBroadcastCount;\n\n function percent(value) {\n var p = (100 * value \/ routesSendCount);\n return isNaN(p) ? '' : (' (' + p + '%)');\n };\n\n $$('routes_count').nodeValue = routesCount;\n $$('routes_packets_send').nodeValue = routesSendCount;\n $$('routes_packets_received').nodeValue = routesReceivedCount + percent(routesReceivedCount);\n $$('routes_packets_transit').nodeValue = routesTransitCount + percent(routesTransitCount);\n var routesLostCount = (routesSendCount - routesReceivedCount - routesTransitCount);\n $$('routes_packets_lost').nodeValue = routesLostCount + percent(routesLostCount);\n\n $$('routing_efficiency').nodeValue = num(routingEfficiency);\n }\n\n function append(parent, name, content = '') {\n var e = document.createElement(name);\n if (content.length) {\n var text = document.createTextNode(content)\n e.appendChild(text);\n }\n parent.appendChild(e);\n return e;\n }\n\n function updateRoutesTable() {\n var tbody = $('sim_routes');\n\n \/\/ Remove all elements\n while (tbody.firstChild) {\n tbody.removeChild(tbody.firstChild);\n }\n\n for (key in self.routes) {\n var route = self.routes[key];\n var tr = append(tbody, 'tr');\n var source_td = append(tr, 'td', route.sourceMAC.slice(-5));\n var target_td = append(tr, 'td', route.targetMAC.slice(-5));\n append(tr, 'td', route.deployRate.toString());\n append(tr, 'td', route.sendCount.toString());\n append(tr, 'td', route.receivedCount.toString());\n append(tr, 'td', num(route.efficiency, '%'));\n\n source_td.title = route.sourceMAC\n target_td.title = route.targetMAC;\n }\n }\n\n self.delRoutes = function delRoutes() {\n function delRoute(sourceNode, targetNode) {\n var id = sourceNode.mac + '=>' + targetNode.mac;\n delete routes[id];\n updateSimStatistics();\n }\n\n var intNodes = graph.getSelectedIntNodes();\n if (intNodes.length == 0) {\n alert('Select one source and at least one target node.');\n return;\n }\n\n var sourceNode = intNodes[0].o;\n for (var i = 1; i < intNodes.length; i += 1) {\n var targetNode = intNodes[i].o;\n delRoute(sourceNode, targetNode);\n }\n updateRoutesTable();\n }\n\n self.addRoutes = function addRoutes() {\n function addRoute(sourceNode, targetNode) {\n var id = sourceMAC + '=>' + targetMAC;\n if (!(id in self.routes)) {\n self.routes[id] = new Route(sourceMAC, targetMAC, 1);\n updateSimStatistics();\n }\n }\n\n var intNodes = graph.getSelectedIntNodes();\n if (intNodes.length == 0) {\n alert('Select one source and at least one target node.');\n return;\n }\n\n var sourceMAC = intNodes[0].o.mac;\n for (var i = 1; i < intNodes.length; i += 1) {\n var targetMAC = intNodes[i].o.mac;\n addRoute(sourceMAC, targetMAC);\n }\n updateRoutesTable();\n }\n\n function deployPackets_() {\n var nodes = graph.getIntNodes();\n var nodeMap = {};\n nodes.forEach(function(e) {\n nodeMap[e.o.mac] = e.o;\n });\n\n for (var id in self.routes) {\n var route = self.routes[id];\n if (randomBoolean(route.deployRate)) {\n var srcMAC = route.sourceMAC;\n var dstMAC = route.targetMAC;\n nodeMap[srcMAC].incoming.push(\n new Packet(srcMAC, srcMAC, srcMAC, dstMAC, self.sim_steps_total)\n );\n route.sendCount += 1\n }\n }\n\n updateRoutesTable();\n updateSimStatistics();\n }\n\n self.deployPackets = function deployPackets() {\n deployPackets_();\n graph.redraw();\n }\n\n function updateRouteEfficiency() {\n var intNodes = graph.getIntNodes();\n var intLinks = graph.getIntLinks();\n var dijkstra = createDijkstra(intNodes, intLinks);\n\n for (var id in self.routes) {\n var route = self.routes[id];\n var sourceIntNode = intNodes.find(function(e) { return e.o.mac === route.sourceMAC; });\n var targetIntNode = intNodes.find(function(e) { return e.o.mac === route.targetMAC; });\n var shortestDistance = dijkstra.getShortestDistance(sourceIntNode, targetIntNode);\n \/*\n * Efficiency as rate of optimal step count weighted by rate of received packets.\n * This means packets in transit are counted as lost packets.\n *\/\n route.efficiency = (route.receivedStepCount \/ (route.receivedCount * shortestDistance)) * (route.receivedCount \/ route.sendCount);\n }\n }\n\n self.step = function step(steps_id, deploy_id) {\n var steps = getInteger(steps_id);\n var deployPacketsEnabled = getBoolean(deploy_id);\n\n var intNodes = graph.getIntNodes();\n var intLinks = graph.getIntLinks();\n\n \/\/ Map internal node index to array of link objects\n var connections = {};\n\n intNodes.forEach(function(n) {\n connections[n.index] = [];\n });\n\n intLinks.forEach(function(l) {\n connections[l.source.index].push(l);\n connections[l.target.index].push(l);\n });\n\n function clonePacket(packet) {\n return JSON.parse(JSON.stringify(packet));\n }\n\n \/\/ Get other part of the link\n function getNeighbor(intLink, intNode) {\n return (intLink.source.index !== intNode.index) ? intLink.source : intLink.target;\n }\n\n var date = new Date();\n var simStartTime = date.getTime();\n\n \/\/ _very_ simple simulation\n var len = intNodes.length;\n for (var step = 0; step < steps; step += 1) {\n self.sim_steps_total += 1;\n\n if (deployPacketsEnabled) {\n deployPackets_();\n }\n\n shuffleArray(intNodes);\n\n \/\/ Step nodes\n for (var i = 0; i < len; i++) {\n var intNode = intNodes[i];\n intNode.o.step();\n }\n\n \/\/ Move packets over links\n for (var i = 0; i < len; i++) {\n var intNode = intNodes[i];\n var intLinks = connections[intNode.index];\n \/\/ Send outgoing packets over links\n for (var p = 0; p < intNode.o.outgoing.length; p++) {\n var packet = intNode.o.outgoing[p];\n if (packet.dstMAC === BROADCAST_MAC) {\n \/\/ Handle broadcast packet\n \/\/ Send cloned apcket to all neighbors\n for (var k = 0; k < intLinks.length; k++) {\n var intLink = intLinks[k];\n var intNeigh = getNeighbor(intLink, intNode);\n packet = clonePacket(packet);\n\n if (randomBoolean(intLink.quality \/ 100)) {\n intNeigh.o.incoming.push(packet);\n } else {\n \/\/ Packet is lost\n }\n }\n } else {\n \/\/ Handle unicast packet\n var targetFound = false;\n \/\/ Send to one neighbor\n for (var k = 0; k < intLinks.length; k++) {\n var intLink = intLinks[k];\n var intNeigh = getNeighbor(intLink, intNode);\n if (packet.dstMAC === intNeigh.o.mac) {\n targetFound = true;\n if (randomBoolean(intLink.quality \/ 100)) {\n intNeigh.o.incoming.push(packet);\n \/\/ Update route stats if packet reached final destination\n if (packet.destinationMAC === intNeigh.o.mac) {\n var id = packet.sourceMAC + '=>' + packet.destinationMAC;\n if (id in self.routes) {\n var route = self.routes[id];\n route.receivedCount += 1;\n route.receivedStepCount += (self.sim_steps_total - packet.step);\n }\n }\n }\n break;\n }\n\n if (!targetFound) {\n console.log('packet lost because next target not found: ' + packet.dstMAC);\n }\n }\n }\n }\n\n \/\/ All packets should have been handled\n intNode.o.outgoing = [];\n }\n }\n\n self.sim_duration = date.getTime() - simStartTime;\n\n updateRouteEfficiency();\n updateSimStatistics();\n\n graph.redraw();\n }\n\n return self;\n}<|endoftext|>"} {"text":"require('dotenv').config();\n\nconst path = require('path');\nconst merge = require('webpack-merge');\nconst webpack = require('webpack');\nconst CopyWebpackPlugin = require('copy-webpack-plugin');\nconst FaviconPlugin = require('favicons-webpack-plugin');\nconst HtmlPlugin = require('html-webpack-plugin');\nconst VueSSRClientPlugin = require('vue-server-renderer\/client-plugin');\nconst SWPrecachePlugin = require('sw-precache-webpack-plugin');\n\nconst baseConfig = require('.\/webpack.base');\nconst createClientEnvironment = require('.\/env');\n\nconst rootPath = path.join(__dirname, '..\/..\/');\n\nconst isProduction = env => env.NODE_ENV === 'production';\n\nmodule.exports = (env = process.env) => {\n const config = merge(baseConfig(env), {\n devtool: isProduction(env) ? 'source-map' : 'eval-source-map',\n plugins: [\n new webpack.DefinePlugin(createClientEnvironment(Object.assign(env, {\n VUE_ENV: 'client',\n }))),\n new CopyWebpackPlugin([\n {\n from: path.join(rootPath, 'static'),\n to: path.join(rootPath, 'dist\/public'),\n },\n ]),\n new webpack.optimize.UglifyJsPlugin({\n compress: isProduction(env) ? { warnings: false } : false,\n }),\n new webpack.optimize.OccurrenceOrderPlugin(),\n new FaviconPlugin({\n logo: '.\/internals\/templates\/favicon.png',\n prefix: 'icons\/',\n persistentCache: true,\n inject: true,\n background: '#fff',\n title: 'NUSWhispers',\n icons: {\n android: isProduction(env),\n appleIcon: isProduction(env),\n appleStartup: false,\n coast: false,\n favicons: true,\n firefox: isProduction(env),\n windows: isProduction(env),\n yandex: isProduction(env),\n },\n }),\n new HtmlPlugin({\n filename: '..\/index.template.html',\n template: '.\/internals\/templates\/index.hbs',\n inject: true,\n minify: {\n removeComments: false,\n collapseWhitespace: isProduction(env),\n removeAttributeQuotes: isProduction(env),\n },\n chunksSortMode: 'dependency',\n excludeChunks: ['app', 'vendor'], \/\/ Handled by vue-server-renderer.\n }),\n new VueSSRClientPlugin(),\n ],\n });\n\n if (isProduction(env)) {\n config.plugins.push(\n \/\/ Split vendor into its own file.\n new webpack.optimize.CommonsChunkPlugin({\n name: 'vendor',\n minChunks: module =>\n \/\/ Any required modules inside node_modules are extracted to vendor.\n module.resource &&\n \/\\.js$\/.test(module.resource) &&\n module.resource.indexOf(path.join(__dirname, '..\/node_modules')) === 0,\n }),\n \/\/ Extract webpack runtime and module manifest to its own file in order to\n \/\/ prevent vendor hash from being updated whenever app bundle is updated.\n new webpack.optimize.CommonsChunkPlugin({\n name: 'manifest',\n chunks: ['vendor'],\n minChunks: Infinity,\n }),\n new SWPrecachePlugin({\n cacheId: 'nuswhispers-vue',\n filename: 'service-worker.js',\n dontCacheBustUrlsMatching: \/.\/,\n staticFileGlobsIgnorePatterns: [\/index\\.template\\.html$\/, \/\\.json$\/, \/\\.map$\/],\n runtimeCaching: [\n {\n urlPattern: \/^https:\\\/\\\/www\\.nuswhispers\\.com\\\/api\/,\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/',\n handler: 'networkFirst',\n },\n {\n urlPattern: \/\\\/(latest|popular|success|policy)\/,\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/confession\/:id',\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/category\/:id',\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/tag\/:id',\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/search\/:id',\n handler: 'networkFirst',\n },\n ],\n })\n );\n }\n\n return config;\n};\nRemove OccurrenceOrderPluginrequire('dotenv').config();\n\nconst path = require('path');\nconst merge = require('webpack-merge');\nconst webpack = require('webpack');\nconst CopyWebpackPlugin = require('copy-webpack-plugin');\nconst FaviconPlugin = require('favicons-webpack-plugin');\nconst HtmlPlugin = require('html-webpack-plugin');\nconst VueSSRClientPlugin = require('vue-server-renderer\/client-plugin');\nconst SWPrecachePlugin = require('sw-precache-webpack-plugin');\n\nconst baseConfig = require('.\/webpack.base');\nconst createClientEnvironment = require('.\/env');\n\nconst rootPath = path.join(__dirname, '..\/..\/');\n\nconst isProduction = env => env.NODE_ENV === 'production';\n\nmodule.exports = (env = process.env) => {\n const config = merge(baseConfig(env), {\n devtool: isProduction(env) ? 'source-map' : 'eval-source-map',\n plugins: [\n new webpack.DefinePlugin(createClientEnvironment(Object.assign(env, {\n VUE_ENV: 'client',\n }))),\n new CopyWebpackPlugin([\n {\n from: path.join(rootPath, 'static'),\n to: path.join(rootPath, 'dist\/public'),\n },\n ]),\n new webpack.optimize.UglifyJsPlugin({\n compress: isProduction(env) ? { warnings: false } : false,\n }),\n new FaviconPlugin({\n logo: '.\/internals\/templates\/favicon.png',\n prefix: 'icons\/',\n persistentCache: true,\n inject: true,\n background: '#fff',\n title: 'NUSWhispers',\n icons: {\n android: isProduction(env),\n appleIcon: isProduction(env),\n appleStartup: false,\n coast: false,\n favicons: true,\n firefox: isProduction(env),\n windows: isProduction(env),\n yandex: isProduction(env),\n },\n }),\n new HtmlPlugin({\n filename: '..\/index.template.html',\n template: '.\/internals\/templates\/index.hbs',\n inject: true,\n minify: {\n removeComments: false,\n collapseWhitespace: isProduction(env),\n removeAttributeQuotes: isProduction(env),\n },\n chunksSortMode: 'dependency',\n excludeChunks: ['app', 'vendor'], \/\/ Handled by vue-server-renderer.\n }),\n new VueSSRClientPlugin(),\n ],\n });\n\n if (isProduction(env)) {\n config.plugins.push(\n \/\/ Split vendor into its own file.\n new webpack.optimize.CommonsChunkPlugin({\n name: 'vendor',\n minChunks: module =>\n \/\/ Any required modules inside node_modules are extracted to vendor.\n module.resource &&\n \/\\.js$\/.test(module.resource) &&\n module.resource.indexOf(path.join(__dirname, '..\/node_modules')) === 0,\n }),\n \/\/ Extract webpack runtime and module manifest to its own file in order to\n \/\/ prevent vendor hash from being updated whenever app bundle is updated.\n new webpack.optimize.CommonsChunkPlugin({\n name: 'manifest',\n chunks: ['vendor'],\n minChunks: Infinity,\n }),\n new SWPrecachePlugin({\n cacheId: 'nuswhispers-vue',\n filename: 'service-worker.js',\n dontCacheBustUrlsMatching: \/.\/,\n staticFileGlobsIgnorePatterns: [\/index\\.template\\.html$\/, \/\\.json$\/, \/\\.map$\/],\n runtimeCaching: [\n {\n urlPattern: \/^https:\\\/\\\/www\\.nuswhispers\\.com\\\/api\/,\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/',\n handler: 'networkFirst',\n },\n {\n urlPattern: \/\\\/(latest|popular|success|policy)\/,\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/confession\/:id',\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/category\/:id',\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/tag\/:id',\n handler: 'networkFirst',\n },\n {\n urlPattern: '\/search\/:id',\n handler: 'networkFirst',\n },\n ],\n })\n );\n }\n\n return config;\n};\n<|endoftext|>"} {"text":"function TimeSeriesChart() {\n\n this.create = function(element) {\n\n var series = {};\n\n var margin = {top: 20, right: 20, bottom: 30, left: 50},\n width = 900 - margin.left - margin.right,\n height = 300 - margin.top - margin.bottom;\n\n var accessDatetime = function(d) { return d.datetime; };\n var accessValue = function(d) { return d.value; };\n\n var xScale = d3.time.scale.utc()\n .range([0, width]);\n\n var yScale = d3.scale.linear()\n .range([height, 0]);\n\n var xAxis = d3.svg.axis()\n .scale(xScale)\n .orient(\"bottom\");\n\n var yAxis = d3.svg.axis()\n .scale(yScale)\n .orient(\"left\");\n\n var line = d3.svg.line()\n .interpolate(\"line\")\n .x(function(d) { return xScale(d.datetime); })\n .y(function(d) { return yScale(d.value); });\n\n var lineX = d3.svg.line()\n .interpolate(\"line\")\n .x(function(d) { return xScale(d.datetime); })\n .y(function(d) { return yScale.range()[0]; });\n\n \/\/ create chart and bind to element\n \/\/ var svg = d3.select(element).append(\"svg\")\n \/\/ .attr(\"width\", width + margin.left + margin.right)\n \/\/ .attr(\"height\", height + margin.top + margin.bottom)\n \/\/ .append(\"g\")\n \/\/ .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");\n\n \/* http:\/\/stackoverflow.com\/questions\/16265123\/resize-svg-when-window-is-resized-in-d3-js *\/\n var svg = d3.select(element)\/\/.append(\"svg\")\n \/\/ .append(\"div\")\n .classed(\"svg-container\", true) \/\/container class to make it responsive\n .append(\"svg\")\n \/\/responsive SVG needs these 2 attributes and no width and height attr\n .attr(\"preserveAspectRatio\", \"xMinYMin meet\")\n .attr(\"viewBox\", \"0 0 900 300\")\n \/\/class to make it responsive\n .classed(\"svg-content-responsive\", true)\/\/;\n .append(\"g\")\n .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");\n\n var chartXAxis = svg.append(\"g\")\n .attr(\"class\", \"x axis\")\n .attr(\"transform\", \"translate(0,\" + height + \")\")\n .call(xAxis);\n\n var chartYAxis = svg.append(\"g\")\n .attr(\"class\", \"y axis\")\n .call(yAxis);\n\n \/**\n * Update chart for all series\n *\/\n var chartUpdate = function() {\n updateChartAxis();\n updateDate();\n };\n\n var updateChartAxis = function() {\n\n \/\/ calculate extent for each series\n var extentsDatetime = [];\n var extentsValue = [];\n for (var key in series) {\n if (series.hasOwnProperty(key)) {\n var ser = series[key];\n extentsDatetime.push(d3.extent(ser, accessDatetime));\n extentsValue.push(d3.extent(ser, accessValue));\n }\n }\n\n \/\/ select global min\/max from all extents\n var min_datetime = d3.min(extentsDatetime, function(d){ return d[0]});\n var max_datetime = d3.max(extentsDatetime, function(d){ return d[1]});\n var min_value = d3.min(extentsValue, function(d){ return d[0]});\n var max_value = d3.max(extentsValue, function(d){ return d[1]});\n\n \/\/ update chart scales\n xScale.domain([min_datetime, max_datetime]);\n yScale.domain([min_value, max_value]);\n\n \/\/ update chart\n chartXAxis.call(xAxis);\n chartYAxis.call(yAxis);\n };\n\n var updateDate = function() {\n\n var data = [];\n for (var key in series) {\n if (series.hasOwnProperty(key)) {\n data.push({ key: key, values: series[key] });\n }\n }\n\n var path = svg.selectAll(\"path\").data(data, function(k,i) {\n return k.key;\n });\n\n path.enter().append(\"path\")\n \/\/ .attr(\"d\", function(d) { return line(d.values) })\n .attr(\"class\", function(d) { return \"line \" + d.key } )\n .attr(\"d\", function(d) { return lineX(d.values) });\n\n path.transition().duration(500)\n .attr(\"d\", function(d) { return line(d.values) } );\n\n path.exit().remove();\n };\n\n return {\n\n \/\/\n addSeries: function(series_id, label, data) {\n\n if (series[series_id]) {\n console.warn('Replacing series [' + series_id + '] with a new data!');\n }\n series[series_id] = data;\n chartUpdate();\n\n \/\/ svg.append(\"g\")\n \/\/ .attr(\"class\", \"x axis\")\n \/\/ .attr(\"transform\", \"translate(0,\" + height + \")\")\n \/\/ .call(xAxis);\n\n \/\/ chartXAxis.call(xAxis);\n\n \/\/ svg.append(\"g\")\n \/\/ .attr(\"class\", \"y axis\")\n \/\/ .call(yAxis);\n \/\/ .append(\"text\")\n \/\/ .attr(\"transform\", \"rotate(-90)\")\n \/\/ .attr(\"y\", 6)\n \/\/ .attr(\"dy\", \".71em\")\n \/\/ .style(\"text-anchor\", \"end\")\n \/\/ .text(\"Temperature (ºF)\");\n \/\/ chartYAxis.call(yAxis);\n\n \/\/ var city = svg.selectAll(\".series\")\n \/\/ .data(data)\n \/\/ .enter().append(\"g\")\n \/\/ .attr(\"class\", \"series\");\n },\n\n \/\/\n disableSeries: function(series_id) {\n console.error(\"disableSeries method not implemented yet!\");\n },\n\n \/\/\n enableSeries: function(series_id) {\n console.error(\"enableSeries method not implemented yet!\");\n }\n };\n }\n\n}\n\n\/\/ Make our chart globally available\nwindow._TimeSeriesChart = new TimeSeriesChart();Add transition to axes as well.function TimeSeriesChart() {\n\n this.create = function(element) {\n\n var series = {};\n\n var margin = {top: 20, right: 20, bottom: 30, left: 50},\n width = 900 - margin.left - margin.right,\n height = 300 - margin.top - margin.bottom;\n\n var accessDatetime = function(d) { return d.datetime; };\n var accessValue = function(d) { return d.value; };\n\n var xScale = d3.time.scale.utc()\n .range([0, width]);\n\n var yScale = d3.scale.linear()\n .range([height, 0]);\n\n var xAxis = d3.svg.axis()\n .scale(xScale)\n .orient(\"bottom\");\n\n var yAxis = d3.svg.axis()\n .scale(yScale)\n .orient(\"left\");\n\n var line = d3.svg.line()\n .interpolate(\"line\")\n .x(function(d) { return xScale(d.datetime); })\n .y(function(d) { return yScale(d.value); });\n\n var lineX = d3.svg.line()\n .interpolate(\"line\")\n .x(function(d) { return xScale(d.datetime); })\n .y(function(d) { return yScale.range()[0]; });\n\n \/\/ create chart and bind to element\n \/\/ var svg = d3.select(element).append(\"svg\")\n \/\/ .attr(\"width\", width + margin.left + margin.right)\n \/\/ .attr(\"height\", height + margin.top + margin.bottom)\n \/\/ .append(\"g\")\n \/\/ .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");\n\n \/* http:\/\/stackoverflow.com\/questions\/16265123\/resize-svg-when-window-is-resized-in-d3-js *\/\n var svg = d3.select(element)\/\/.append(\"svg\")\n \/\/ .append(\"div\")\n .classed(\"svg-container\", true) \/\/container class to make it responsive\n .append(\"svg\")\n \/\/responsive SVG needs these 2 attributes and no width and height attr\n .attr(\"preserveAspectRatio\", \"xMinYMin meet\")\n .attr(\"viewBox\", \"0 0 900 300\")\n \/\/class to make it responsive\n .classed(\"svg-content-responsive\", true)\/\/;\n .append(\"g\")\n .attr(\"transform\", \"translate(\" + margin.left + \",\" + margin.top + \")\");\n\n var chartXAxis = svg.append(\"g\")\n .attr(\"class\", \"x axis\")\n .attr(\"transform\", \"translate(0,\" + height + \")\")\n .call(xAxis);\n\n var chartYAxis = svg.append(\"g\")\n .attr(\"class\", \"y axis\")\n .call(yAxis);\n\n \/**\n * Update chart for all series\n *\/\n var chartUpdate = function() {\n updateChartAxis();\n updateDate();\n };\n\n var updateChartAxis = function() {\n\n \/\/ calculate extent for each series\n var extentsDatetime = [];\n var extentsValue = [];\n for (var key in series) {\n if (series.hasOwnProperty(key)) {\n var ser = series[key];\n extentsDatetime.push(d3.extent(ser, accessDatetime));\n extentsValue.push(d3.extent(ser, accessValue));\n }\n }\n\n \/\/ select global min\/max from all extents\n var min_datetime = d3.min(extentsDatetime, function(d){ return d[0]});\n var max_datetime = d3.max(extentsDatetime, function(d){ return d[1]});\n var min_value = d3.min(extentsValue, function(d){ return d[0]});\n var max_value = d3.max(extentsValue, function(d){ return d[1]});\n\n \/\/ update chart scales\n xScale.domain([min_datetime, max_datetime]);\n yScale.domain([min_value, max_value]);\n\n \/\/ update chart\n chartXAxis.transition().duration(500).call(xAxis);\n chartYAxis.transition().duration(500).call(yAxis);\n };\n\n var updateDate = function() {\n\n var data = [];\n for (var key in series) {\n if (series.hasOwnProperty(key)) {\n data.push({ key: key, values: series[key] });\n }\n }\n\n var path = svg.selectAll(\"path\").data(data, function(k,i) {\n return k.key;\n });\n\n path.enter().append(\"path\")\n \/\/ .attr(\"d\", function(d) { return line(d.values) })\n .attr(\"class\", function(d) { return \"line \" + d.key } )\n .attr(\"d\", function(d) { return lineX(d.values) });\n\n path.transition().duration(500)\n .attr(\"d\", function(d) { return line(d.values) } );\n\n path.exit().remove();\n };\n\n return {\n\n \/\/\n addSeries: function(series_id, label, data) {\n\n if (series[series_id]) {\n console.warn('Replacing series [' + series_id + '] with a new data!');\n }\n series[series_id] = data;\n chartUpdate();\n\n \/\/ svg.append(\"g\")\n \/\/ .attr(\"class\", \"x axis\")\n \/\/ .attr(\"transform\", \"translate(0,\" + height + \")\")\n \/\/ .call(xAxis);\n\n \/\/ chartXAxis.call(xAxis);\n\n \/\/ svg.append(\"g\")\n \/\/ .attr(\"class\", \"y axis\")\n \/\/ .call(yAxis);\n \/\/ .append(\"text\")\n \/\/ .attr(\"transform\", \"rotate(-90)\")\n \/\/ .attr(\"y\", 6)\n \/\/ .attr(\"dy\", \".71em\")\n \/\/ .style(\"text-anchor\", \"end\")\n \/\/ .text(\"Temperature (ºF)\");\n \/\/ chartYAxis.call(yAxis);\n\n \/\/ var city = svg.selectAll(\".series\")\n \/\/ .data(data)\n \/\/ .enter().append(\"g\")\n \/\/ .attr(\"class\", \"series\");\n },\n\n \/\/\n disableSeries: function(series_id) {\n console.error(\"disableSeries method not implemented yet!\");\n },\n\n \/\/\n enableSeries: function(series_id) {\n console.error(\"enableSeries method not implemented yet!\");\n }\n };\n }\n\n}\n\n\/\/ Make our chart globally available\nwindow._TimeSeriesChart = new TimeSeriesChart();<|endoftext|>"} {"text":"\/* global Zepto, document, EJS, context, ejsTemplate, TextMate *\/\n\/* global error_explanations *\/\n\nZepto(document).ready(function($) {\n \/\/ Remove the marker flag indicating that the validation window\n \/\/ for this document is showing.\n $(document).on('visibilitychange', function() {\n if (document.hidden && ('markerFile' in context) && context.markerFile) {\n TextMate.system('\/bin\/rm \"' + context.markerFile + '\"');\n }\n });\n\n \/\/ close the report window when the user presses ESCape\n $(document).keydown(function(e) {\n if (e.keyCode === 27) {\n e.preventDefault();\n var cmd = '\"tell application \\\\\"System Events\\\\\" ' +\n 'to keystroke \\\\\"w\\\\\" using command down\"';\n TextMate.system('osascript -e ' + cmd, function(){});\n }\n });\n\n \/\/ render the template and inject it into the page\n var html = new EJS({text: ejsTemplate}).render(context);\n $('#content').html(html);\n\n \/\/ add links to error\/warning codes, when available\n $('.issue-code').each(function(index, item) {\n var issueCode = $(item).text();\n if (error_explanations.hasOwnProperty(issueCode)) {\n var url = error_explanations[issueCode];\n $(item).wrap('');\n }\n });\n\n \/\/ By default, links will open in the TextMate results window. If\n \/\/ the tag has class \"open-external\" we’ll catch it and open\n \/\/ the link in the user’s browser instead.\n $('.open-external').on('click', function(e) {\n e.preventDefault();\n var href = $(this).attr('href');\n if (!href.match(\/^http(?:s?)\\:\\\/\\\/[^\\\/]\/)) {\n \/\/ doesn’t look like a normal URL\n return;\n }\n TextMate.system('open \"' + encodeURI(href) + '\"', null);\n });\n});\nfix freeze when closing report shown in a pane\/* global Zepto, document, EJS, context, ejsTemplate, TextMate, window *\/\n\/* global error_explanations *\/\n\nZepto(document).ready(function($) {\n \/\/ Remove the marker flag indicating that the validation window\n \/\/ for this document is showing.\n $(document).on('visibilitychange', function() {\n window.setTimeout(function() {\n if (document.hidden && ('markerFile' in context) && context.markerFile) {\n TextMate.system('\/bin\/rm \"' + context.markerFile + '\"');\n }\n }, 1);\n });\n\n \/\/ close the report window when the user presses ESCape\n $(document).keydown(function(e) {\n if (e.keyCode === 27) {\n e.preventDefault();\n var cmd = '\"tell application \\\\\"System Events\\\\\" ' +\n 'to keystroke \\\\\"w\\\\\" using command down\"';\n TextMate.system('osascript -e ' + cmd, function(){});\n }\n });\n\n \/\/ render the template and inject it into the page\n var html = new EJS({text: ejsTemplate}).render(context);\n $('#content').html(html);\n\n \/\/ add links to error\/warning codes, when available\n $('.issue-code').each(function(index, item) {\n var issueCode = $(item).text();\n if (error_explanations.hasOwnProperty(issueCode)) {\n var url = error_explanations[issueCode];\n $(item).wrap('');\n }\n });\n\n \/\/ By default, links will open in the TextMate results window. If\n \/\/ the tag has class \"open-external\" we’ll catch it and open\n \/\/ the link in the user’s browser instead.\n $('.open-external').on('click', function(e) {\n e.preventDefault();\n var href = $(this).attr('href');\n if (!href.match(\/^http(?:s?)\\:\\\/\\\/[^\\\/]\/)) {\n \/\/ doesn’t look like a normal URL\n return;\n }\n TextMate.system('open \"' + encodeURI(href) + '\"', null);\n });\n});\n<|endoftext|>"} {"text":"'use strict'\n\nangular.module('ludwigApp')\n .controller('AccountCtrl', function ($scope, $state, LoginService, RepositoryService) {\n LoginService.get()\n .then(function (user) {\n if (!user) {\n return $state.go('layout.home')\n }\n\n $scope.user = user\n RepositoryService.getCandidates()\n .then(function (repositories) {\n $scope.candidates = repositories.filter(function (repo) {\n return $scope.user.repositories.indexOf(repo.full_name) < 0\n })\n })\n })\n\n $scope.logout = function () {\n LoginService.delete()\n .then(function () {\n $state.go('layout.home')\n })\n }\n\n $scope.activateRepository = RepositoryService.activateRepository\n })\nImprove front to prevent double activation'use strict'\n\nangular.module('ludwigApp')\n .controller('AccountCtrl', function ($scope, $state, LoginService, RepositoryService) {\n LoginService.get()\n .then(function (user) {\n if (!user) {\n return $state.go('layout.home')\n }\n\n $scope.user = user\n RepositoryService.getCandidates()\n .then(function (repositories) {\n $scope.candidates = repositories.filter(function (repo) {\n return $scope.user.repositories.indexOf(repo.full_name) < 0\n })\n })\n })\n\n $scope.logout = function () {\n LoginService.delete()\n .then(function () {\n $state.go('layout.home')\n })\n }\n\n $scope.activateRepository = function (repository) {\n RepositoryService.activateRepository(repository)\n .then(function (repository) {\n if (repository.error) {\n return\n }\n\n $scope.user.repositories.push(repository.id)\n var idx = $scope.candidates.findIndex(function (repo) {\n return repo.full_name === repository.id\n })\n if (idx > -1) {\n $scope.candidates.splice(idx, 1)\n }\n })\n }\n })\n<|endoftext|>"} {"text":"\n\/**\n * AJAX: FETCH CONTENT FOR DESCRIPTION\n * @param externalSource either \"Wikipedia\" or \"Europeana\"\n *\/\nfunction wpunity_fetchDescriptionAjaxFrontEnd( externalSource, title, description_dom ){\n\n \/\/document.getElementById('wpunity_fetchDescription_bt').innerHTML = \"Fetching\";\n \/\/externalSource = document.getElementById(\"fetch_source\").options[document.getElementById(\"fetch_source\").selectedIndex].value;\n \/\/lang document.getElementById(\"fetch_lang\").options[document.getElementById(\"fetch_lang\").selectedIndex].value;\n\n \/\/ Replace empty spaces with underscores\n var title = title.replace(new RegExp(\" \", 'g'),\"_\"); \/\/ document.getElementById(\"wpunity_titles_search\").value.replace(\" \",\"%20\");\n\n\n var lang = \"en\";\n\n for (var j=0; j< title.length; j++)\n if ( title.charCodeAt(j) > 902 && title.charCodeAt(j) < 974 ){\n lang = \"el\";\n break;\n }\n\n\n\n var fulltext = '';\n\n var reqCompile = jQuery.ajax({\n url : my_ajax_object_fetch_content.ajax_url,\n type : 'POST',\n data : {'action': 'wpunity_fetch_description_action',\n 'lang': lang,\n 'externalSource': externalSource,\n 'titles': title,\n 'fulltext': fulltext},\n\n success : function(response) {\n\n\/\/ console.log(response);\n\n var json_content = jQuery.parseJSON(response);\n\n if (json_content) {\n\n if (externalSource === 'Wikipedia') {\n\n if (json_content.query) {\n for (key in json_content.query.pages) {\n if (json_content.query.pages[key].extract) {\n\n description_dom['multi-line'].value = json_content.query.pages[key].extract.trim();\n\n description_dom[1].style.display = 'none';\n } else {\n \/\/tinymce.activeEditor.setContent(json_content.query.pages[key].extract.trim());\n\n console.log(\"Nothing found 151\");\n alert(\"Nothing found in Wikipedia\");\n\n \/\/tinymce.activeEditor.setContent(response);\n\n\n }\n }\n }\n } else if (externalSource === 'Europeana') {\n\n console.log(json_content);\n\n if(json_content.items.length > 0 ){\n\n for (var l=0; l'+fname+'<\/a>';\n\n document.getElementById(whichimage + \"_title\").innerHTML = 'More info';\n\n document.getElementById(whichimage + \"_title\").href = json_content.query.pages[key].imageinfo[0].descriptionurl;\n\n j++;\n }\n }\n } else {\n console.log(\"Nothing found 151\");\n }\n } else {\n\n\n if (json_content.itemsCount > 0) {\n\n for(j=0; j'+fname+'<\/a>';;\n\n document.getElementById(whichvideo + \"_title\").innerHTML = \"----\";\n\n }\n }\n } else {\n console.log(\"Nothing found 151\");\n }\n } else {\n\n\n if (json_content.itemsCount > 0) {\n\n for(j=0; j- Minors (wikipedia label)\n\/**\n * AJAX: FETCH CONTENT FOR DESCRIPTION\n * @param externalSource either \"Wikipedia\" or \"Europeana\"\n *\/\nfunction wpunity_fetchDescriptionAjaxFrontEnd( externalSource, title, description_dom ){\n\n \/\/document.getElementById('wpunity_fetchDescription_bt').innerHTML = \"Fetching\";\n \/\/externalSource = document.getElementById(\"fetch_source\").options[document.getElementById(\"fetch_source\").selectedIndex].value;\n \/\/lang document.getElementById(\"fetch_lang\").options[document.getElementById(\"fetch_lang\").selectedIndex].value;\n\n \/\/ Replace empty spaces with underscores\n var title = title.replace(new RegExp(\" \", 'g'),\"_\"); \/\/ document.getElementById(\"wpunity_titles_search\").value.replace(\" \",\"%20\");\n\n\n var lang = \"en\";\n\n for (var j=0; j< title.length; j++)\n if ( title.charCodeAt(j) > 902 && title.charCodeAt(j) < 974 ){\n lang = \"el\";\n break;\n }\n\n\n\n var fulltext = '';\n\n var reqCompile = jQuery.ajax({\n url : my_ajax_object_fetch_content.ajax_url,\n type : 'POST',\n data : {'action': 'wpunity_fetch_description_action',\n 'lang': lang,\n 'externalSource': externalSource,\n 'titles': title,\n 'fulltext': fulltext},\n\n success : function(response) {\n\n\/\/ console.log(response);\n\n var json_content = jQuery.parseJSON(response);\n\n if (json_content) {\n\n if (externalSource === 'Wikipedia') {\n\n if (json_content.query) {\n for (key in json_content.query.pages) {\n if (json_content.query.pages[key].extract) {\n\n description_dom['multi-line'].value = \"(Wikipedia)\" + \"\\n\" + json_content.query.pages[key].extract.trim();\n\n description_dom[1].style.display = 'none';\n } else {\n \/\/tinymce.activeEditor.setContent(json_content.query.pages[key].extract.trim());\n\n console.log(\"Nothing found 151\");\n alert(\"Nothing found in Wikipedia\");\n\n \/\/tinymce.activeEditor.setContent(response);\n\n\n }\n }\n }\n } else if (externalSource === 'Europeana') {\n\n console.log(json_content);\n\n description_dom['multi-line'].value += \"(Europeana)\" + \"\\n\";\n\n if(json_content.items.length > 0 ){\n\n for (var l=0; l'+fname+'<\/a>';\n\n document.getElementById(whichimage + \"_title\").innerHTML = 'More info';\n\n document.getElementById(whichimage + \"_title\").href = json_content.query.pages[key].imageinfo[0].descriptionurl;\n\n j++;\n }\n }\n } else {\n console.log(\"Nothing found 151\");\n }\n } else {\n\n\n if (json_content.itemsCount > 0) {\n\n for(j=0; j'+fname+'<\/a>';;\n\n document.getElementById(whichvideo + \"_title\").innerHTML = \"----\";\n\n }\n }\n } else {\n console.log(\"Nothing found 151\");\n }\n } else {\n\n\n if (json_content.itemsCount > 0) {\n\n for(j=0; j"} {"text":"#!\/usr\/bin\/env node\nvar Spotify = require('node-spotify');\nvar DweetIO = require('.\/DweetIO');\n\nvar SpotifyRequest = function(username, password, readyCallback) {\n\tvar instance = this;\n\tthis.dweetio = new DweetIO();\n\tthis.dweetio.listenFor('jme-spotify-request', function(dweet) {\n\t\tconsole.log(\"Request received.\");\n\t\tinstance.request(dweet);\n\t});\n\n\tthis.spotify = new Spotify({ appkeyFile: 'api_spotify.key' });\n\tthis.spotify.on({\n\t\t\"ready\": readyCallback\n\t});\n\tthis.spotify.login(username, password, false, false);\n\n};\n\nSpotifyRequest.prototype.request = function(dweet) {\n\tvar instance = this;\n\tvar callback = function(track) {\n\t\tif (track.isLoaded === true) {\n\t\t\tconsole.log(\"Sending Answer.\");\n\t\t\tinstance.dweetio.sendData('jme-spotify-answer', track);\n\t\t}\n\t};\n\tif (dweet.content['type'] &&\n\t\t(dweet.content['uri'] || dweet.content['search']))\n\t{\n\t\tconsole.log(\"Request type: \" + dweet.content.type + \".\");\n\t\tif (dweet.content.type == \"name-track\") {\n\t\t\tthis.loadTrack(dweet.content.uri, callback);\n\t\t} else if (dweet.content.type == \"search-track\") {\n\t\t\tthis.searchTrack(dweet.content.search, callback);\n\t\t}\n\t}\n};\n\nSpotifyRequest.prototype.loadTrack = function(trackLink, callback) {\n\tvar track = this.spotify.createFromLink(trackLink);\n\tif (track.isLoaded !== false) {\n\t\tconsole.log(\"Track was loaded, serving from cache.\");\n\t\tcallback(track);\n\t} else {\n\t\tconsole.log(\"Waiting for track to load.\");\n\t\tthis.spotify.waitForLoaded([track], callback);\n\t}\n};\n\nSpotifyRequest.prototype.searchTrack = function(searchText, callback) {\n\tvar instance = this;\n\tvar search = new this.spotify.Search(searchText);\n\tsearch.execute(function(err, searchResult) {\n\t\tconsole.log(\"Search Executed.\");\n\t\tif (!err) {\n\t\t\tif (search.totalTracks > 0) {\n\t\t\t\tcallback(search.tracks[0]);\n\t\t\t}\n\t\t}\n\t});\n};\n\nvar sq = new SpotifyRequest('joeasaurus', 'password');\nAdded reqType to answer for better context.#!\/usr\/bin\/env node\nvar Spotify = require('node-spotify');\nvar DweetIO = require('.\/DweetIO');\n\nvar SpotifyRequest = function(username, password, readyCallback) {\n\tvar instance = this;\n\tthis.dweetio = new DweetIO();\n\tthis.dweetio.listenFor('jme-spotify-request', function(dweet) {\n\t\tconsole.log(\"Request received.\");\n\t\tinstance.request(dweet);\n\t});\n\n\tthis.spotify = new Spotify({ appkeyFile: 'api_spotify.key' });\n\tthis.spotify.on({\n\t\t\"ready\": readyCallback\n\t});\n\tthis.spotify.login(username, password, false, false);\n\n};\n\nSpotifyRequest.prototype.request = function(dweet) {\n\tvar instance = this;\n\tvar callback = function(reqType, answer) {\n\t\tif (answer.isLoaded === true) {\n\t\t\tconsole.log(\"Sending Answer.\");\n\t\t\tinstance.dweetio.sendData('jme-spotify-answer', {\n\t\t\t\t\"type\": reqType,\n\t\t\t\t\"answer\": answer\n\t\t\t});\n\t\t}\n\t};\n\tif (dweet.content['type'] &&\n\t\t(dweet.content['uri'] || dweet.content['search']))\n\t{\n\t\tconsole.log(\"Request type: \" + dweet.content.type + \".\");\n\t\tif (dweet.content.type == \"name-track\") {\n\t\t\tthis.loadTrack(dweet.content.uri, function(track) {callback(dweet.content.type, track);});\n\t\t} else if (dweet.content.type == \"search-track\") {\n\t\t\tthis.searchTrack(dweet.content.search, function(track) {callback(dweet.content.type, track);});\n\t\t}\n\t}\n};\n\nSpotifyRequest.prototype.loadTrack = function(trackLink, callback) {\n\tvar track = this.spotify.createFromLink(trackLink);\n\tif (track.isLoaded !== false) {\n\t\tconsole.log(\"Track was loaded, serving from cache.\");\n\t\tcallback(track);\n\t} else {\n\t\tconsole.log(\"Waiting for track to load.\");\n\t\tthis.spotify.waitForLoaded([track], callback);\n\t}\n};\n\nSpotifyRequest.prototype.searchTrack = function(searchText, callback) {\n\tvar instance = this;\n\tvar search = new this.spotify.Search(searchText);\n\tsearch.execute(function(err, searchResult) {\n\t\tconsole.log(\"Search Executed.\");\n\t\tif (!err) {\n\t\t\tif (search.totalTracks > 0) {\n\t\t\t\tcallback(search.tracks[0]);\n\t\t\t}\n\t\t}\n\t});\n};\n\nvar sq = new SpotifyRequest('joeasaurus', 'password');\n<|endoftext|>"} {"text":"function MurderPlayers(){\n\tthis.canRepeat = true;\t\n\tthis.playerList = []; \/\/what players are already in the medium when i trigger?\n\tthis.murderers = [];\n\t\n\tthis.trigger = function(playerList){\n\t\tthis.playerList = playerList;\n\t\tthis.murderers = [];\n\t\t\/\/select a random player. if they've been triggered, random chance of going murderMode if enemies (based on how triggered.)\n\t\tthis.player = getRandomElementFromArray(availablePlayers);\n\t\tfor(var i = 0; i null;\n\t}\n\t\n\tthis.renderContent = function(div){\n\t\tdiv.append(\"
\"+this.contentForRender(div));\n\t}\n\t\n\tthis.friendsOfVictimHateYou = function(victim, murderer, livePlayers){\n\t\t\/\/just, fuck that guy.\n\t\tvar ret = \"\";\n\t\tfor(var i = 0; i 0){ \/\/iff i actually liked the guy.\n\t\t\t\t\tfor(var j = 0; j< rv.value; j++){\n\t\t\t\t\t\trm.decrease();\n\t\t\t\t\t}\n\t\t\t\t\tret += \" The \" + p.htmlTitle() + \" is pretty pissed that their friend was killed. \";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t\t\n\t}\n\t\n\t\/\/not necessarily murder mode player, could be self defense.\n\tthis.renderMurder = function(div,murderer, victim){\n\t\tvar divID = (div.attr(\"id\")) + \"_\" + victim.chatHandle;\n\t\tvar canvasHTML = \"
<\/canvas>\";\n\t\tdiv.append(canvasHTML);\n\t\tvar canvas = document.getElementById(\"canvas\"+ divID);\n\t\t\n\t\tvar pSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(pSpriteBuffer,murderer,1000)\n\n\t\tvar dSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(dSpriteBuffer,victim,1000)\n\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, pSpriteBuffer,-100,0)\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, dSpriteBuffer,100,0)\n\n\t}\n\t\n\t\/\/diamond faces murderer, calms them the hell down and hug bumps are shared.\n\tthis.renderDiamonds = function(div, murderer, diamond){\n\t\tvar divID = (div.attr(\"id\")) + \"_\" + diamond.chatHandle;\n\t\tvar canvasHTML = \"
<\/canvas>\";\n\t\tdiv.append(canvasHTML);\n\t\tvar canvas = document.getElementById(\"canvas\"+ divID);\n\t\t\n\t\tvar pSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(pSpriteBuffer,murderer,1000)\n\t\t\n\n\t\tvar dSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSpriteTurnways(dSpriteBuffer,diamond,1000)\n\n\t\tvar x = 100;\n\t\tif(murderer.isTroll == true || diamond.isTroll == true){ \/\/humans have regular romance, but if even one is a troll, this is romance.\n\t\t\tvar diSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\t\tdrawDiamond(diSpriteBuffer,1000)\n\t\t\tx = 50; \/\/stand closer cause romance\n\t\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, diSpriteBuffer,75,0)\n\t\t}\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, pSpriteBuffer,-100,0)\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, dSpriteBuffer,x,0) \n\t}\n\t\n\t\/\/random Auspistice settles their shit down. this will probably be pretty rare.\n\tthis.renderClubs = function(div, murderer, victim, club){\n\t\talert(\"clubs)\")\n\t\tvar divID = (div.attr(\"id\")) + \"_\" + club.chatHandle;\n\t\tvar canvasHTML = \"
<\/canvas>\";\n\t\tdiv.append(canvasHTML);\n\t\tvar canvas = document.getElementById(\"canvas\"+ divID);\n\t\t\n\t\tvar pSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(pSpriteBuffer,murderer,1000)\n\t\t\n\t\tvar vSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(vSpriteBuffer,victim,1000)\n\n\t\tvar dSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSpriteTurnways(dSpriteBuffer,club,1000) \/\/facing non-middle leafs\n\n\n\t\tif(murderer.isTroll == true || club.isTroll == true || club.isTroll == true){ \/\/humans have regular romance, but if even one is a troll, this is romance.\n\t\t\tvar diSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\t\tdrawClub(diSpriteBuffer,1000) \/\/Auspisticism\n\t\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, diSpriteBuffer,375,50)\n\t\t}\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, pSpriteBuffer,-100,0)\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, vSpriteBuffer,100,0) \n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, dSpriteBuffer,400,0) \n\t}\n\t\n\tthis.contentForRender = function(div){\n\t\tvar livePlayers = this.playerList; \/\/just because they are alive doesn't mean they are in the medium\n\t\tfor(var i = 0; i 2){\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead the Bloody Thing happens and the \" + m.htmlTitle() + \" is calmed down, and hug bumps are shared. \";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tworstEnemy.checkBloodBoost(livePlayers);\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderDiamonds(div, m, worstEnemy);\n\t\t\t\t\t\/\/don't hate your new diamond buddy\n\t\t\t\t\tvar r = m.getRelationshipWith(worstEnemy);\n\t\t\t\t\tr.value = 1;\n\t\t\t\t\treturn ret; \/\/don't try to murder. (and also blood powers stop any other potential murders);\n\t\t\t\t}\n\t\t\t\tvar r = worstEnemy.getRelationshipWith(m)\n\t\t\t\tif(r.type() == r.goodBig ){\n\t\t\t\t\t\/\/moiralligance.\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead gets talked down hardcore. Shit is downright tender.\";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderDiamonds(div, m, worstEnemy);\n\t\t\t\t\tvar r = m.getRelationshipWith(worstEnemy);\n\t\t\t\t\tr.value = 1;\n\t\t\t\t}else if(ausp != null && r.type() == r.badBig){ \/\/they hate you back....\n\t\t\t\t\t\/\/\/auspitism, but who is middle leaf?\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \"(who hates them back just as much), but instead is interupted by the \" + ausp.htmlTitle() + \", who convinces everyone to settle their shit down. \";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderClubs(div, m, worstEnemy,ausp);\n\t\t\t\t\tvar r = m.getRelationshipWith(ausp); \/\/neutral to middle leaf, but unchanged about each other.\n\t\t\t\t\tr.value = 1;\n\t\t\t\t\tvar r2 = worstEnemy.getRelationshipWith(ausp);\n\t\t\t\t\tr2.value = 1;\n\n\t\t\t\t}else if(worstEnemy.power < m.power*2){ \/\/more likely to kill enemy than be killed. element of surprise\n\t\t\t\t\tm.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tworstEnemy.causeOfDeath = \"fighting the \" + m.htmlTitle();\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" brutally murders that asshole, the \" + worstEnemy.htmlTitle() +\". \";\n\t\t\t\t\tret += this.friendsOfVictimHateYou(worstEnemy, m, livePlayers);\n\t\t\t\t\tworstEnemy.dead = true;\n\t\t\t\t\tvar r = worstEnemy.getRelationshipWith(m);\n\t\t\t\t\tr.value = -10; \/\/you are not happy with murderer\n\t\t\t\t\tm.victimBlood = worstEnemy.bloodColor;\n\t\t\t\t\tthis.renderMurder(div, m, worstEnemy)\n\t\t\t\t}else{\n\t\t\t\t\tworstEnemy.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tm.causeOfDeath = \"being put down like a rabid dog by \" + worstEnemy.htmlTitle()\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to brutally murders that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \",but instead gets murdered first, in self-defense. \";\n\t\t\t\t\tm.dead = true;\n\t\t\t\t\tvar r = worstEnemy.getRelationshipWith(m);\n\t\t\t\t\tr.value = -10; \/\/you are not happy with murderer\n\t\t\t\t\tworstEnemy.victimBlood = m.bloodColor;\n\t\t\t\t\tthis.renderMurder(div,worstEnemy, m);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tret += \" The \" + m.htmlTitle() + \" can't find anybody they hate enough to murder. They calm down a little. \";\n\t\t\t\tm.triggerLevel += -1;\n\t\t\t}\n\t\t}\n\t\tremoveFromArray(m, availablePlayers);\n\t\treturn ret;\n\t}\n\t\n\n\t\n\tthis.content = function(){\n\t\tvar livePlayers = this.playerList; \/\/just because they are alive doesn't mean they are in the medium\n\t\tfor(var i = 0; i 2){\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead the Bloody Thing happens and the \" + m.htmlTitle() + \" is calmed down, and hug bumps are shared. \";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tworstEnemy.checkBloodBoost(livePlayers);\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\treturn ret; \/\/don't try to murder. (and also blood powers stop any other potential murders);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar r = worstEnemy.getRelationshipWith(m)\n\t\t\t\tif(r.type() == r.goodBig ){\n\t\t\t\t\t\/\/moiralligance.\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead gets talked down hardcore. Shit is downright tender.\";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderDiamonds(div, m, worstEnemy);\n\t\t\t\t}else if(worstEnemy.power < m.power*2){ \/\/more likely to kill enemy than be killed. element of surprise\n\t\t\t\t\tm.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tworstEnemy.causeOfDeath = \"fighting the \" + m.htmlTitle();\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" brutally murders that asshole, the \" + worstEnemy.htmlTitle() +\". \";\n\t\t\t\t\tret += this.friendsOfVictimHateYou(worstEnemy, m, livePlayers);\n\t\t\t\t\tworstEnemy.dead = true;\n\t\t\t\t\tm.victimBlood = worstEnemy.bloodColor;\n\t\t\t\t}else{\n\t\t\t\t\tworstEnemy.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tm.causeOfDeath = \"being put down like a rabid dog by \" + worstEnemy.htmlTitle()\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to brutally murders that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \",but instead gets murdered first, in self-defense. \";\n\t\t\t\t\tm.dead = true;\n\t\t\t\t\tworstEnemy.victimBlood = m.bloodColor;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tret += \" The \" + m.htmlTitle() + \" can't find anybody they hate enough to murder. They calm down a little. \";\n\t\t\t\tm.triggerLevel += -1;\n\t\t\t}\n\t\t}\n\t\tremoveFromArray(m, availablePlayers);\n\t\treturn ret;\n\t}\n}debuggingfunction MurderPlayers(){\n\tthis.canRepeat = true;\t\n\tthis.playerList = []; \/\/what players are already in the medium when i trigger?\n\tthis.murderers = [];\n\t\n\tthis.trigger = function(playerList){\n\t\tthis.playerList = playerList;\n\t\tthis.murderers = [];\n\t\t\/\/select a random player. if they've been triggered, random chance of going murderMode if enemies (based on how triggered.)\n\t\tthis.player = getRandomElementFromArray(availablePlayers);\n\t\tfor(var i = 0; i null;\n\t}\n\t\n\tthis.renderContent = function(div){\n\t\tdiv.append(\"
\"+this.contentForRender(div));\n\t}\n\t\n\tthis.friendsOfVictimHateYou = function(victim, murderer, livePlayers){\n\t\t\/\/just, fuck that guy.\n\t\tvar ret = \"\";\n\t\tfor(var i = 0; i 0){ \/\/iff i actually liked the guy.\n\t\t\t\t\tfor(var j = 0; j< rv.value; j++){\n\t\t\t\t\t\trm.decrease();\n\t\t\t\t\t}\n\t\t\t\t\tret += \" The \" + p.htmlTitle() + \" is pretty pissed that their friend was killed. \";\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn ret;\n\t\t\n\t}\n\t\n\t\/\/not necessarily murder mode player, could be self defense.\n\tthis.renderMurder = function(div,murderer, victim){\n\t\tvar divID = (div.attr(\"id\")) + \"_\" + victim.chatHandle;\n\t\tvar canvasHTML = \"
<\/canvas>\";\n\t\tdiv.append(canvasHTML);\n\t\tvar canvas = document.getElementById(\"canvas\"+ divID);\n\t\t\n\t\tvar pSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(pSpriteBuffer,murderer,1000)\n\n\t\tvar dSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(dSpriteBuffer,victim,1000)\n\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, pSpriteBuffer,-100,0)\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, dSpriteBuffer,100,0)\n\n\t}\n\t\n\t\/\/diamond faces murderer, calms them the hell down and hug bumps are shared.\n\tthis.renderDiamonds = function(div, murderer, diamond){\n\t\tvar divID = (div.attr(\"id\")) + \"_\" + diamond.chatHandle;\n\t\tvar canvasHTML = \"
<\/canvas>\";\n\t\tdiv.append(canvasHTML);\n\t\tvar canvas = document.getElementById(\"canvas\"+ divID);\n\t\t\n\t\tvar pSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(pSpriteBuffer,murderer,1000)\n\t\t\n\n\t\tvar dSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSpriteTurnways(dSpriteBuffer,diamond,1000)\n\n\t\tvar x = 100;\n\t\tif(murderer.isTroll == true || diamond.isTroll == true){ \/\/humans have regular romance, but if even one is a troll, this is romance.\n\t\t\tvar diSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\t\tdrawDiamond(diSpriteBuffer,1000)\n\t\t\tx = 50; \/\/stand closer cause romance\n\t\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, diSpriteBuffer,75,0)\n\t\t}\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, pSpriteBuffer,-100,0)\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, dSpriteBuffer,x,0) \n\t}\n\t\n\t\/\/random Auspistice settles their shit down. this will probably be pretty rare.\n\tthis.renderClubs = function(div, murderer, victim, club){\n\t\t\/\/alert(\"clubs)\")\n\t\tvar divID = (div.attr(\"id\")) + \"_\" + club.chatHandle;\n\t\tvar canvasHTML = \"
<\/canvas>\";\n\t\tdiv.append(canvasHTML);\n\t\tvar canvas = document.getElementById(\"canvas\"+ divID);\n\t\t\n\t\tvar pSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(pSpriteBuffer,murderer,1000)\n\t\t\n\t\tvar vSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSprite(vSpriteBuffer,victim,1000)\n\n\t\tvar dSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\tdrawSpriteTurnways(dSpriteBuffer,club,1000) \/\/facing non-middle leafs\n\n\n\t\tif(murderer.isTroll == true || club.isTroll == true || club.isTroll == true){ \/\/humans have regular romance, but if even one is a troll, this is romance.\n\t\t\tvar diSpriteBuffer = getBufferCanvas(document.getElementById(\"sprite_template\"));\n\t\t\tdrawClub(diSpriteBuffer,1000) \/\/Auspisticism\n\t\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, diSpriteBuffer,375,50)\n\t\t}\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, pSpriteBuffer,-100,0)\n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, vSpriteBuffer,100,0) \n\t\tcopyTmpCanvasToRealCanvasAtPos(canvas, dSpriteBuffer,400,0) \n\t}\n\t\n\tthis.contentForRender = function(div){\n\t\tvar livePlayers = this.playerList; \/\/just because they are alive doesn't mean they are in the medium\n\t\tfor(var i = 0; i 2){\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead the Bloody Thing happens and the \" + m.htmlTitle() + \" is calmed down, and hug bumps are shared. \";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tworstEnemy.checkBloodBoost(livePlayers);\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderDiamonds(div, m, worstEnemy);\n\t\t\t\t\t\/\/don't hate your new diamond buddy\n\t\t\t\t\tvar r = m.getRelationshipWith(worstEnemy);\n\t\t\t\t\tr.value = 1;\n\t\t\t\t\treturn ret; \/\/don't try to murder. (and also blood powers stop any other potential murders);\n\t\t\t\t}\n\t\t\t\tvar r = worstEnemy.getRelationshipWith(m)\n\t\t\t\tif(r.type() == r.goodBig ){\n\t\t\t\t\t\/\/moiralligance.\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead gets talked down hardcore. Shit is downright tender.\";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderDiamonds(div, m, worstEnemy);\n\t\t\t\t\tvar r = m.getRelationshipWith(worstEnemy);\n\t\t\t\t\tr.value = 1;\n\t\t\t\t}else if(ausp != null && r.type() == r.badBig){ \/\/they hate you back....\n\t\t\t\t\t\/\/\/auspitism, but who is middle leaf?\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \"(who hates them back just as much), but instead is interupted by the \" + ausp.htmlTitle() + \", who convinces everyone to settle their shit down. \";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderClubs(div, m, worstEnemy,ausp);\n\t\t\t\t\tvar r = m.getRelationshipWith(ausp); \/\/neutral to middle leaf, but unchanged about each other.\n\t\t\t\t\tr.value = 1;\n\t\t\t\t\tvar r2 = worstEnemy.getRelationshipWith(ausp);\n\t\t\t\t\tr2.value = 1;\n\n\t\t\t\t}else if(worstEnemy.power < m.power*2){ \/\/more likely to kill enemy than be killed. element of surprise\n\t\t\t\t\tm.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tworstEnemy.causeOfDeath = \"fighting the \" + m.htmlTitle();\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" brutally murders that asshole, the \" + worstEnemy.htmlTitle() +\". \";\n\t\t\t\t\tret += this.friendsOfVictimHateYou(worstEnemy, m, livePlayers);\n\t\t\t\t\tworstEnemy.dead = true;\n\t\t\t\t\tvar r = worstEnemy.getRelationshipWith(m);\n\t\t\t\t\tr.value = -10; \/\/you are not happy with murderer\n\t\t\t\t\tm.victimBlood = worstEnemy.bloodColor;\n\t\t\t\t\tthis.renderMurder(div, m, worstEnemy)\n\t\t\t\t}else{\n\t\t\t\t\tworstEnemy.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tm.causeOfDeath = \"being put down like a rabid dog by \" + worstEnemy.htmlTitle()\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to brutally murders that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \",but instead gets murdered first, in self-defense. \";\n\t\t\t\t\tm.dead = true;\n\t\t\t\t\tvar r = worstEnemy.getRelationshipWith(m);\n\t\t\t\t\tr.value = -10; \/\/you are not happy with murderer\n\t\t\t\t\tworstEnemy.victimBlood = m.bloodColor;\n\t\t\t\t\tthis.renderMurder(div,worstEnemy, m);\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tret += \" The \" + m.htmlTitle() + \" can't find anybody they hate enough to murder. They calm down a little. \";\n\t\t\t\tm.triggerLevel += -1;\n\t\t\t}\n\t\t}\n\t\tremoveFromArray(m, availablePlayers);\n\t\treturn ret;\n\t}\n\t\n\n\t\n\tthis.content = function(){\n\t\tvar livePlayers = this.playerList; \/\/just because they are alive doesn't mean they are in the medium\n\t\tfor(var i = 0; i 2){\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead the Bloody Thing happens and the \" + m.htmlTitle() + \" is calmed down, and hug bumps are shared. \";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tworstEnemy.checkBloodBoost(livePlayers);\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\treturn ret; \/\/don't try to murder. (and also blood powers stop any other potential murders);\n\t\t\t\t}\n\t\t\t\t\n\t\t\t\tvar r = worstEnemy.getRelationshipWith(m)\n\t\t\t\tif(r.type() == r.goodBig ){\n\t\t\t\t\t\/\/moiralligance.\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to murder that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \", but instead gets talked down hardcore. Shit is downright tender.\";\n\t\t\t\t\tm.murderMode = false;\n\t\t\t\t\tm.triggerLevel = 1;\n\t\t\t\t\tthis.renderDiamonds(div, m, worstEnemy);\n\t\t\t\t}else if(worstEnemy.power < m.power*2){ \/\/more likely to kill enemy than be killed. element of surprise\n\t\t\t\t\tm.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tworstEnemy.causeOfDeath = \"fighting the \" + m.htmlTitle();\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" brutally murders that asshole, the \" + worstEnemy.htmlTitle() +\". \";\n\t\t\t\t\tret += this.friendsOfVictimHateYou(worstEnemy, m, livePlayers);\n\t\t\t\t\tworstEnemy.dead = true;\n\t\t\t\t\tm.victimBlood = worstEnemy.bloodColor;\n\t\t\t\t}else{\n\t\t\t\t\tworstEnemy.increasePower();\n\t\t\t\t\t\n\t\t\t\t\tm.causeOfDeath = \"being put down like a rabid dog by \" + worstEnemy.htmlTitle()\n\t\t\t\t\tret += \" The \" + m.htmlTitle() + \" attempts to brutally murders that asshole, the \" + worstEnemy.htmlTitle();\n\t\t\t\t\tret += \",but instead gets murdered first, in self-defense. \";\n\t\t\t\t\tm.dead = true;\n\t\t\t\t\tworstEnemy.victimBlood = m.bloodColor;\n\t\t\t\t}\n\t\t\t}else{\n\t\t\t\tret += \" The \" + m.htmlTitle() + \" can't find anybody they hate enough to murder. They calm down a little. \";\n\t\t\t\tm.triggerLevel += -1;\n\t\t\t}\n\t\t}\n\t\tremoveFromArray(m, availablePlayers);\n\t\treturn ret;\n\t}\n}<|endoftext|>"} {"text":"\/** @jsx React.DOM *\/\n\n\/\/ Constants\nvar Events = require('..\/Events');\nvar debug = require('..\/Helpers').debug;\n\n\/\/ Global variables\nvar store = require('..\/store');\nvar flux = require('..\/flux\/dispatcher');\n\nfunction DEBUG(text) {\n return debug('Similarity Component - ' + text);\n}\n\n\/\/ Algorithm\n\n\/\/ TODO make this threshold a parameter\nconst TIME_SIMILAR_THRESHOLD = 1000 * 60 * 60 * 24 * 2; \/\/ 48 hours\nfunction findRedundantPairs(operations) {\n DEBUG('Running findRedundantPairs algorithm...');\n DEBUG('Input: ' + operations.length + ' operations');\n var similar = [];\n\n function areSimilarOperations(a, b) {\n if (a.amount != b.amount)\n return false;\n var datediff = Math.abs(+a.date - +b.date);\n return datediff <= TIME_SIMILAR_THRESHOLD;\n }\n\n \/\/ O(n log n)\n function sortCriteria(a,b) { return a.amount - b.amount; }\n var sorted = operations.slice().sort(sortCriteria);\n for (var i = 0; i < operations.length; ++i) {\n if (i + 1 >= operations.length)\n continue;\n\n var op = sorted[i];\n var next = sorted[i+1];\n if (areSimilarOperations(op, next))\n similar.push([op, next]);\n }\n\n DEBUG(similar.length + ' pairs of similar operations found');\n return similar;\n}\n\n\/\/ Components\nvar SimilarityItemComponent = React.createClass({\n\n _deleteOperation: function() {\n flux.dispatch({\n type: Events.DELETE_OPERATION,\n operation: this.props.operation\n });\n },\n\n render: function() {\n return (\n \n {this.props.operation.date.toString()}<\/td>\n {this.props.operation.title}<\/td>\n {this.props.operation.amount}<\/td>\n
x<\/a><\/td>\n <\/tr>\n );\n }\n});\n\nvar SimilarityPairComponent = React.createClass({\n\n render: function() {\n return (\n \n \n \n <\/table>\n );\n }\n});\n\nmodule.exports = React.createClass({\n\n getInitialState: function() {\n return {\n pairs: []\n };\n },\n\n _cb: function() {\n this.setState({\n pairs: findRedundantPairs(store.operations)\n });\n },\n\n componentDidMount: function() {\n store.subscribeMaybeGet(Events.OPERATIONS_LOADED, this._cb);\n },\n\n componentWillUnmount: function() {\n store.removeListener(Events.OPERATIONS_LOADED, this._cb);\n },\n\n render: function() {\n var pairs = this.state.pairs;\n if (pairs.length === 0) {\n return (\n
No similar operations found.<\/div>\n )\n }\n\n var sim = pairs.map(function (p) {\n var key = p[0].id.toString() + p[1].id.toString();\n return ()\n });\n return (\n
\n

Similarities<\/h1>\n
\n {sim}\n <\/div>\n <\/div>)\n }\n});\n\nFixes #8: automatically transfer category of deleted similar operation.\/** @jsx React.DOM *\/\n\n\/\/ Constants\nvar Events = require('..\/Events');\nvar assert = require('..\/Helpers').assert;\nvar debug = require('..\/Helpers').debug;\n\n\/\/ Global variables\nvar store = require('..\/store');\nvar flux = require('..\/flux\/dispatcher');\n\nfunction DEBUG(text) {\n return debug('Similarity Component - ' + text);\n}\n\n\/\/ Algorithm\n\n\/\/ TODO make this threshold a parameter\nconst TIME_SIMILAR_THRESHOLD = 1000 * 60 * 60 * 24 * 1.5; \/\/ 36 hours\nfunction findRedundantPairs(operations) {\n DEBUG('Running findRedundantPairs algorithm...');\n DEBUG('Input: ' + operations.length + ' operations');\n var similar = [];\n\n function areSimilarOperations(a, b) {\n if (a.amount != b.amount)\n return false;\n var datediff = Math.abs(+a.date - +b.date);\n return datediff <= TIME_SIMILAR_THRESHOLD;\n }\n\n \/\/ O(n log n)\n function sortCriteria(a,b) { return a.amount - b.amount; }\n var sorted = operations.slice().sort(sortCriteria);\n for (var i = 0; i < operations.length; ++i) {\n if (i + 1 >= operations.length)\n continue;\n\n var op = sorted[i];\n var next = sorted[i+1];\n if (areSimilarOperations(op, next))\n similar.push([op, next]);\n }\n\n DEBUG(similar.length + ' pairs of similar operations found');\n return similar;\n}\n\n\/\/ Components\nvar SimilarityItemComponent = React.createClass({\n\n render: function() {\n return (\n

\n
{this.props.operation.date.toString()}<\/td>\n {this.props.operation.title}<\/td>\n {this.props.operation.amount}<\/td>\n Category: {store.categoryToLabel(this.props.operation.categoryId)}<\/td>\n Imported on: {new Date(this.props.operation.dateImport).toLocaleString()}<\/td>\n x<\/a><\/td>\n <\/tr>\n );\n }\n});\n\nvar SimilarityPairComponent = React.createClass({\n\n render: function() {\n\n var that = this;\n function makeOndelete(id) {\n return function() {\n assert(id === 'a' || id === 'b');\n var toDelete = that.props[id];\n var toKeep = that.props[(id === 'a') ? 'b' : 'a'];\n\n \/\/ If the one to delete had a category and the one to keep\n \/\/ doesn't, automatically transfer category.\n if (toDelete.categoryId !== -1 && toKeep.categoryId === -1) {\n var catId = toDelete.categoryId;\n flux.dispatch({\n type: Events.OPERATION_CATEGORY_CHANGED,\n operationId: toKeep.id,\n categoryId: catId\n });\n }\n\n flux.dispatch({\n type: Events.DELETE_OPERATION,\n operation: toDelete\n });\n }\n }\n\n return (\n \n \n \n <\/table>\n );\n }\n});\n\nmodule.exports = React.createClass({\n\n getInitialState: function() {\n return {\n pairs: []\n };\n },\n\n _cb: function() {\n this.setState({\n pairs: findRedundantPairs(store.operations)\n });\n },\n\n componentDidMount: function() {\n store.subscribeMaybeGet(Events.OPERATIONS_LOADED, this._cb);\n },\n\n componentWillUnmount: function() {\n store.removeListener(Events.OPERATIONS_LOADED, this._cb);\n },\n\n render: function() {\n var pairs = this.state.pairs;\n if (pairs.length === 0) {\n return (\n
No similar operations found.<\/div>\n )\n }\n\n var sim = pairs.map(function (p) {\n var key = p[0].id.toString() + p[1].id.toString();\n return ()\n });\n return (\n
\n

Similarities<\/h1>\n
\n {sim}\n <\/div>\n <\/div>)\n }\n});\n\n<|endoftext|>"} {"text":"var cacheName = 'snap-pwa';\nvar filesToCache = [\n 'snap.html',\n 'src\/morphic.js',\n 'src\/symbols.js',\n 'src\/widgets.js',\n 'src\/blocks.js',\n 'src\/threads.js',\n 'src\/objects.js',\n 'src\/scenes.js',\n 'src\/gui.js',\n 'src\/paint.js',\n 'src\/lists.js',\n 'src\/byob.js',\n 'src\/tables.js',\n 'src\/sketch.js',\n 'src\/video.js',\n 'src\/maps.js',\n 'src\/extensions.js',\n 'src\/xml.js',\n 'src\/store.js',\n 'src\/locale.js',\n 'src\/cloud.js',\n 'src\/api.js',\n 'src\/sha512.js',\n 'src\/FileSaver.min.js'\n];\n\n\/* Start the service worker and cache all of the app's content *\/\nself.addEventListener('install', function(e) {\n e.waitUntil(\n caches.open(cacheName).then(function(cache) {\n return cache.addAll(filesToCache);\n })\n );\n});\n\n\/* Serve cached content when offline *\/\nself.addEventListener('fetch', function(e) {\n e.respondWith(\n caches.match(e.request).then(function(response) {\n return response || fetch(e.request);\n })\n );\n});\nmake sure to cache libraries and media in pwavar cacheName = 'snap-pwa',\n filesToCache = [\n 'snap.html',\n\n \/\/ program\n 'src\/morphic.js',\n 'src\/symbols.js',\n 'src\/widgets.js',\n 'src\/blocks.js',\n 'src\/threads.js',\n 'src\/objects.js',\n 'src\/scenes.js',\n 'src\/gui.js',\n 'src\/paint.js',\n 'src\/lists.js',\n 'src\/byob.js',\n 'src\/tables.js',\n 'src\/sketch.js',\n 'src\/video.js',\n 'src\/maps.js',\n 'src\/extensions.js',\n 'src\/xml.js',\n 'src\/store.js',\n 'src\/locale.js',\n 'src\/cloud.js',\n 'src\/api.js',\n 'src\/sha512.js',\n 'src\/FileSaver.min.js',\n\n \/\/ translations\n 'locale\/lang-ar.js',\n 'locale\/lang-bg.js',\n 'locale\/lang-bn.js',\n 'locale\/lang-ca.js',\n 'locale\/lang-ca_VA.js',\n 'locale\/lang-cs.js',\n 'locale\/lang-de.js',\n 'locale\/lang-dk.js',\n 'locale\/lang-el.js',\n 'locale\/lang-eo.js',\n 'locale\/lang-es.js',\n 'locale\/lang-et.js',\n 'locale\/lang-eu.js',\n 'locale\/lang-fi.js',\n 'locale\/lang-fr.js',\n 'locale\/lang-gl.js',\n 'locale\/lang-he.js',\n 'locale\/lang-hi.js',\n 'locale\/lang-hr.js',\n 'locale\/lang-hu.js',\n 'locale\/lang-ia.js',\n 'locale\/lang-id.js',\n 'locale\/lang-it.js',\n 'locale\/lang-ja_HIRA.js',\n 'locale\/lang-ja.js',\n 'locale\/lang-kn.js',\n 'locale\/lang-ko.js',\n 'locale\/lang-ml.js',\n 'locale\/lang-nl.js',\n 'locale\/lang-no.js',\n 'locale\/lang-pl.js',\n 'locale\/lang-pt_BR.js',\n 'locale\/lang-pt.js',\n 'locale\/lang-ro.js',\n 'locale\/lang-ru.js',\n 'locale\/lang-si.js',\n 'locale\/lang-sk.js',\n 'locale\/lang-sv.js',\n 'locale\/lang-ta.js',\n 'locale\/lang-te.js',\n 'locale\/lang-tr.js',\n 'locale\/lang-ua.js',\n 'locale\/lang-zh_CN.js',\n 'locale\/lang-zh_TW.js',\n\n \/\/libraries\n 'libraries\/LIBRARIES',\n\n 'libraries\/animation_module.xml',\n 'libraries\/apl.xml',\n 'libraries\/audioComp_module.xml',\n 'libraries\/bar-charts.xml',\n 'libraries\/biginteger.js',\n 'libraries\/bignumbers.xml',\n 'libraries\/bignums.js',\n 'libraries\/cases.xml',\n 'libraries\/colors.xml',\n 'libraries\/Eisenbergification.xml',\n 'libraries\/frequency_distribution_module.xml',\n 'libraries\/httpBlocks.xml',\n 'libraries\/HummingbirdBlocks.xml',\n 'libraries\/iteration-composition.xml',\n 'libraries\/leap-library.xml',\n 'libraries\/list-utilities.xml',\n 'libraries\/localstorage_module.xml',\n 'libraries\/make-variables.xml',\n 'libraries\/maps_module.xml',\n 'libraries\/parallel_module.xml',\n 'libraries\/pixel_module.xml',\n 'libraries\/schemeNumber.js',\n 'libraries\/serial_module.xml',\n 'libraries\/speech_module.xml',\n 'libraries\/stream-tools.xml',\n 'libraries\/strings.xml',\n 'libraries\/textCostumes_module.xml',\n 'libraries\/try-catch.xml',\n 'libraries\/variadic-reporters.xml',\n 'libraries\/word-sentence.xml',\n\n \/\/costumes\n 'Costumes\/COSTUMES',\n\n 'Costumes\/abby-a.svg',\n 'Costumes\/abby-b.svg',\n 'Costumes\/abby-c.svg',\n 'Costumes\/abby-d.svg',\n 'Costumes\/airplane2.png',\n 'Costumes\/alonzo.png',\n 'Costumes\/Alonzo3D.png',\n 'Costumes\/alonzo.svg',\n 'Costumes\/amon.gif',\n 'Costumes\/anina_pop_down.png',\n 'Costumes\/anina_pop_front.png',\n 'Costumes\/anina_pop_L_arm.png',\n 'Costumes\/anina_pop_left.png',\n 'Costumes\/anina_pop_R_arm.png',\n 'Costumes\/anina_pop_right.png',\n 'Costumes\/anina_pop_stand.png',\n 'Costumes\/anina_R_cross.png',\n 'Costumes\/anina_stance.png',\n 'Costumes\/anina_top_freeze.png',\n 'Costumes\/anina_top_L_step.png',\n 'Costumes\/anina_top_R_step.png',\n 'Costumes\/anina_top_stand.png',\n 'Costumes\/anna01.png',\n 'Costumes\/anna02.png',\n 'Costumes\/anna03.png',\n 'Costumes\/anna04.png',\n 'Costumes\/anna05.png',\n 'Costumes\/anna06.png',\n 'Costumes\/anna07b.png',\n 'Costumes\/anna07c.png',\n 'Costumes\/anna07.png',\n 'Costumes\/anna08.png',\n 'Costumes\/anna09.png',\n 'Costumes\/anna10.png',\n 'Costumes\/anna11.png',\n 'Costumes\/anna12.png',\n 'Costumes\/anna-a.png',\n 'Costumes\/anna-b.png',\n 'Costumes\/apple.svg',\n 'Costumes\/arrow1-a.svg',\n 'Costumes\/arrow1-b.svg',\n 'Costumes\/arrow1-c.svg',\n 'Costumes\/arrow1-d.svg',\n 'Costumes\/avery-a.svg',\n 'Costumes\/avery-b.svg',\n 'Costumes\/avery_walking-a.svg',\n 'Costumes\/avery_walking-b.svg',\n 'Costumes\/avery_walking-c.svg',\n 'Costumes\/avery_walking-d.svg',\n 'Costumes\/AZ_pop_down.png',\n 'Costumes\/AZ_pop_front.png',\n 'Costumes\/AZ_pop_L_arm.png',\n 'Costumes\/AZ_pop_left.png',\n 'Costumes\/AZ_pop_R_arm.png',\n 'Costumes\/AZ_pop_right.png',\n 'Costumes\/AZ_pop_stand.png',\n 'Costumes\/AZ_stance.png',\n 'Costumes\/AZ_top_freeze.png',\n 'Costumes\/AZ_top_L_step.png',\n 'Costumes\/AZ_top_R_cross.png',\n 'Costumes\/AZ_top_R_step.png',\n 'Costumes\/AZ_top_stand.png',\n 'Costumes\/ball-a.svg',\n 'Costumes\/ball-b.svg',\n 'Costumes\/ball-c.svg',\n 'Costumes\/ball-d.svg',\n 'Costumes\/ballerina-a.svg',\n 'Costumes\/ballerina-b.svg',\n 'Costumes\/ballerina-c.svg',\n 'Costumes\/ballerina-d.svg',\n 'Costumes\/ball-e.svg',\n 'Costumes\/balloon1-a.svg',\n 'Costumes\/balloon1-b.svg',\n 'Costumes\/balloon1-c.svg',\n 'Costumes\/ball-soccer.svg',\n 'Costumes\/bananas.svg',\n 'Costumes\/baseball.svg',\n 'Costumes\/basketball.svg',\n 'Costumes\/bass.svg',\n 'Costumes\/bat1-a_.svg',\n 'Costumes\/bat1-b_.svg',\n 'Costumes\/bat2-a_.svg',\n 'Costumes\/bat2-b_.svg',\n 'Costumes\/beachball.svg',\n 'Costumes\/bear2-a.svg',\n 'Costumes\/bear2-b.svg',\n 'Costumes\/beetle.svg',\n 'Costumes\/bell1.svg',\n 'Costumes\/bells-a.svg',\n 'Costumes\/bells-b.svg',\n 'Costumes\/bowl-a.svg',\n 'Costumes\/bowtie-a.svg',\n 'Costumes\/bowtie-b.svg',\n 'Costumes\/boy1-standing.gif',\n 'Costumes\/boy1-walking.gif',\n 'Costumes\/boy2.gif',\n 'Costumes\/boy3.gif',\n 'Costumes\/building-a.svg',\n 'Costumes\/building-b.svg',\n 'Costumes\/building-c.svg',\n 'Costumes\/building-d.svg',\n 'Costumes\/building-e.svg',\n 'Costumes\/building-f.svg',\n 'Costumes\/building-g.svg',\n 'Costumes\/building-h.svg',\n 'Costumes\/building-i.svg',\n 'Costumes\/building-j.svg',\n 'Costumes\/bus.png',\n 'Costumes\/butterfly1-a.svg',\n 'Costumes\/butterfly1-b_.svg',\n 'Costumes\/butterfly2_.svg',\n 'Costumes\/butterfly3_.svg',\n 'Costumes\/button1.svg',\n 'Costumes\/button2-a.svg',\n 'Costumes\/button2-b.svg',\n 'Costumes\/button3-a.svg',\n 'Costumes\/button3-b.svg',\n 'Costumes\/button4-a.svg',\n 'Costumes\/button4-b.svg',\n 'Costumes\/button5-a.svg',\n 'Costumes\/button5-b.svg',\n 'Costumes\/cake-a.svg',\n 'Costumes\/cake-b.svg',\n 'Costumes\/calvrett_jumping.png',\n 'Costumes\/calvrett_thinking.png',\n 'Costumes\/candle1-a.svg',\n 'Costumes\/candle1-b.svg',\n 'Costumes\/candles1.svg',\n 'Costumes\/candles2.svg',\n 'Costumes\/car-bug.png',\n 'Costumes\/cassy-a.png',\n 'Costumes\/cassy-b.png',\n 'Costumes\/cassy-c.png',\n 'Costumes\/cassy_dance-a.png',\n 'Costumes\/cassy_dance-b.png',\n 'Costumes\/cassy_dance-c.png',\n 'Costumes\/cassy_dance-d.png',\n 'Costumes\/cassy-d.png',\n 'Costumes\/cat2.gif',\n 'Costumes\/cat2.svg',\n 'Costumes\/cat3.png',\n 'Costumes\/cat4.png',\n 'Costumes\/cat5.gif',\n 'Costumes\/catherine-a.png',\n 'Costumes\/catherine-b.png',\n 'Costumes\/catherine-c.png',\n 'Costumes\/catherine-d.png',\n 'Costumes\/champ99-a.png',\n 'Costumes\/champ99-b.png',\n 'Costumes\/champ99-c.png',\n 'Costumes\/champ99-d.png',\n 'Costumes\/champ99-e.png',\n 'Costumes\/champ99-f.png',\n 'Costumes\/champ99-g.png',\n 'Costumes\/cheesy-puffs.png',\n 'Costumes\/cloud-a.svg',\n 'Costumes\/cloud-b.svg',\n 'Costumes\/cloud-c.svg',\n 'Costumes\/cloud-d.svg',\n 'Costumes\/cloud.svg',\n 'Costumes\/cm_pop_L_arm.png',\n 'Costumes\/cm_pop_R_arm.png',\n 'Costumes\/cm_top_L_cross.png',\n 'Costumes\/cm_top_L_leg.png',\n 'Costumes\/cm_top_R_cross.png',\n 'Costumes\/cm_top_ready.png',\n 'Costumes\/cm_top_R_leg.png',\n 'Costumes\/cm_top_stand.png',\n 'Costumes\/convertible1.png',\n 'Costumes\/convertible2.png',\n 'Costumes\/convertible3.svg',\n 'Costumes\/cowbell.svg',\n 'Costumes\/crab-a.svg',\n 'Costumes\/crab-b.svg',\n 'Costumes\/creature1-a.svg',\n 'Costumes\/creature1-b.svg',\n 'Costumes\/creature1-c.svg',\n 'Costumes\/cymbal-a.svg',\n 'Costumes\/cymbal-b.svg',\n 'Costumes\/dan-a.png',\n 'Costumes\/dan-b.png',\n 'Costumes\/dani-a.svg',\n 'Costumes\/dani-b.svg',\n 'Costumes\/dani-c.svg',\n 'Costumes\/dee-a.svg',\n 'Costumes\/dee-b.svg',\n 'Costumes\/dee-c.svg',\n 'Costumes\/dee-d.svg',\n 'Costumes\/dee-e.svg',\n 'Costumes\/devin-a.svg',\n 'Costumes\/devin-b.svg',\n 'Costumes\/devin-c.svg',\n 'Costumes\/devin-d.svg',\n 'Costumes\/dinosaur1-a.svg',\n 'Costumes\/dinosaur1-b.svg',\n 'Costumes\/dinosaur1-c.svg',\n 'Costumes\/dinosaur1-d.svg',\n 'Costumes\/dinosaur1-e.svg',\n 'Costumes\/dinosaur1-f.svg',\n 'Costumes\/dinosaur1-g.svg',\n 'Costumes\/dinosaur2-a.svg',\n 'Costumes\/dinosaur2-b.svg',\n 'Costumes\/dinosaur3.svg',\n 'Costumes\/diver1.svg',\n 'Costumes\/diver2.svg',\n 'Costumes\/dm_freeze.png',\n 'Costumes\/dm_pop_down.png',\n 'Costumes\/dm_pop_front.png',\n 'Costumes\/dm_pop_L_arm.png',\n 'Costumes\/dm_pop_left.png',\n 'Costumes\/dm_pop_R_arm.png',\n 'Costumes\/dm_pop_right.png',\n 'Costumes\/dm_pop_stand.png',\n 'Costumes\/dm_stance.svg',\n 'Costumes\/dm_top_L_leg.png',\n 'Costumes\/dm_top_R_leg.png',\n 'Costumes\/dm_top_stand.png',\n 'Costumes\/dog1-a.svg',\n 'Costumes\/dog1-b.svg',\n 'Costumes\/dog2-a.svg',\n 'Costumes\/dog2-b.svg',\n 'Costumes\/dog2-c.svg',\n 'Costumes\/dog_puppy_back.png',\n 'Costumes\/dog_puppy_right.png',\n 'Costumes\/dog_puppy_side.png',\n 'Costumes\/dog_puppy_sit.png',\n 'Costumes\/donut.svg',\n 'Costumes\/dove1-a.svg',\n 'Costumes\/dove1-b.svg',\n 'Costumes\/dove2-a.svg',\n 'Costumes\/dove2-b.svg',\n 'Costumes\/dragon1-a.svg',\n 'Costumes\/dragon1-b.png',\n 'Costumes\/dragon1-b.svg',\n 'Costumes\/dragon2.gif',\n 'Costumes\/drum1-a.svg',\n 'Costumes\/drum1-b.svg',\n 'Costumes\/drum2-a.svg',\n 'Costumes\/drum2-b.svg',\n 'Costumes\/drum_bass-a.svg',\n 'Costumes\/drum_bass-b.svg',\n 'Costumes\/drums_conga-a.svg',\n 'Costumes\/drums_conga-b.svg',\n 'Costumes\/drum_snare-a.svg',\n 'Costumes\/drum_snare-b.svg',\n 'Costumes\/duck.svg',\n 'Costumes\/earth.svg',\n 'Costumes\/elephant-a_.svg',\n 'Costumes\/elephant-b_.svg',\n 'Costumes\/fire_hydrant.png',\n 'Costumes\/fish1.svg',\n 'Costumes\/fish2.svg',\n 'Costumes\/fish3.svg',\n 'Costumes\/flower_shape.svg',\n 'Costumes\/football_running.png',\n 'Costumes\/football_standing.png',\n 'Costumes\/fortunecookie.png',\n 'Costumes\/fox.svg',\n 'Costumes\/frog.svg',\n 'Costumes\/fruit_platter.png',\n 'Costumes\/fruitsalad.svg',\n 'Costumes\/ghost1_.svg',\n 'Costumes\/ghost2-a.svg',\n 'Costumes\/ghost2-b.svg',\n 'Costumes\/ghoul-a.svg',\n 'Costumes\/ghoul-b.svg',\n 'Costumes\/gift-a.svg',\n 'Costumes\/gift-b.svg',\n 'Costumes\/girl1-standing.gif',\n 'Costumes\/girl1-walking.gif',\n 'Costumes\/girl2-shouting.gif',\n 'Costumes\/girl2-standing.gif',\n 'Costumes\/girl3-basketball.gif',\n 'Costumes\/girl3-running.gif',\n 'Costumes\/girl3-standing.gif',\n 'Costumes\/glasses.svg',\n 'Costumes\/glass_water-a.svg',\n 'Costumes\/glass_water-b.svg',\n 'Costumes\/green_flag.svg',\n 'Costumes\/guitar_bass.svg',\n 'Costumes\/guitar_electric.svg',\n 'Costumes\/guitar.svg',\n 'Costumes\/hannah-a.png',\n 'Costumes\/hannah-b.png',\n 'Costumes\/hannah-c.png',\n 'Costumes\/hat_beanie.svg',\n 'Costumes\/hat_party2-a.svg',\n 'Costumes\/Hat.svg',\n 'Costumes\/hat_winter.svg',\n 'Costumes\/hat_wizard.svg',\n 'Costumes\/headband.svg',\n 'Costumes\/heart_code.svg',\n 'Costumes\/heart_face.svg',\n 'Costumes\/heart_love_it.svg',\n 'Costumes\/heart_purple.svg',\n 'Costumes\/heart_red.svg',\n 'Costumes\/heart_smile.svg',\n 'Costumes\/heart_sweet.svg',\n 'Costumes\/helicopter.png',\n 'Costumes\/hippo1-a.svg',\n 'Costumes\/hippo1-b.svg',\n 'Costumes\/holly1.svg',\n 'Costumes\/holly2.svg',\n 'Costumes\/home_button.svg',\n 'Costumes\/horse1-a.svg',\n 'Costumes\/horse1-b.svg',\n 'Costumes\/jaime-a.png',\n 'Costumes\/jaime-b.png',\n 'Costumes\/jaime_walking-a.png',\n 'Costumes\/jaime_walking-b.png',\n 'Costumes\/jaime_walking-c.png',\n 'Costumes\/jaime_walking-d.png',\n 'Costumes\/jaime_walking-e.png',\n 'Costumes\/jay.gif',\n 'Costumes\/jeans-a.svg',\n 'Costumes\/jeans-b.svg',\n 'Costumes\/jodi.gif',\n 'Costumes\/jo_pop_down.png',\n 'Costumes\/jo_pop_front.png',\n 'Costumes\/jo_pop_L_arm.png',\n 'Costumes\/jo_pop_left.png',\n 'Costumes\/jo_pop_R_arm.png',\n 'Costumes\/jo_pop_right.png',\n 'Costumes\/jo_pop_stand.png',\n 'Costumes\/jo_stance.png',\n 'Costumes\/jo_top_L_cross.png',\n 'Costumes\/jo_top_L_leg.png',\n 'Costumes\/jo_top_R_cross.png',\n 'Costumes\/jo_top_R_leg.png',\n 'Costumes\/jo_top_stand.png',\n 'Costumes\/keyboard-a.svg',\n 'Costumes\/keyboard-b.svg',\n 'Costumes\/keyboard-c.svg',\n 'Costumes\/keyboard-d.svg',\n 'Costumes\/key.svg',\n 'Costumes\/khalid-a.png',\n 'Costumes\/Khalid-b.png',\n 'Costumes\/khalid-c.png',\n 'Costumes\/khalid-d.png',\n 'Costumes\/knight.svg',\n 'Costumes\/ladybug2-a.svg',\n 'Costumes\/ladybug2-b.svg',\n 'Costumes\/ladybug2.svg',\n 'Costumes\/lamp.png',\n 'Costumes\/laptop.svg',\n 'Costumes\/lb_pop_down.png',\n 'Costumes\/lb_pop_front.png',\n 'Costumes\/lb_pop_L_arm.png',\n 'Costumes\/lb_pop_left.png',\n 'Costumes\/lb_pop_R_arm.png',\n 'Costumes\/lb_pop_right.png',\n 'Costumes\/lb_pop_stand.png',\n 'Costumes\/lb_stance.png',\n 'Costumes\/lb_top_L_cross.png',\n 'Costumes\/lb_top_L_leg.png',\n 'Costumes\/lb_top_R_cross.png',\n 'Costumes\/lb_top_R_leg.png',\n 'Costumes\/lb_top_stand.png',\n 'Costumes\/lightning.svg',\n 'Costumes\/lion-a.svg',\n 'Costumes\/lion-b.svg',\n 'Costumes\/lioness.svg',\n 'Costumes\/lorenz01.png',\n 'Costumes\/lorenz02.png',\n 'Costumes\/lorenz03.png',\n 'Costumes\/lorenz04.png',\n 'Costumes\/lorenz05.png',\n 'Costumes\/lorenz06.png',\n 'Costumes\/lorenz07b.png',\n 'Costumes\/lorenz07.png',\n 'Costumes\/magiccarpet.png',\n 'Costumes\/magicwand.svg',\n 'Costumes\/marble-building.png',\n 'Costumes\/marissa-crouching.gif',\n 'Costumes\/marissa.gif',\n 'Costumes\/marissa-sitting.gif',\n 'Costumes\/maya.png',\n 'Costumes\/microphonestand.svg',\n 'Costumes\/microphone.svg',\n 'Costumes\/monkey1-a.svg',\n 'Costumes\/monkey1-b.svg',\n 'Costumes\/monkey2-a.svg',\n 'Costumes\/monkey2-b.svg',\n 'Costumes\/monkey2-c.svg',\n 'Costumes\/mori.png',\n 'Costumes\/mouse1-a.svg',\n 'Costumes\/mouse1-b.svg',\n 'Costumes\/muffin-a.svg',\n 'Costumes\/muffin-b.svg',\n 'Costumes\/octopus-a.svg',\n 'Costumes\/octopus-b.svg',\n 'Costumes\/orange2-a.svg',\n 'Costumes\/orange2-b.svg',\n 'Costumes\/orange2-c.svg',\n 'Costumes\/orange.svg',\n 'Costumes\/paddle.svg',\n 'Costumes\/palmtree.gif',\n 'Costumes\/parrot2-a.svg',\n 'Costumes\/parrot2-b.svg',\n 'Costumes\/parrot-a.svg',\n 'Costumes\/parrot-b.svg',\n 'Costumes\/partyhat1.svg',\n 'Costumes\/paul.gif',\n 'Costumes\/pencil-a.svg',\n 'Costumes\/pencil-b.svg',\n 'Costumes\/penguin1.svg',\n 'Costumes\/penguin1_talk-a.svg',\n 'Costumes\/penguin1_talk-b.svg',\n 'Costumes\/penguin2.svg',\n 'Costumes\/penguin2_talk-a.svg',\n 'Costumes\/penguin2_talk-b.svg',\n 'Costumes\/penguin3-a.svg',\n 'Costumes\/penguin3-b.svg',\n 'Costumes\/penguin3-c.svg',\n 'Costumes\/piano.svg',\n 'Costumes\/planet2.svg',\n 'Costumes\/princess.svg',\n 'Costumes\/prince.svg',\n 'Costumes\/rainbow.svg',\n 'Costumes\/referee.gif',\n 'Costumes\/reindeer.svg',\n 'Costumes\/robot1.svg',\n 'Costumes\/rocks.svg',\n 'Costumes\/rory.png',\n 'Costumes\/ruby-a.png',\n 'Costumes\/ruby-b.png',\n 'Costumes\/sail-boat.png',\n 'Costumes\/sam.gif',\n 'Costumes\/saxophone-a.svg',\n 'Costumes\/saxophone-b.svg',\n 'Costumes\/scarf1.svg',\n 'Costumes\/scarf2.svg',\n 'Costumes\/shark-a_.svg',\n 'Costumes\/shark-b_.svg',\n 'Costumes\/shark-c_.svg',\n 'Costumes\/shirt2-a2.svg',\n 'Costumes\/shirt2-a.svg',\n 'Costumes\/shirt-a.svg',\n 'Costumes\/shirt_blouse.svg',\n 'Costumes\/shirt-b.svg',\n 'Costumes\/shirt_collar-a.svg',\n 'Costumes\/shirt_collar-b.svg',\n 'Costumes\/shirt_collar-c.svg',\n 'Costumes\/shoes1.svg',\n 'Costumes\/shoes2.svg',\n 'Costumes\/Singer1.svg',\n 'Costumes\/skates.svg',\n 'Costumes\/sl_pop_L_arm.png',\n 'Costumes\/sl_pop_R_arm.png',\n 'Costumes\/sl_top_L_cross.png',\n 'Costumes\/sl_top_L_leg.png',\n 'Costumes\/sl_top_R_cross.png',\n 'Costumes\/sl_top_ready.png',\n 'Costumes\/sl_top_R_leg.png',\n 'Costumes\/sl_top_stand.png',\n 'Costumes\/snowflake.svg',\n 'Costumes\/snowman.svg',\n 'Costumes\/spaceship-a.svg',\n 'Costumes\/spaceship-b.svg',\n 'Costumes\/speaker.svg',\n 'Costumes\/squirrel1.png',\n 'Costumes\/star1.svg',\n 'Costumes\/star2.svg',\n 'Costumes\/star3-a.svg',\n 'Costumes\/star3-b.svg',\n 'Costumes\/starfish-a.svg',\n 'Costumes\/starfish-b_.svg',\n 'Costumes\/stop.svg',\n 'Costumes\/street-cleaner-mit.png',\n 'Costumes\/sunglasses1.svg',\n 'Costumes\/sunglasses2.svg',\n 'Costumes\/sun.svg',\n 'Costumes\/tabla-a.svg',\n 'Costumes\/tabla-b.svg',\n 'Costumes\/taco-a.svg',\n 'Costumes\/taco-b.svg',\n 'Costumes\/tennisball.png',\n 'Costumes\/trampoline.png',\n 'Costumes\/tree1.svg',\n 'Costumes\/tree2.svg',\n 'Costumes\/tree-lights-a.svg',\n 'Costumes\/tree-lights-b.svg',\n 'Costumes\/trees-a.svg',\n 'Costumes\/trees-b.svg',\n 'Costumes\/trombone-a.svg',\n 'Costumes\/trombone-b.svg',\n 'Costumes\/trumpet-a2.svg',\n 'Costumes\/trumpet-a.svg',\n 'Costumes\/ukulele.svg',\n 'Costumes\/umbrella.png',\n 'Costumes\/unicorn1.png',\n 'Costumes\/unicorn.svg',\n 'Costumes\/vest-a.svg',\n 'Costumes\/vest-b.svg',\n 'Costumes\/wanda.svg',\n 'Costumes\/watermelon-a.svg',\n 'Costumes\/watermelon-b.svg',\n 'Costumes\/watermelon-c.svg',\n 'Costumes\/witch.svg',\n 'Costumes\/wizard1.svg',\n 'Costumes\/wizard2.svg',\n 'Costumes\/wizard.svg',\n\n \/\/ Backgrounds\n 'Backgrounds\/BACKGROUNDS',\n\n 'Backgrounds\/atom_playground.jpg',\n 'Backgrounds\/bedroom1.gif',\n 'Backgrounds\/bedroom2.gif',\n 'Backgrounds\/berkeley_mural.jpg',\n 'Backgrounds\/brick-wall-and-stairs.jpg',\n 'Backgrounds\/brick-wall1.jpg',\n 'Backgrounds\/brick-wall2.jpg',\n 'Backgrounds\/desert.gif',\n 'Backgrounds\/night_city_with_street.gif',\n 'Backgrounds\/party_room.jpg',\n 'Backgrounds\/pathway.jpg',\n 'Backgrounds\/xy-grid.gif',\n \n \/\/ Sounds\n 'Sounds\/SOUNDS',\n\n 'Sounds\/Cat.mp3',\n 'Sounds\/Chord.wav',\n 'Sounds\/Dog1.wav',\n 'Sounds\/Dog2.wav',\n 'Sounds\/FingerSnap.wav',\n 'Sounds\/Kitten.wav',\n 'Sounds\/Laugh-female.wav',\n 'Sounds\/Laugh-male1.wav',\n 'Sounds\/Laugh-male2.wav',\n 'Sounds\/Laugh-male3.mp3',\n 'Sounds\/Meow.wav',\n 'Sounds\/Pop.wav',\n \n \/\/ Examples\n 'Examples\/EXAMPLES',\n\n 'Examples\/animal-game.xml',\n 'Examples\/Codification.xml',\n 'Examples\/copter.xml',\n 'Examples\/count-change.xml',\n 'Examples\/icecream-visual.xml',\n 'Examples\/JSfunctions.xml',\n 'Examples\/live-tree.xml',\n 'Examples\/swimmer.xml',\n 'Examples\/tree.xml',\n 'Examples\/vee.xml',\n ];\n\n\/* Start the service worker and cache all of the app's content *\/\nself.addEventListener('install', function(e) {\n e.waitUntil(\n caches.open(cacheName).then(function(cache) {\n return cache.addAll(filesToCache);\n })\n );\n});\n\nself.addEventListener('activate', (evt) => {\n evt.waitUntil(\n caches.keys().then((keyList) => {\n return Promise.all(keyList.map((key) => {\n if (key !== cacheName) {\n return caches.delete(key);\n }\n }));\n })\n );\n self.clients.claim();\n});\n\n\/* Serve cached content when offline *\/\nself.addEventListener('fetch', function(e) {\n e.respondWith(\n caches.match(e.request).then(function(response) {\n return response || fetch(e.request);\n })\n );\n});\n<|endoftext|>"} {"text":"const CACHE_NAME = 'neutron-v1';\nconst urlsToCache = [\n '\/index.html',\n '\/styles\/main.css',\n '\/styles\/bootstrap.min.css',\n '\/images\/3246305.jpg',\n '\/index.19fb4943df0cf427704a.bundle.js',\n '\/manifest.1487ea393e348f6eea30.bundle.js',\n '\/scripts\/loadsw.js',\n '\/scripts\/bootstrap.min.js',\n '\/scripts\/jquery-3.1.1.slim.min.js',\n '\/scripts\/tether.min.js',\n];\n\nself.addEventListener('install', function(event) {\n \/\/ Perform install steps\n console.log('Installing SW!');\n event.waitUntil(\n caches.open(CACHE_NAME)\n .then(function(cache) {\n console.log('Opened cache');\n return cache.addAll(urlsToCache);\n })\n );\n});\n\nthis.addEventListener('activate', function(event) {\n const cacheWhitelist = [CACHE_NAME];\n\n event.waitUntil(\n caches.keys().then(function(keyList) {\n return Promise.all(keyList.map(function(key) {\n if (cacheWhitelist.indexOf(key) === -1) {\n return caches.delete(key);\n }\n }));\n })\n );\n});\n\nself.addEventListener('fetch', function(event) {\n event.respondWith(\n caches.match(event.request)\n .then(function(response) {\n \/\/ Cache hit - return response\n if (response) {\n return response;\n }\n\n \/\/ IMPORTANT: Clone the request. Since we are consuming this\n \/\/ once by cache and once by the browser for fetch, we need\n \/\/ to clone the response.\n var fetchRequest = event.request.clone();\n\n return fetch(fetchRequest).then(\n function(response) {\n \/\/ Check if we received a valid response\n if(!response || response.status !== 200 || response.type !== 'basic') {\n return response;\n }\n\n \/\/ We want the browser to consume the response\n \/\/ as well as the cache consuming the response, we need\n \/\/ to clone it so we have two streams.\n var responseToCache = response.clone();\n\n caches.open(CACHE_NAME)\n .then(function(cache) {\n cache.put(event.request, responseToCache);\n });\n\n return response;\n }\n );\n })\n );\n});\nUpdated main Service Worker.const cacheVersion = '1.0.0';\nconst staticCacheName = `musale-v${cacheVersion}`;\nconst filesToCache = [\n '.\/',\n '\/(index)',\n '\/styles\/main.css',\n '\/styles\/bootstrap.min.css',\n '\/images\/3246305.jpg',\n '\/images\/001.svg',\n '\/images\/002.png',\n '\/images\/003.png',\n '\/images\/004.jpg',\n '\/images\/005.jpg',\n '\/index.bundle.js',\n '\/manifest.bundle.js',\n '\/scripts\/loadsw.js',\n '\/scripts\/bootstrap.min.js',\n '\/scripts\/jquery-3.1.1.slim.min.js',\n '\/scripts\/tether.min.js',\n 'https:\/\/farm6.staticflickr.com\/5510\/14338202952_93595258ff_z.jpg',\n 'https:\/\/fonts.gstatic.com\/s\/raleway\/v11\/yQiAaD56cjx1AooMTSghGfY6323mHUZFJMgTvxaG2iE.woff2',\n 'https:\/\/fonts.gstatic.com\/s\/raleway\/v11\/0dTEPzkLWceF7z0koJaX1A.woff2',\n 'https:\/\/placehold.it\/355x250',\n];\n\nthis.addEventListener('install', function(event) {\n event.waitUntil(caches.open(staticCacheName).then(function(cache) {\n return cache.addAll(filesToCache);\n }));\n});\n\n\nself.addEventListener('fetch', function(event) {\n event.respondWith(\n caches.match(event.request).then(function(response) {\n return response || fetch(event.request);\n })\n );\n});\n\nself.addEventListener('activate', function(event) {\n event.waitUntil(\n caches.keys().then(function(cacheNames) {\n return Promise.all(\n cacheNames.filter(function(cacheName) {\n return cacheName.startsWith('musale-v') &&\n cacheName != staticCacheName;\n }).map(function(cacheName) {\n return caches.delete(cacheName);\n })\n );\n })\n );\n});\n<|endoftext|>"} {"text":"var cacheName = 'tools';\nvar cacheFiles = [\n '\/',\n '\/index.html',\n '\/tools.html',\n '\/calc.html',\n '\/hypothesis.html',\n '\/utm.html',\n '\/dencoder.html',\n '\/check.html',\n '\/test.html'\n];\n\nself.addEventListener('install', function(event) {\n event.waitUntil(\n caches.open(cacheName)\n .then(function(cache) {\n return cache.addAll(cacheFiles);\n })\n );\n});\n\nself.addEventListener('fetch', function(event) {\n event.respondWith(\n caches.match(event.request)\n .then(function(response) {\n \/\/ Grab the asset from SW cache.\n if (response) {\n return response;\n }\n return fetch(event.request);\n }).catch(function() {\n \/\/ Can't access the network return an offline page from the cache\n return caches.match('\/tools.html');\n })\n );\n});\n\n\/\/ Empty out any caches that don’t match the ones listed.\nself.addEventListener('activate', function(event) {\n var cacheWhitelist = ['tools'];\n event.waitUntil(\n caches.keys().then(function(cacheNames) {\n return Promise.all(\n cacheNames.map(function(cacheName) {\n if (cacheWhitelist.indexOf(cacheName) === -1) {\n return caches.delete(cacheName);\n }\n })\n );\n })\n );\n});ServiceWorkervar cacheName = 'tools';\nvar cacheFiles = [\n '\/',\n '\/index.html',\n '\/tools.html',\n '\/calc.html',\n '\/hypothesis.html',\n '\/utm.html',\n '\/dencoder.html',\n '\/check.html'\n];\n\nself.addEventListener('install', function(event) {\n event.waitUntil(\n caches.open(cacheName)\n .then(function(cache) {\n return cache.addAll(cacheFiles);\n })\n );\n});\n\nself.addEventListener('fetch', function(event) {\n event.respondWith(\n caches.match(event.request)\n .then(function(response) {\n \/\/ Grab the asset from SW cache.\n if (response) {\n return response;\n }\n return fetch(event.request);\n }).catch(function() {\n \/\/ Can't access the network return an offline page from the cache\n return caches.match('\/tools.html');\n })\n );\n});\n\n\/\/ Empty out any caches that don’t match the ones listed.\nself.addEventListener('activate', function(event) {\n var cacheWhitelist = ['tools'];\n event.waitUntil(\n caches.keys().then(function(cacheNames) {\n return Promise.all(\n cacheNames.map(function(cacheName) {\n if (cacheWhitelist.indexOf(cacheName) === -1) {\n return caches.delete(cacheName);\n }\n })\n );\n })\n );\n});<|endoftext|>"} {"text":"var CACHE_NAME = 'citybookV5';\n\nvar cityBookUrls = [\n '.\/',\n '\/static\/bundle.js'\n];\n\nself.addEventListener('install', function(event) {\n event.waitUntil(\n caches.open(CACHE_NAME)\n .then(function(cache) {\n console.log('Opened cache');\n return cache.addAll(cityBookUrls);\n })\n );\n});\n\nself.addEventListener('activate', function(event) {\n event.waitUntil(\n caches.keys().then(function(cacheNames) {\n return Promise.all(\n cacheNames.map(function(cacheName) {\n if (CACHE_NAME !== cacheName) {\n return caches.delete(cacheName);\n }\n })\n );\n })\n );\n return self.clients.claim();\n});\n\n\/\/ Add an event listener for when the browser fetches\nself.addEventListener('fetch', function(event) {\n \/\/ Respond to the event with a promise\n event.respondWith(\n \/\/ Check if we have the file in our cache\n caches.match(event.request)\n .then(function(response) {\n \/\/ If we find it, return it\n if (response) {\n return response;\n }\n\n \/\/ If we can't find the file, we clone the request\n var fetchRequest = event.request.clone();\n\n \/\/ Return the request we need to make\n return fetch(fetchRequest).then(\n function(response) {\n \/\/ Check if we received a valid response\n if(!response || response.status !== 200 || response.type !== 'basic') {\n \/\/ If not, we just return it\n return response;\n }\n \/\/ Clone the response to put in the cache\n var responseToCache = response.clone();\n\n \/\/ Add the cloned resource to our cache\n caches.open(CACHE_NAME)\n .then(function(cache) {\n cache.put(event.request, responseToCache);\n });\n\n return response;\n }\n );\n })\n );\n});\nUpdate serviceworker with spreadsheet cachevar CITYBOOK_CACHE = 'citybookV9';\nvar SPREADSHEET_CACHE = 'spreadsheetV1';\n\nvar cityBookUrls = [\n '.\/',\n '\/static\/bundle.js'\n];\n\nself.addEventListener('install', function(event) {\n event.waitUntil(\n caches.open(CITYBOOK_CACHE)\n .then(function(cache) {\n console.log('Opened cache');\n return cache.addAll(cityBookUrls);\n })\n );\n});\n\nself.addEventListener('activate', function(event) {\n event.waitUntil(\n caches.keys().then(function(cacheNames) {\n return Promise.all(\n cacheNames.map(function(cacheName) {\n if (CITYBOOK_CACHE !== cacheName && SPREADSHEET_CACHE !== cacheName) {\n return caches.delete(cacheName);\n }\n })\n );\n })\n );\n return self.clients.claim();\n});\n\n\/\/ Add an event listener for when the browser fetches\nself.addEventListener('fetch', function(event) {\n console.log('fetch event happened');\n var dataUrl = 'https:\/\/spreadsheets.google.com';\n\n if(event.request.url.indexOf(dataUrl) > -1){\n console.log('fetching from google');\n event.respondWith(\n caches.open(SPREADSHEET_CACHE).then(function(cache) {\n return fetch(event.request).then(function(response){\n cache.put(event.request.url, response.clone());\n return response;\n });\n })\n );\n } else {\n \/\/ Respond to the event with a promise\n event.respondWith(\n \/\/ Check if we have the file in our cache\n caches.match(event.request)\n .then(function(response) {\n \/\/ If we find it, return it\n if (response) {\n return response;\n }\n\n \/\/ If we can't find the file, we clone the request\n var fetchRequest = event.request.clone();\n\n \/\/ Return the request we need to make\n return fetch(fetchRequest).then(\n function(response) {\n \/\/ Check if we received a valid response\n if(!response || response.status !== 200 || response.type !== 'basic') {\n \/\/ If not, we just return it\n return response;\n }\n \/\/ Clone the response to put in the cache\n var responseToCache = response.clone();\n\n \/\/ Add the cloned resource to our cache\n caches.open(CITYBOOK_CACHE)\n .then(function(cache) {\n cache.put(event.request, responseToCache);\n });\n\n return response;\n }\n );\n })\n );\n }\n});\n<|endoftext|>"} {"text":"import React from 'react';\nimport {PropTypes} from 'prop-types';\nimport { connect } from 'react-redux';\nimport {bindActionCreators} from 'redux';\n\n\nclass TeamVotePage extends React.Component {\n constructor(props, context) {\n super(props, context);\n\n this.saveVote = this.saveVote.bind(this);\n }\n\n saveVote() {\n alert('call save vote!');\n }\n\n render() {\n return (\n
\n

{this.props.team.name} - Voting<\/h3>\n
\n {this.props.categories && this.props.categories.map(c =>\n
\n

{c.name}<\/h4>\n
\n

\"+\"
Entry<\/th>\"+\"藏文解釋<\/th>\"+\"中文解釋<\/th>\"+\n\t\t\t\"
\"+obj.entry+\"<\/td>\"+obj.tdefinition+\"<\/td>\"+\n\t\t\tobj.cdefinition+\"<\/td><\/tr><\/tbody><\/table>\"+\"\";\n}\n\t\nvar edit=function(){\n\tvar table=document.getElementById(\"details\").innerHTML;\n\tvar edittable=\"