-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
78 lines (67 loc) · 1.89 KB
/
app.js
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
76
77
78
(function(){
//if ('WeixinJSBridge' in window) WeixinApi.ready(init)
//else init()
init()
function init() {
var shareUrl = 'http://fritx.github.io/voice'
var shareDesc = '将文字以语音的形式派发给朋友'
var shareTitle = '语音派发'
var wxGetData = function(){
return {
//appId: '',
img: 'http://fritx.github.io/voice/logo.jpg',
link: shareUrl,
desc: shareDesc,
title: shareTitle
}
}
var wxCallback = function(res){
//alert(JSON.stringify(res))
}
wechat('friend', wxGetData, wxCallback)
wechat('timeline', wxGetData, wxCallback)
$(function(){
var $form = $('#form-voice')
var $text = $('#input-text')
var $link = $('#output-link')
var $audioBox = $('#audio-box')
$text.val(fetch())
$form.on('submit', function(e){
e.preventDefault()
$link.empty()
$audioBox.empty().removeClass('ready')
var text = $text.val()
if (!text.trim()) {
shareUrl = 'http://fritx.github.io/voice'
shareDesc = '将文字以语音的形式派发给朋友'
shareTitle = '语音派发'
return
}
var url = [
'http://voice.coding.io/v.mp3?t=', text
].join('')
$link.text(url)
shareUrl = url
shareDesc = '点击进入播放'
shareTitle = '派发了一段语音'
var $audio = $([
'<audio controls autoplay>',
'<source type="audio/mpeg" src="', url, '">',
'</audio>'
].join('')).appendTo($audioBox)
})
$('body').addClass('ready')
if ('localStorage' in window) {
setInterval(function(){
save($text.val())
}, 2000)
}
})
}
function save(text){
localStorage.setItem('text', text)
}
function fetch(){
return localStorage.getItem('text')
}
})()