Profile image for Andrea SAPO!! killsapo
il codice di shaun inman
Language
HTML
Tags
html5

html5 audio extension

1 function audioHTML(audioFile) 2 { 3 return '<audio src="'+audioFile+'" title="'+audioFile.replace(/.+\//g,'')+'" controls preload="none"></audio>'; 4 }; 5 6 /* 7 ------------------------------------------------------------------------------- 8 Tumblr Audio Player <http://www.tumblr.com/> 9 ------------------------------------------------------------------------------- 10 Tested on: 11 - http://blog.mimeoverse.com/ 12 - http://nerdmusic.tumblr.com/ 13 ------------------------------------------------------------------------------- 14 */ 15 // Tumblr sites 16 var scripts = document.querySelectorAll('*[id^=audio_player_]+script'); 17 for (var i=0; i<scripts.length;i++) 18 { 19 var script = scripts[i].innerHTML.replace(/(\r|\n)/g, ''); 20 var playerId = script.replace(/\s*replaceIfFlash\([0-9]+,\s*["']/, '').replace(/(audio_player_[0-9]+).+/, '$1'); 21 var audioFile = script.replace(/.+audio_file=/,'').replace(/&.+/, ''); 22 23 // ?plead tip from @evanwalsh: http://twitter.com/#!/evanwalsh/status/612667370774530 24 audioFile += '?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio'; 25 document.getElementById(playerId).innerHTML = audioHTML(audioFile); 26 }; 27 // Tumblr Dashboard (only works for initial page load, can't seem to find an audioFile during Ajax paging) 28 var scripts = document.querySelectorAll('*[id^=audio_node_]+script'); 29 for (var i=0; i<scripts.length;i++) 30 { 31 var script = scripts[i].innerHTML.replace(/(\r|\n)/g, ''); 32 var playerId = script.replace(/\s*replaceIfFlash\([0-9]+,\s*["']/, '').replace(/(audio_node_[0-9]+).+/, '$1'); 33 var audioFile = script.replace(/.+audio_file=/,'').replace(/\\.+/, ''); 34 35 // ?plead tip from @evanwalsh: http://twitter.com/#!/evanwalsh/status/612667370774530 36 audioFile += '?plead=please-dont-download-this-or-our-lawyers-wont-let-us-host-audio'; 37 document.getElementById(playerId).innerHTML = audioHTML(audioFile); 38 }; 39 40 function pad6(str) 41 { 42 var fill = 6 - str.length; 43 while (fill > 0) 44 { 45 str = '0'+str; 46 fill--; 47 }; 48 return str; 49 }; 50 function dec2bin(dec) 51 { 52 return parseInt(dec).toString(2); 53 }; 54 function bin2dec(bin) 55 { 56 var dec = 0; 57 for (var i=0;i<bin.length; i++) 58 { 59 var j = bin.charAt(i); 60 if (j == '1') 61 { 62 dec += Math.pow(2, bin.length-1-i); 63 }; 64 }; 65 return dec; 66 }; 67 function AudioPlayerDecodeSource(encoded) 68 { 69 // so very secure 70 var source = ''; 71 var key = {'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25,'a':26,'b':27,'c':28,'d':29,'e':30,'f':31,'g':32,'h':33,'i':34,'j':35,'k':36,'l':37,'m':38,'n':39,'o':40,'p':41,'q':42,'r':43,'s':44,'t':45,'u':46,'v':47,'w':48,'x':49,'y':50,'z':51,'0':52,'1':53,'2':54,'3':55,'4':56,'5':57,'6':58,'7':59,'8':60,'9':61,'_':62,'-':63}; 72 var chars = encoded.split(''); 73 var mid = ''; 74 75 for (var j=0; j<chars.length; j++) 76 { 77 var c = chars[j]; 78 var i = key[c]; 79 var b = pad6(i.toString(2)); 80 mid += b; 81 }; 82 83 mid = mid.substring(0, Math.floor(mid.length/8)*8); 84 85 for (var j=0; j<mid.length; j+=8) 86 { 87 var b = mid.substring(j, j+8); 88 var i = bin2dec(b); 89 var c = String.fromCharCode(i); 90 source += c; 91 }; 92 return source; 93 }; 94 var scripts = document.getElementsByTagName('script'); 95 for (var i=0; i<scripts.length;i++) 96 { 97 var script = scripts[i].innerHTML; 98 99 /* 100 ------------------------------------------------------------------------------- 101 WordPress Audio Player <http://wpaudioplayer.com/> 102 ------------------------------------------------------------------------------- 103 Tested on: 104 - http://www.bearmccreary.com/blog/ 105 ------------------------------------------------------------------------------- 106 */ 107 if (script.match('AudioPlayer.embed')) 108 { 109 var exps = script.split(';'); 110 for (var j=0; j<exps.length; j++) 111 { 112 var exp = exps[j].replace(/(\r|\n)/g, ''); 113 var playerId = exp.replace(/AudioPlayer\.embed\(["']/,'').replace(/([^"']+)["'].+/, '$1'); 114 if (playerId.match(/^\s*$/)) continue; 115 var audioFile = exp.replace(/.+soundFile:\s*["']([^"']+).+/, '$1'); 116 if (audioFile.match(/^\s*$/)) continue; 117 118 if (!audioFile.match(/\./)) 119 { 120 audioFile = AudioPlayerDecodeSource(audioFile); 121 }; 122 document.getElementById(playerId).innerHTML = audioHTML(audioFile); 123 }; 124 } 125 /* 126 ------------------------------------------------------------------------------- 127 SWFObject, initially JWPlayer <http://www.longtailvideo.com/players/> 128 ------------------------------------------------------------------------------- 129 Tested on: 130 - http://5by5.tv/ 131 ------------------------------------------------------------------------------- 132 */ 133 else if (script.match(/\.addVariable\('file'/) && script.match('.mp3')) 134 { 135 script = script.replace(/[\r\n]/g,''); 136 var playerId = script.replace(/^.*\.write\(["']([^"']+)["'].*$/, '$1'); 137 if (playerId.match(/^\s*$/)) continue; 138 var audioFile = script.replace(/^.*\.addVariable\(["']file["'],\s*["']([^"']+)["'].*$/, '$1'); 139 if (audioFile.match(/^\s*$/)) continue; 140 document.getElementById(playerId).innerHTML = audioHTML(audioFile); 141 } 142 /* 143 ------------------------------------------------------------------------------- 144 Guardian Audio Player <http://www.guardian.co.uk/audio> 145 ------------------------------------------------------------------------------- 146 Tested on: 147 - http://www.guardian.co.uk/audio 148 ------------------------------------------------------------------------------- 149 */ 150 else if (script.match(/guAudioPlayer\.swf/)) 151 { 152 script = script.replace(/[\r\n]/g,''); 153 var audioFile = script.replace(/^.*&file=([^&]+).*$/, '$1'); 154 if (audioFile.match(/^\s*$/)) continue; 155 document.getElementById('flash-player').innerHTML = audioHTML(audioFile); 156 } 157 /* 158 ------------------------------------------------------------------------------- 159 freesound.org Audio Player <http://www.freesound.org> 160 ------------------------------------------------------------------------------- 161 Tested on: 162 - http://www.freesound.org/samplesViewSingle.php?id=108602 163 - Works on detail pages only. 164 ------------------------------------------------------------------------------- 165 */ 166 else if (script.match(/preview-player\.swf/)) 167 { 168 script = script.replace(/[\r\n]/g,''); 169 var audioFile = script.replace(/^.*\.addVariable\(["']url["'],\s*["']([^"']+)["'].*$/, '$1'); 170 if (audioFile.match(/^\s*$/)) continue; 171 var freesoundId = audioFile.replace(/.*\/(\d+)__.*/, '$1'); 172 if (freesoundId.match(/^\s*$/)) continue; 173 var freesoundSpanId = 'flashcontent_' + freesoundId; 174 document.getElementById(freesoundSpanId).innerHTML = audioHTML(audioFile); 175 }; 176 }; 177 178 var objects = document.getElementsByTagName('object'); 179 for (var i=0; i<objects.length;i++) 180 { 181 var object = objects[i]; 182 183 /* 184 ------------------------------------------------------------------------------- 185 AOL Audio Player used by Weblogs Inc. properties 186 ------------------------------------------------------------------------------- 187 Tested on: 188 - http://engadget.com/ 189 190 Submitted by Benjamin Mayo http://benjaminmayo.posterous.com/ 191 ------------------------------------------------------------------------------- 192 */ 193 if (object.data && object.data.match(/weblogsinc/i)) 194 { 195 var audioFile = object.children.FlashVars.value.substr(10); 196 object.innerHTML = audioHTML(audioFile); 197 } 198 /* 199 ------------------------------------------------------------------------------- 200 8bit Collective Audio Player 201 ------------------------------------------------------------------------------- 202 Tested on: 203 - http://8bc.org/ 204 ------------------------------------------------------------------------------- 205 */ 206 else if (object.data && object.data.match(/player_mp3_maxi\.swf/)) 207 { 208 if (m = object.children.FlashVars.value.match(/mp3=([^&]+)/)) 209 { 210 var audioFile = window.decodeURIComponent(m[1]).replace(/\+/g,'%20'); 211 object.innerHTML = audioHTML(audioFile); 212 }; 213 }; 214 };

Comments