69 lines
1.8 KiB
JavaScript
69 lines
1.8 KiB
JavaScript
|
//定期获取超值旅游线路
|
||
|
(new TimerManager()).addTimer(new Timer(
|
||
|
'bargain',
|
||
|
config.cheap.delay,
|
||
|
config.cheap.interval,
|
||
|
function() {
|
||
|
var newest = JSON.parse($.ajax({url: config.urls.cheapNotice + encodeURIComponent(Storage.get('location')), async: false}).responseText),
|
||
|
now = Util.date.now(),
|
||
|
lastPopup = parseInt(Storage.getWithDefault('lastCheapPopupTime', '0'));
|
||
|
|
||
|
if (newest && newest.createTime * 1000 > lastPopup && !newest.abandon && newest.expirationTime * 1000 > now) {
|
||
|
Storage.set('showStage', {
|
||
|
name: 'bargainFound',
|
||
|
data: newest
|
||
|
});
|
||
|
Storage.set('lastCheapPopupTime', now);
|
||
|
Util.popup();
|
||
|
}
|
||
|
}
|
||
|
));
|
||
|
|
||
|
//图标转动
|
||
|
(new TimerManager()).addTimer(new Timer(
|
||
|
'flip',
|
||
|
0,
|
||
|
config.monitor.flip,
|
||
|
function() {
|
||
|
var canvas = document.getElementById('canvasWrap'),
|
||
|
canvasContext = canvas.getContext('2d'),
|
||
|
rotation = 0,
|
||
|
animationFrames = 36,
|
||
|
animationSpeed = 12,
|
||
|
|
||
|
ease = function(x) {
|
||
|
return (1-Math.sin(Math.PI/2+x*Math.PI))/2;
|
||
|
},
|
||
|
|
||
|
drawIconAtRotation = function() {
|
||
|
canvasContext.save();
|
||
|
canvasContext.clearRect(0, 0, canvas.width, canvas.height);
|
||
|
canvasContext.translate(
|
||
|
Math.ceil(canvas.width/2),
|
||
|
Math.ceil(canvas.height/2)
|
||
|
);
|
||
|
canvasContext.rotate(2*Math.PI*ease(rotation));
|
||
|
canvasContext.drawImage(
|
||
|
document.getElementById('hasData'),
|
||
|
- Math.ceil(canvas.width/2),
|
||
|
- Math.ceil(canvas.height/2)
|
||
|
);
|
||
|
canvasContext.restore();
|
||
|
|
||
|
chrome.browserAction.setIcon({imageData:canvasContext.getImageData(0, 0, canvas.width, canvas.height)});
|
||
|
},
|
||
|
|
||
|
animateFlip = function() {
|
||
|
rotation += 1/animationFrames;
|
||
|
drawIconAtRotation();
|
||
|
|
||
|
if (rotation <= 1) {
|
||
|
setTimeout(animateFlip, animationSpeed);
|
||
|
} else {
|
||
|
rotation = 0;
|
||
|
}
|
||
|
};
|
||
|
|
||
|
animateFlip();
|
||
|
}
|
||
|
));
|