• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

ギコナビ


Commit MetaInfo

Revision5b23cdd3194d219f6cd887bcdc1b9e3529dced04 (tree)
Time2009-02-23 00:30:05
Authorh677 <h677>
Commiterh677

Log Message

ニコニコ動画へのリンクのサムネイルをプレビューで表示できるように拡張

Change Summary

Incremental Difference

--- a/Giko.pas
+++ b/Giko.pas
@@ -2083,7 +2083,8 @@ begin
20832083 s := '';
20842084 Ext := AnsiLowerCase(ExtractFileExt(Text2));
20852085 if (Pos('http://', Text2) = 1) and (GikoSys.Setting.PreviewVisible) and
2086- ((Ext = '.jpg') or (Ext = '.jpeg') or (Ext = '.gif') or (Ext = '.png')) then begin
2086+ ((Ext = '.jpg') or (Ext = '.jpeg') or (Ext = '.gif') or (Ext = '.png')) or
2087+ (Pos('http://www.nicovideo.jp/watch/', Text2) = 1) then begin
20872088 if FPreviewBrowser = nil then begin
20882089 FPreviewBrowser := TPreviewBrowser.Create(Self);
20892090 ShowWindow(FPreviewBrowser.Handle, SW_HIDE);
--- a/Preview.pas
+++ b/Preview.pas
@@ -13,6 +13,7 @@ uses
1313 type
1414 TPreviewBrowser = class(TWebBrowser)
1515 private
16+ function makeHTML(const URL, Host, Document : String): String;
1617 protected
1718 procedure CreateParams(var Params: TCreateParams); override;
1819 public
@@ -31,6 +32,7 @@ const
3132 // ƒ}ƒEƒXƒJ[ƒ\ƒ‹‚©‚ç‚Ì‚¸‚炵ˆÊ’u
3233 DIV_X = 15;
3334 DIV_Y = 15;
35+ NICO = 'www.nicovideo.jp';
3436
3537 constructor TPreviewBrowser.Create(AOwner: TComponent);
3638 begin
@@ -52,7 +54,6 @@ end;
5254 }
5355 procedure TPreviewBrowser.PreviewImage(URL : String);
5456 var
55- html : string;
5657 HtmlFileName : string;
5758 sl : TStringList;
5859 Protocol, Host, Path, Document, Port, Bookmark : string;
@@ -62,41 +63,21 @@ var
6263 PostData: OleVariant;
6364 Headers: OleVariant;
6465 begin
65- html := '<html><head>'#13#10
66- + '<SCRIPT>'#13#10
67- + 'function init() {'#13#10
68- + ' if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10
69- + ' } else {'#13#10
70- + ' var dh, ih;'#13#10
71- + ' dh = document.body.clientWidth / document.body.clientHeight;'#13#10
72- + ' ih = Image1.width / Image1.height;'#13#10
73- + ' if (document.body.clientWidth < document.body.clientHeight) {'#13#10
74- + ' if (ih > dh)'#13#10
75- + ' Image1.width = document.body.clientWidth;'#13#10
76- + ' else'#13#10
77- + ' Image1.height = document.body.clientHeight;'#13#10
78- + ' } else {'#13#10
79- + ' if (ih < dh)'#13#10
80- + ' Image1.height = document.body.clientHeight;'#13#10
81- + ' else'#13#10
82- + ' Image1.width = document.body.clientWidth;'#13#10
83- + ' }'#13#10
84- + ' }'#13#10
85- + ' Message.style.display = "none";'#13#10
86- + '}'#13#10
87- + '</SCRIPT>'#13#10
88- + '</head>'#13#10
89- + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
90- + '<div align="center" id="Message">ƒvƒŒƒrƒ…[ì¬’†</div>'#13#10
91- + '<div align="center"><img name="Image1" border="0" src="%ImageURL%"></div>'#13#10
92- + '</body></html>';
93-
66+ GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark);
67+ Referer := Protocol + '://' + Host;
68+ if Port <> '' then
69+ Referer := Referer + ':' + Port;
70+ Referer := Referer + Path;
71+ Headers := 'Referer: ' + Referer;
72+ Flags := 0;
73+ TargetFrameName := '';
74+ PostData := '';
75+
9476 HtmlFileName := GikoSys.GetAppDir + HTML_FILE_NAME;
9577 sl := TStringList.Create;
9678 try
9779 try
98- sl.Text := MojuUtils.
99- CustomStringReplace(html, '%ImageURL%', URL, False);
80+ sl.Text := makeHTML(URL, Host, Document);
10081 sl.SaveToFile(HtmlFileName);
10182 finally
10283 sl.Free;
@@ -104,15 +85,6 @@ begin
10485 except
10586 end;
10687
107- GikoSys.ParseURI(URL, Protocol, Host, Path, Document, Port, Bookmark);
108- Referer := Protocol + '://' + Host;
109- if Port <> '' then
110- Referer := Referer + ':' + Port;
111- Referer := Referer + Path;
112- Headers := 'Referer: ' + Referer;
113- Flags := 0;
114- TargetFrameName := '';
115- PostData := '';
11688
11789 Navigate(HtmlFileName,Flags, TargetFrameName, PostData, Headers);
11890
@@ -173,4 +145,60 @@ begin
173145 end;
174146
175147 end;
148+
149+{
150+\breif ƒvƒŒƒrƒ…[—p‚ÌHTML‚ðì¬‚·‚é
151+\param URL ƒvƒŒƒrƒ…[‚·‚éƒCƒ[ƒWƒtƒ@ƒCƒ‹
152+}
153+function TPreviewBrowser.makeHTML(const URL, Host, Document : String): String;
154+var
155+ point :TPoint;
156+ rect :TRect;
157+begin
158+ if (Pos('http://www.nicovideo.jp/watch/', URL) <> 1) then begin
159+ Result := '<html><head>'#13#10
160+ + '<SCRIPT>'#13#10
161+ + 'function init() {'#13#10
162+ + ' if ((document.body.clientHeight >= Image1.height) && (document.body.clientWidth >= Image1.width)) {'#13#10
163+ + ' } else {'#13#10
164+ + ' var dh, ih;'#13#10
165+ + ' dh = document.body.clientWidth / document.body.clientHeight;'#13#10
166+ + ' ih = Image1.width / Image1.height;'#13#10
167+ + ' if (document.body.clientWidth < document.body.clientHeight) {'#13#10
168+ + ' if (ih > dh)'#13#10
169+ + ' Image1.width = document.body.clientWidth;'#13#10
170+ + ' else'#13#10
171+ + ' Image1.height = document.body.clientHeight;'#13#10
172+ + ' } else {'#13#10
173+ + ' if (ih < dh)'#13#10
174+ + ' Image1.height = document.body.clientHeight;'#13#10
175+ + ' else'#13#10
176+ + ' Image1.width = document.body.clientWidth;'#13#10
177+ + ' }'#13#10
178+ + ' }'#13#10
179+ + ' Message.style.display = "none";'#13#10
180+ + '}'#13#10
181+ + '</SCRIPT>'#13#10
182+ + '</head>'#13#10
183+ + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
184+ + '<div align="center" id="Message">ƒvƒŒƒrƒ…[ì¬’†</div>'#13#10
185+ + '<div align="center"><img name="Image1" border="0" src="' + URL + '"></div>'#13#10
186+ + '</body></html>';
187+ end else begin
188+ // <div><iframe width="340" height="185" src="http://www.nicovideo.jp/thumb/sm2494604" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe></div><div class=link_nicovideo_title><a href="" title="" target="_blank"></a></div>
189+ rect := GetWindowRect(point);
190+
191+ Result := '<html><head>'#13#10
192+ + '<SCRIPT>'#13#10
193+ + 'function init() {'#13#10
194+ + ' Message.style.display = "none";'#13#10
195+ + '}'#13#10
196+ + '</SCRIPT>'#13#10
197+ + '</head>'#13#10
198+ + '<body topmargin="0" leftmargin="0" style="border-width: 1px; overflow:hidden; border-style: solid;" onLoad="init()">'#13#10
199+ + '<div align="center" id="Message">ƒvƒŒƒrƒ…[ì¬’†</div>'#13#10
200+ + '<div><iframe width="' + IntToStr(rect.Right - rect.Left) +'" height="' + IntToStr(rect.Bottom - rect.Top) + '" src="http://' + Host + '/thumb/' + Document + '" scrolling="no" style="border:solid 1px #CCC;" frameborder="0"></iframe></div>'
201+ + '</body></html>';
202+ end;
203+end;
176204 end.