OLD | NEW |
| (Empty) |
1 <!DOCTYPE HTML> | |
2 <html i18n-values="dir:textdirection;"> | |
3 <head> | |
4 <meta charset="utf-8"> | |
5 <title>Media Playlist</title> | |
6 <style type="text/css"> | |
7 body { | |
8 background: #080809; | |
9 } | |
10 | |
11 .playlist { | |
12 width: 100%; | |
13 height: 100%; | |
14 background: #080809; | |
15 color: #8AACE7; | |
16 font-size: .7em; | |
17 position: absolute; | |
18 top: 0; | |
19 left: 0; | |
20 } | |
21 | |
22 .playlistitem { | |
23 width: 100%; | |
24 padding: 6px; | |
25 cursor: pointer; | |
26 } | |
27 | |
28 .playing { | |
29 background: #393b41; | |
30 color: #dddde7; | |
31 font-weight: bold; | |
32 } | |
33 | |
34 .tracknum { | |
35 width: 20px; | |
36 position: relative; | |
37 float: left; | |
38 } | |
39 | |
40 .title { | |
41 | |
42 } | |
43 | |
44 .innertitle { | |
45 text-decoration: line-through; | |
46 } | |
47 | |
48 .error { | |
49 color: red; | |
50 float: left; | |
51 padding-right: 5px; | |
52 } | |
53 | |
54 </style> | |
55 <script src="chrome://resources/js/local_strings.js"></script> | |
56 <script> | |
57 | |
58 function $(o) { | |
59 return document.getElementById(o); | |
60 } | |
61 | |
62 function pathIsVideoFile(path) { | |
63 return /\.(mp4|ogg|mpg|avi)$/i.test(path); | |
64 }; | |
65 | |
66 function pathIsAudioFile(path) { | |
67 return /\.(mp3|m4a)$/i.test(path); | |
68 }; | |
69 | |
70 /////////////////////////////////////////////////////////////////////////////// | |
71 // Document Functions: | |
72 /** | |
73 * Window onload handler, sets up the page. | |
74 */ | |
75 | |
76 var currentPlaylist = null; | |
77 var currentOffset = -1; | |
78 function load() { | |
79 document.body.addEventListener('dragover', function(e) { | |
80 if (e.preventDefault) e.preventDefault(); | |
81 }); | |
82 document.body.addEventListener('drop', function(e) { | |
83 if (e.preventDefault) e.preventDefault(); | |
84 }); | |
85 chrome.mediaPlayerPrivate.getPlaylist(false, getPlaylistCallback); | |
86 chrome.mediaPlayerPrivate.onPlaylistChanged.addListener(function() { | |
87 chrome.mediaPlayerPrivate.getPlaylist(false, getPlaylistCallback); | |
88 }); | |
89 }; | |
90 | |
91 function getDisplayNameFromPath(path) { | |
92 slash = path.lastIndexOf("/") | |
93 if (slash != -1) { | |
94 fileName = path.substring(slash+1,path.length) | |
95 return fileName; | |
96 } else { | |
97 return path; | |
98 } | |
99 }; | |
100 | |
101 function setPlaylistOffset(offset) { | |
102 chrome.mediaPlayerPrivate.playAt(offset); | |
103 }; | |
104 | |
105 function updateUI() { | |
106 var main = $('main'); | |
107 if (currentPlaylist) { | |
108 main.textContent = ''; | |
109 var main = $('main'); | |
110 for (var x = 0; x < currentPlaylist.length; x++) { | |
111 var rowdiv = document.createElement('div'); | |
112 rowdiv.className = 'playlistitem'; | |
113 | |
114 var numberdiv = document.createElement('div'); | |
115 numberdiv.className = 'tracknum'; | |
116 numberdiv.textContent = '' + (x + 1); | |
117 rowdiv.appendChild(numberdiv); | |
118 | |
119 var titlediv = document.createElement('div'); | |
120 if (currentPlaylist[x].error) { | |
121 var errormark = document.createElement('div'); | |
122 errormark.className = 'error'; | |
123 errormark.textContent = 'X'; | |
124 var innertitle = document.createElement('div'); | |
125 innertitle.className = 'innertitle'; | |
126 innertitle.textContent = | |
127 decodeURI(getDisplayNameFromPath(currentPlaylist[x].path)); | |
128 titlediv.appendChild(errormark); | |
129 titlediv.appendChild(innertitle); | |
130 } else { | |
131 titlediv.className = 'title'; | |
132 titlediv.textContent = | |
133 decodeURI(getDisplayNameFromPath(currentPlaylist[x].path)); | |
134 } | |
135 rowdiv.appendChild(titlediv); | |
136 rowdiv.onclick = new Function('setPlaylistOffset(' + x + ')'); | |
137 if (currentOffset == x) { | |
138 rowdiv.className = 'playlistitem playing'; | |
139 } | |
140 main.appendChild(rowdiv); | |
141 } | |
142 } | |
143 }; | |
144 | |
145 function getPlaylistCallback(playlist) { | |
146 currentPlaylist = playlist.items; | |
147 currentOffset = playlist.position; | |
148 updateUI(); | |
149 }; | |
150 </script> | |
151 <body onload='load();' onselectstart='return false'> | |
152 <div id='main' class='playlist'> | |
153 </div> | |
154 </body> | |
155 </html> | |
OLD | NEW |