forked from goldendict/goldendict
-
Notifications
You must be signed in to change notification settings - Fork 0
/
audiolink.cc
39 lines (34 loc) · 1.14 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
39
/* This file is (c) 2008-2012 Konstantin Isakov <ikm@goldendict.org>
* Part of GoldenDict. Licensed under GPLv3 or later, see the LICENSE file */
#include "audiolink.hh"
std::string addAudioLink( std::string const & url,
std::string const & dictionaryId )
{
return std::string( "<script type=\"text/javascript\">" +
makeAudioLinkScript( url, dictionaryId ) +
"</script>" );
}
std::string makeAudioLinkScript( std::string const & url,
std::string const & dictionaryId )
{
/// 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 == '\\' );
}
std::string audioLinkForDict = "gdAudioLinks['" + dictionaryId + "']";
return "gdAudioLinks.first = gdAudioLinks.first || " + ref + ";" +
audioLinkForDict + " = " + audioLinkForDict + " || " + ref + ";";
}