forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathaudiolink.cc
38 lines (33 loc) · 1.09 KB
/
audiolink.cc
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
/* This file is (c) 2008-2012 Konstantin Isakov <[email protected]>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "audiolink.hh"
std::string addAudioLink( std::string const & url)
{
return std::string( "<script>" +
makeAudioLinkScript( url ) +
"</script>" );
}
std::string makeAudioLinkScript( std::string const & url)
{
/// Convert "'" to "\'" - this char broke autoplay of audiolinks
std::string ref;
bool escaped = false;
for( unsigned x = 0; x < url.size(); x++ )
{
char ch = url[ x ];
if( escaped )
{
ref += ch;
escaped = false;
continue;
}
if( ch == '\'' )
ref += '\\';
ref += ch;
escaped = ( ch == '\\' );
}
// Assign the first audio link of each article to gdJustLoadedAudioLink JavaScript variable.
// Once an article finishes loading, the value of gdJustLoadedAudioLink is stored away
// and the variable is set to null, before the next article starts loading.
return "gdJustLoadedAudioLink = gdJustLoadedAudioLink || " + ref + ';';
}