Skip to content

Commit

Permalink
レス取得をJavaScriptで取得する形式に変更
Browse files Browse the repository at this point in the history
  • Loading branch information
ggslyman committed Mar 21, 2014
1 parent a848b60 commit ae391a9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 42 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@

##更新履歴

* 14/03/10 2.0.1 Rev.8
- レス取得をJavaScriptで取得するよう変更

* 14/03/10 2.0.1 Rev.7
- ビューアのタブを閉じてもメモリが解放されない不具合を修正
- youtubeもビューアで開く様に変更
Expand Down
22 changes: 11 additions & 11 deletions SpeechCast/FormMain.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 46 additions & 29 deletions SpeechCast/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ public FormMain()
// Webブラウザオブジェクトへの新規イベント追加
this.webBrowser.StatusTextChanged += new EventHandler(webBrowser_StatusTextChanged);
this.webBrowser.Navigating += new WebBrowserNavigatingEventHandler(webBrowser_Navigating);
// JavaScriptでの差分取得用HTMLをセット
this.webBrowser.DocumentText = @"<html><body><script type=""text/javascript"">
function addRes(res) {
var element = document.createElement('div');
element.innerHTML = res;
var objResArea = document.getElementById(""resArea"");;
objResArea.appendChild(element);
}
function clearRes() {
var objResArea = document.getElementById(""resArea"");;
objResArea.innerHTML = """";
}
</script>
<div id=""resArea""></div></body></html>";
}

// ブラウザ内リンクのイベント追加
Expand Down Expand Up @@ -326,6 +340,8 @@ private bool CheckBaseURL()
string debugDatFileName = null;
#endif
// 元ソースより非同期に変更
private int oldResCount = 0;
private string oldUrl = "";
private async Task<bool> GetFromURL(bool next)
{

Expand Down Expand Up @@ -408,6 +424,15 @@ private async Task<bool> GetFromURL(bool next)
}
url = rawURL;
datSize = 1;
// レス差分取得関係の初期化処理
if (oldUrl != rawURL)
{
responses.Clear();
oldUrl = rawURL;
oldResCount = 0;
Object[] objArray = new Object[1];
webBrowser.Document.InvokeScript("clearRes", objArray);
}
}

System.Diagnostics.Stopwatch stopWatch = new System.Diagnostics.Stopwatch();
Expand Down Expand Up @@ -623,6 +648,15 @@ await Task.Run(() =>
//レスが増えた

updated = true;
// 差分用処理
if (responses.Count == 0)
{
oldResCount = 0;
}
else
{
oldResCount = responses.Count;
}
listViewResponses.BeginUpdate();
int startIndex;
if (clearItems)
Expand Down Expand Up @@ -684,34 +718,16 @@ await Task.Run(() =>

if (updated)
{
string[] htmlStrings = new string[responses.Count];

int i = 0;
foreach (Response res in responses)
// JavaScriptでの差分追加処理
if (webBrowser.Document != null)
{
htmlStrings[i] = res.Html;
i++;
}

string html = string.Format("<html><body>{0}</body></html>"
, string.Concat(htmlStrings)
);

try
{
webBrowser.DocumentText = html;
documetnTime = stopWatch.ElapsedMilliseconds;

#if DEBUG
AddLog("Elasped res={0} read={1} enc={2} list={3} doc={4} set={5}",
responseTime, readTime, encodingTime, listViewTime, documetnTime, setTime);
#endif
}
catch (Exception ex)
{
result = false;
AddLog("webBrowser Exception: {0}", ex.Message);
}
for (int idx = oldResCount; idx < responses.Count; idx++)
{
Object[] objArray = new Object[1];
objArray[0] = responses[idx].Html;
webBrowser.Document.InvokeScript("addRes", objArray);
}
}
}
return result;
}
Expand Down Expand Up @@ -834,7 +850,7 @@ private int GetResponsesScrollY(int no)

private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
ScrollToDocumentEnd();
//ScrollToDocumentEnd();
}

private int currentResNumber_ = 0;
Expand Down Expand Up @@ -948,7 +964,7 @@ private void StartSpeaking()
isSpeaking = true;
StartSpeaking(text);
listViewResponses.Items[CurrentResNumber - 1].Selected = true;
webBrowser.Document.Window.ScrollTo(0, GetResponsesScrollY(CurrentResNumber));
//webBrowser.Document.Window.ScrollTo(0, GetResponsesScrollY(CurrentResNumber));
}
else if (openNextThread == OpenNextThread)
{
Expand Down Expand Up @@ -2135,5 +2151,6 @@ public void saveViewerPos(FormViewResource frm)
{
UserConfig.SetFormToRect(ref UserConfig.FormViewToRect, frm);
}

}
}
1 change: 1 addition & 0 deletions SpeechCast/FormViewResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public void addTabYoutube(string id)
{
// コンテンツ格納用のWebブラウザを作成
WebBrowser wb = new WebBrowser();
// ウィジェットHTMLを生成
string widgetCode = "<iframe width=\"480\" height=\"360\" src=\"https://www.youtube.com/embed/" + id + "\" frameborder=\"0\" allowfullscreen></iframe>";
wb.DocumentText = "<body>" + widgetCode + "</body>";
wb.Dock = DockStyle.Fill;
Expand Down
4 changes: 2 additions & 2 deletions SpeechCast/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.0.1.7")]
[assembly: AssemblyFileVersion("2.0.1.7")]
[assembly: AssemblyVersion("2.0.1.8")]
[assembly: AssemblyFileVersion("2.0.1.8")]

0 comments on commit ae391a9

Please sign in to comment.