summaryrefslogtreecommitdiff
path: root/2015_locomotivebrowser/firefox/script.js
blob: 74c7805635474ccc630241b03c8fe625b2da3ffa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var audioElement;
var audioElement2;
var interer;
var start = false;

chrome.runtime.onMessage.addListener(
    function(request, sender, sendResponse) {
        if(request.greeting == "start"){
			if(start == false){
				start = true;
		        //start
		        
		        var link = document.createElement("link");
				link.href = chrome.extension.getURL("animationlocomotive.css");
				link.type = "text/css";
				link.rel = "stylesheet";
				document.getElementsByTagName("head")[0].appendChild(link);
				
		        audioElement = document.createElement('audio');
				audioElement.setAttribute('src', chrome.extension.getURL("start.mp3"));
				audioElement.setAttribute('autoplay', 'autoplay');
				audioElement2 = document.createElement('audio');
				audioElement2.setAttribute('src', chrome.extension.getURL("sound.mp3"));
				audioElement2.setAttribute('autoplay', 'autoplay');
				audioElement2.setAttribute('loop', 'true');

				$('html').css({"-webkit-animation-duration": "3s"});
		        $('html').css({"-webkit-animation-name": "locomotivestart"});
		        $('html').css({"-webkit-animation-timing-function": "linear" });
		        $('html').css({"-webkit-animation-play-state": "running"});
		        $('html').css({"-webkit-animation-iteration-count": "1" });
		        
				audioElement.addEventListener("ended", function() {
					audioElement2.play();
				}, true);

				//normal
				var interval = 3;
				if(start == true){
					inter = setTimeout(function(){
						$('html').css({"-webkit-animation-duration": String(interval)+"s"});
						$('html').css({"-webkit-animation-name": "locomotiveanimation"});
						$('html').css({"-webkit-animation-timing-function": "linear" });
						$('html').css({"-webkit-animation-play-state": "running"});
				        $('html').css({"-webkit-animation-iteration-count": "infinite" });
						stuff();
					}, 2900);
				}
				function stuff(){
					if (interval > 0.31 && start == true){
						interval = interval - 0.3;
						$('html').css("-webkit-animation", "none").hide().show(0);
						//$('html').css({"-webkit-animation-play-state": "paused"});
						text = '-webkit-animation-duration: '+String(interval)+'s !important;';
						$('html').css({"-webkit-animation-duration": String(interval)+"s"});
						//$('html').css('cssText', text);
						$('html').css({"-webkit-animation-name": "locomotiveanimation"});
						$('html').css({"-webkit-animation-timing-function": "linear" });
						$('html').css({"-webkit-animation-play-state": "running"});
						$('html').css({"-webkit-animation-iteration-count": "infinite" });
						interer = setTimeout(stuff, interval*1000);
					} else {
					}
				}
			}
		}
		if(request.greeting == "stop"){
			start = false;
			clearTimeout(interer);
			$('html').css("-webkit-animation", "none");
			audioElement.src = "";
			audioElement2.src = "";
		}
	}
);