fix 多个 css 加载 外部 mp3 处理
Browse files
csharp/mdict/Mdx/Mdx/Readers/MdxReader.cs
CHANGED
|
@@ -105,6 +105,24 @@ namespace Mdict.Mdx.Readers
|
|
| 105 |
content = $"<style>{_cssToInject}</style>\n{content}";
|
| 106 |
}
|
| 107 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
var contentType = _contentDb.Meta.DbInfo.ContentType;
|
| 109 |
if (contentType == ContentType.Text)
|
| 110 |
{
|
|
|
|
| 105 |
content = $"<style>{_cssToInject}</style>\n{content}";
|
| 106 |
}
|
| 107 |
|
| 108 |
+
// Inject sound handling script
|
| 109 |
+
string soundScript = @"<script>
|
| 110 |
+
document.addEventListener('click', function(e) {
|
| 111 |
+
var target = e.target;
|
| 112 |
+
while (target && target.tagName !== 'A') {
|
| 113 |
+
target = target.parentElement;
|
| 114 |
+
}
|
| 115 |
+
if (target && target.href) {
|
| 116 |
+
if (target.href.indexOf('/sound?profile_id=') !== -1 || target.href.match(/\.(mp3|wav|ogg)$/i)) {
|
| 117 |
+
e.preventDefault();
|
| 118 |
+
var audio = new Audio(target.href);
|
| 119 |
+
audio.play();
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
});
|
| 123 |
+
</script>";
|
| 124 |
+
content = soundScript + "\n" + content;
|
| 125 |
+
|
| 126 |
var contentType = _contentDb.Meta.DbInfo.ContentType;
|
| 127 |
if (contentType == ContentType.Text)
|
| 128 |
{
|
csharp/mdict/Mdx/Mdx/Utils/MdxHtmlRewriter.cs
CHANGED
|
@@ -43,6 +43,17 @@ namespace Mdx.Utils
|
|
| 43 |
string newStyle = RewriteCssUrls(style, profileId, baseUrl);
|
| 44 |
return $"style={quote}{newStyle}{quote}";
|
| 45 |
}, RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
return rewritten;
|
| 48 |
}
|
|
|
|
| 43 |
string newStyle = RewriteCssUrls(style, profileId, baseUrl);
|
| 44 |
return $"style={quote}{newStyle}{quote}";
|
| 45 |
}, RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
| 46 |
+
|
| 47 |
+
// Handle <style>...</style> content
|
| 48 |
+
string styleTagPattern = @"(<style[^>]*>)(?<content>.*?)(</style>)";
|
| 49 |
+
rewritten = Regex.Replace(rewritten, styleTagPattern, match =>
|
| 50 |
+
{
|
| 51 |
+
string open = match.Groups[1].Value;
|
| 52 |
+
string content = match.Groups["content"].Value;
|
| 53 |
+
string close = match.Groups[3].Value;
|
| 54 |
+
string newContent = RewriteCssUrls(content, profileId, baseUrl);
|
| 55 |
+
return $"{open}{newContent}{close}";
|
| 56 |
+
}, RegexOptions.IgnoreCase | RegexOptions.Singleline);
|
| 57 |
|
| 58 |
return rewritten;
|
| 59 |
}
|