|
| 1 | +socket = io! |
| 2 | +effects = [ |
| 3 | + * name: \grayscale |
| 4 | + values: [1 to 100] |
| 5 | + unit: \% |
| 6 | + * name: \sepia |
| 7 | + values: [1 to 100] |
| 8 | + unit: \% |
| 9 | + * name: \invert |
| 10 | + values: [60 to 100] |
| 11 | + unit: \% |
| 12 | + * name: \saturate |
| 13 | + values: [1 to 100] |
| 14 | + unit: '' |
| 15 | + * name: \hue-rotate |
| 16 | + values: [0 to 360] |
| 17 | + unit: \deg |
| 18 | + * name: \brightness |
| 19 | + values: [130 to 200] |
| 20 | + unit: \% |
| 21 | + * name: \contrast |
| 22 | + values: [130 to 200] |
| 23 | + unit: \% |
| 24 | +] |
| 25 | + |
| 26 | +filterMaker = -> |
| 27 | + result = '' |
| 28 | + for effect in effects |
| 29 | + if Math.random! < 0.16 |
| 30 | + result += "#{effect.name}(#{effect.values[Math.floor(Math.random! * effect.values.length)]}#{effect.unit}) " |
| 31 | + result |
| 32 | + |
| 33 | +change = -> |
| 34 | + $gifs = $ \.gif |
| 35 | + $gifs.css do |
| 36 | + opacity: 0 |
| 37 | + $loadedGifs = $gifs.filter (_, $el)-> |
| 38 | + $el.querySelector \x-gif .shadowRoot.querySelector \#frames .childNodes.length > 0 |
| 39 | + if $loadedGifs.length > 0 |
| 40 | + target = Math.floor(Math.random! * $loadedGifs.length) |
| 41 | + $ $loadedGifs[target] .css do |
| 42 | + opacity: 1 |
| 43 | + webkitFilter: filterMaker! |
| 44 | + setTimeout change, (main.$data.bpm / 60) * 1000 |
| 45 | + |
| 46 | +processUrls = (urls) -> |
| 47 | + for x in urls |
| 48 | + url = x.replace /^https?:\/\/img\.sorah\.jp/, \http://sorah-pub.s3.amazonaws.com |
| 49 | + if url.match /^https?:\/\/(?:sorah-pub\.s3\.amazonaws\.com|192\.168|10\.|sorah-gif)/ |
| 50 | + url |
| 51 | + else |
| 52 | + "/gifs/retrieve/#{url}" |
| 53 | + |
| 54 | +interrupt = (url)-> |
| 55 | + main.$set \lock, true |
| 56 | + main.$set \urls, processUrls [url] |
| 57 | + |
| 58 | + urlHashes = url.split /#/ |
| 59 | + duration = 20000 |
| 60 | + if 1 < urlHashes.length and urlHashes[urlHashes.length - 1] |
| 61 | + hash = urlHashes[urlHashes.length - 1] |
| 62 | + params = hash.split /:/ |
| 63 | + |
| 64 | + dur = parseInt params[0], 10 |
| 65 | + if 0 < dur |
| 66 | + duration = dur |
| 67 | + |
| 68 | + console.log "Interrupt #{url}, duration:#{duration}" |
| 69 | + setTimeout do |
| 70 | + -> |
| 71 | + main.$set \lock, false |
| 72 | + main.update! |
| 73 | + duration |
| 74 | + |
| 75 | +tweetAdd = (tweet)-> |
| 76 | + top = $ \.comment .length * 40 |
| 77 | + while top > $ \.commentContainer .height! |
| 78 | + top -= $ \.commentContainer .height! |
| 79 | + $ \<p> |
| 80 | + .text tweet.text |
| 81 | + .addClass \comment |
| 82 | + .appendTo $ \.commentContainer |
| 83 | + .css do |
| 84 | + top: "#{top}px" |
| 85 | + .transition do |
| 86 | + left: "-#{$('.commentContainer').width()}px" |
| 87 | + duration: 10000 |
| 88 | + easing: \linear |
| 89 | + complete: -> $ @ .remove! |
| 90 | + |
| 91 | +main = new Vue do |
| 92 | + el: \.container |
| 93 | + template: \#gifs |
| 94 | + data: |
| 95 | + urls: [] |
| 96 | + bpm: 120 |
| 97 | + lock: false |
| 98 | + name: '' |
| 99 | + ready: -> |
| 100 | + @update -> change! |
| 101 | + $.ajax do |
| 102 | + type: \GET |
| 103 | + url: \/bpm |
| 104 | + .done (res)~> @.$data.bpm = res |
| 105 | + methods: |
| 106 | + update: (cb)-> |
| 107 | + $.ajax do |
| 108 | + type: \GET |
| 109 | + url: \/gifs/queue |
| 110 | + .done (res)~> |
| 111 | + @.$data.urls = processUrls res |
| 112 | + if cb? then cb! |
| 113 | + |
| 114 | +socket.on \added, -> unless main.$get \lock then main.update! |
| 115 | +socket.on \choose, -> unless main.$get \lock then main.update! |
| 116 | +socket.on \bpm, (bpm)-> main.$data.bpm = bpm |
| 117 | +socket.on \djadded, interrupt |
| 118 | +socket.on \tweet, tweetAdd |
| 119 | +socket.on \name, (name)-> main.$data.name = name |
0 commit comments