2011-01-18 3 views
0

몇 시간 동안 알아 내려고 노력했지만 성공하지 못했습니다.이 Counter 애플의 10 억 다운로드 상금. 플래시를 전혀 사용하지 않고 단지 자바 스크립트와 0-9 이미지만으로 정말 멋지게 만듭니다. 이제 stackoverflow google의 팩맨을 추출 성공한 후, 우리가 할 수 있습니까?Apple의 10 억 카운트 다운을 추출하는 방법은 무엇입니까?

P.S 두 가지 모두 포함되어 있기 때문에 이것이 프로토 타입 또는 스크립트를 사용하는지 알 수 없습니다.

+0

"추출"이란 무엇을 의미합니까? 작동 방식을 추론하는 데 도움을 요청합니까? 아니면 현재 표시된 값을 디코드하고 싶습니까? – Phrogz

+0

다른 용도로 사용하기 쉽도록 페이지에서 꺼내야합니다. – Ryan

+0

페이지에서 무엇을 얻으세요? 값 또는 스크립트? – Phrogz

답변

3

는 여기있다 : 그것은 CSS와 결합 JS counter처럼 http://images.apple.com/global/scripts/downloadcounter.js

StepTimingFunction = { 
    timingFunctionForStepCount: function (a) { 
     return function (b) { 
      return ((b * (a - 1)) >> 0)/((a - 1)) 
     } 
    } 
}; 
DownloadCounter = Class.create(); 
Object.extend(DownloadCounter.prototype, { 
    initialize: function (a) { 
     this._url = a; 
     this.loadData(); 
     this._isCounting = true 
    }, 
    setIsCounting: function (a) { 
     this._isCounting = a 
    }, 
    stop: function() { 
     if (this._isCounting) { 
      if (this._drawTimeout) { 
       window.clearTimeout(this._drawTimeout) 
      } 
      this.setIsCounting(false); 
      if (this._delegate && typeof this._delegate.counterDidStop === "function") { 
       this._delegate.counterDidStop(this) 
      } 
     } 
    }, 
    start: function() { 
     if (!this._isCounting) { 
      this.loadData(); 
      this.setIsCounting(true); 
      if (this._delegate && typeof this._delegate.counterDidStart === "function") { 
       this._delegate.counterDidStart(this) 
      } 
     } 
    }, 
    isCounting: function() { 
     return this._isCounting 
    }, 
    _delegate: null, 
    setDelegate: function (a) { 
     this._delegate = a 
    }, 
    delegate: function() { 
     return this._delegate 
    }, 
    loadData: function() { 
     if (this._nextUpdateTimeout) { 
      window.clearTimeout(this._nextUpdateTimeout); 
      this._nextUpdateTimeout = null 
     } 
     var a = document.location.href.toString(); 
     a = a.replace(/.apple.com\/.*$/, ".apple.com"); 
     new Ajax.Request((a + this._url + "?r=" + Math.random()), { 
      method: "get", 
      onSuccess: this.dataRequestDidFinishLoading.bind(this) 
     }) 
    }, 
    dataRequestDidFinishLoading: function (o) { 
     var k = o.responseText.split("|"), 
      n, d, j, g, l, h, b, f, e, m, a, i, c; 
     localServerBasedReferenceTime = Date.parse(o.getResponseHeader("Date")); 
     if (k.length === 3) { 
      n = k[0].split(" "); 
      d = n[1]; 
      date = n[0].split("-"); 
      this.setRate(parseInt(k[2])/3600000); 
      l = date[0]; 
      g = date[1]; 
      j = date[2]; 
      a = Date.parse(g + " " + l + ", " + j + " " + d + " GMT-0700"); 
      e = new Date(a + 3600000); 
      m = e.getTime() - a + 1000; 
      this._nextUpdateTimeout = setTimeout(this.loadData.bind(this), m); 
      if (typeof localServerBasedReferenceTime === "number") { 
       this._lastReferenceTime = localServerBasedReferenceTime 
      } else { 
       b = new Date(); 
       this._lastReferenceTime = b.getTime() 
      } 
      f = this._lastReferenceTime - a; 
      i = Math.floor(parseInt(k[1]) + f * (this._rate)); 
      this.setCurrentCount(i); 
      this.setNeedsDisplayIfNeeded() 
     } 
    }, 
    setNeedsDisplayIfNeeded: function() { 
     if (!this._drawTimeout) { 
      this._drawTimeout = setTimeout(this.draw.bind(this), this._drawRefreshRate) 
     } 
    }, 
    setElement: function (c) { 
     this._element = c; 
     var b = this._element.getElementsByClassName("digitGroupSeparator"); 
     if (b.length > 0) { 
      var a = b[0]; 
      this._element.removeChild(a); 
      this.setDigitGroupSeparatorTemplateElement(a) 
     } 
     this._element.empty(); 
     this.createDigitElementsIfNeeded(); 
     this.setNeedsDisplayIfNeeded() 
    }, 
    setDigitGroupSeparatorTemplateElement: function (a) { 
     this._digitGroupSeparatorTemplateElement = a 
    }, 
    _currentCount: 0, 
    setCurrentCount: function (a) { 
     if (a !== this._currentCount) { 
      this._currentCount = a; 
      this.createDigitElementsIfNeeded() 
     } 
    }, 
    digitTemplateElement: function() { 
     if (!this._digitTemplateElement) { 
      this._digitTemplateElement = document.createElement("span"); 
      $(this._digitTemplateElement).addClassName("digit"); 
      var a = document.createElement("div"), 
       b = document.createElement("div"), 
       c = document.createElement("div"); 
      $(a).addClassName("digitText"); 
      $(b).addClassName("digitImage"); 
      this._digitTemplateElement.appendChild(a); 
      this._digitTemplateElement.appendChild(b); 
      $(c).addClassName("digitImageElement"); 
      b.appendChild(c.cloneNode(true)); 
      b.appendChild(c) 
     } 
     return this._digitTemplateElement 
    }, 
    createDigitElementsIfNeeded: function() { 
     if (this._element && (!this._digitElements || this._digitElements.length !== this._currentCount.toString().length)) { 
      this._element.empty(); 
      this._createDigitElements() 
     } 
    }, 
    _createDigitElements: function() { 
     if (!this._digitElements) { 
      this._digitElements = [] 
     } 
     var e = 0, 
      b = (this._maxCount && this._currentCount >= this._maxCount) ? this._maxCount.toString().length : this._currentCount.toString().length, 
      c = document.createDocumentFragment(), 
      a, h = this.digitTemplateElement(), 
      g = this._digitGroupSeparatorTemplateElement, 
      d = (this._maxCount && this._currentCount >= this._maxCount) ? String(this._maxCount) : String(this._currentCount), 
      f; 
     if (!g) { 
      g = document.createElement("span"); 
      $(g).addClassName("digitGroupSeparator") 
     } 
     for (e = 0 + this._digitElements.length; e < b; e++) { 
      a = h.cloneNode(true); 
      f = parseInt(d.charAt(b - (e + 1))); 
      a.lastChild.style.top = "-" + (f * (this._digitImageAnimationCount * this._digitImageHeight)) + "px"; 
      this._digitElements[e] = a; 
      if (e > 0 && ((e) % 3 == 0)) { 
       c.insertBefore(g.cloneNode(true), c.firstChild) 
      } 
      c.insertBefore(a, c.firstChild) 
     } 
     this._element.insertBefore(c, this._element.firstChild) 
    }, 
    currentCount: function() { 
     return this._currentCount 
    }, 
    setRate: function (a) { 
     this._rate = a 
    }, 
    rate: function() { 
     return this._rate 
    }, 
    _drawRefreshRate: 50, 
    _digitImageHeight: 38, 
    setDigitImageHeight: function (a) { 
     this._digitImageHeight = a 
    }, 
    _digitImageAnimationCount: 6, 
    setDigitImageAnimationCount: function (a) { 
     this._digitImageAnimationCount = a 
    }, 
    _maxCount: false, 
    setMaxCount: function (a) { 
     this._maxCount = a 
    }, 
    draw: function() { 
     window.clearTimeout(this._drawTimeout); 
     this._drawTimeout = null; 
     var h = this._drawRefreshRate, 
      e, j, k, c, a, l, o, b, n, d, m, p = this._digitImageHeight * this._digitImageAnimationCount, 
      g, f = this._digitElements, 
      q; 
     if (this._element) { 
      m = String(this._currentCount); 
      this._currentCount = this._currentCount + Math.floor(this._rate * h); 
      if (this._delegate && typeof this._delegate.counterDidReachValue === "function") { 
       this._delegate.counterDidReachValue(this, this._currentCount) 
      } 
      if (this._maxCount && this._currentCount >= this._maxCount) { 
       this._isCounting = false 
      } 
      if (!this._isCounting) { 
       return 
      } 
      e = (this._maxCount && this._currentCount >= this._maxCount) ? String(this._maxCount) : String(this._currentCount); 
      j = e.length; 
      k = j - 1; 
      for (c = k; c >= 0; c--) { 
       l = parseInt(e.charAt(c)); 
       o = parseInt(m.charAt(c)); 
       if (l !== o) { 
        if (!((k - c) < f.length)) { 
         this._createDigitElements() 
        } 
        a = f[k - c].lastChild; 
        if (a.___animating !== true) { 
         n = o * p; 
         if (l > o) { 
          b = l * p 
         } else { 
          b = (o + (10 - o) + l) * p 
         } 
         if (a.style.top !== (d = "-" + n + "px")) { 
          a.style.top = d 
         } 
         g = 1 + ((b - n)/this._digitImageHeight); 
         a.___animating = true; 
         q = new Effect.Move(a, { 
          x: 0, 
          y: (-1 * b), 
          duration: 0.4, 
          mode: "absolute", 
          transition: StepTimingFunction.timingFunctionForStepCount(g) 
         }); 
         q.__element = a; 
         q.finish = function (i) { 
          if (window.removeEventListener) { 
           window.removeEventListener("unload", arguments.callee, false) 
          } 
          if (this.__element !== undefined) { 
           this.__element.___animating = false 
          } 
         }; 
         if (window.addEventListener) { 
          window.addEventListener("unload", q.finish, false) 
         } 
        } 
       } 
      } 
     } 
     this._lastReferenceTime = (this._lastReferenceTime + h); 
     this.setNeedsDisplayIfNeeded() 
    } 
}); 
1

전체 스크립트의 난로이 하나의 이미지입니다. 한 자리에

  1. HTML 자리 :

    <div class="digit-placeholder"></div> 
    
  2. CSS 그 자리 표시 스타일 :

    .digit-placeholder { 
        /* Dimensions of a single "frame" */ 
        width: 50px; 
        height: 75px; 
    
        background-image: url(...); 
        background-position: 0 0; 
    } 
    
  3. 방금 ​​배경 (background-positon 속성) 이동해야 7 숫자를 표시하려면 다음 좌표로 0 -2800px (그 예일뿐입니다). 8을 표시하려면 0 -3400px으로 이동하십시오.

  4. 애니메이션을 만들려면 (7에서 8로 변경) 일정 시간 (예 : 0.5 초)에 60 단계로 -2800에서 -3400까지 배경을 이동하면됩니다.

당신이해야 할 일은 그 복제를 여러 번 (10 억 회 10 회)하고 각 숫자에 대해 그 기간을 계산하기 만하면됩니다.

0

내가 침대로 이동하기 전에 지금

var number = ''; 
$('.digitImage').each(function(i) { 
    number += Math.abs($(this).position().top)/618; 
}); 
console.log(+number); 

어떻게 그렇게 오래 걸릴 않았다? 3 분 동안 jQuery를 주입하기 위해 크롬에 북마크릿을 설치하는 방법을 알아 내려고했습니다 ... 작동하려면 5 분 정도 더 기다려야합니다.

관련 문제