Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
- //
- // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
- //nicobrowserのC#移行&Chrome化しようと試みたもの
- //出来はお察し
- using System;
- using System.Diagnostics;
- using System.Drawing;
- using System.IO;
- using System.Windows.Forms;
- using CefSharp.MinimalExample.WinForms.Controls;
- using CefSharp.WinForms;
- namespace CefSharp.MinimalExample.WinForms
- {
- public partial class BrowserForm : Form
- {
- private string image_pass;
- private string _name;
- private readonly ChromiumWebBrowser browser;
- public BrowserForm()
- {
- InitializeComponent();
- Text = "CefSharp";
- //WindowState = FormWindowState.Minimized;
- browser = new ChromiumWebBrowser("www.google.com")
- {
- Dock = DockStyle.Fill,
- };
- toolStripContainer.ContentPanel.Controls.Add(browser);
- }
- private void BrowserForm_Load(object sender, EventArgs e)
- {
- // 現在のプロセスを取得する
- var hProcess = Process.GetCurrentProcess();
- lblname.Text = hProcess.Id.ToString();
- hProcess.Close();
- //不要になった時点で破棄する
- hProcess.Dispose();
- //■画像ファイルのパスを決める。(jpg,gif,png)
- if (File.Exists(Application.ExecutablePath + "準備中.gif")) {
- image_pass = Application.ExecutablePath + "準備中.gif";
- Console.WriteLine(DateTime.Now + " 準備中.gifの存在を確認。" + "\n");
- }
- else if (File.Exists(Application.ExecutablePath + "準備中.png"))
- {
- image_pass = Application.ExecutablePath + "準備中.png";
- Console.WriteLine(DateTime.Now + " 準備中.pngの存在を確認。" + "\n");
- }
- else if (File.Exists(Application.ExecutablePath + "準備中.jpg"))
- {
- image_pass = Application.ExecutablePath + "準備中.jpg";
- Console.WriteLine(DateTime.Now + " 準備中.jpgの存在を確認。" + "\n");
- }
- else if (File.Exists(Application.ExecutablePath + "準備中.gif"))
- {
- image_pass = Application.ExecutablePath + "準備中.jpeg";
- Console.WriteLine(DateTime.Now + " 準備中.jpegの存在を確認。" + "\n");
- }
- else
- {
- Console.WriteLine(DateTime.Now + " 画像ファイル 準備中.[jpg, png, gif]が存在しません。画像ファイルをこのアプリケーションのあるフォルダ内に置き、起動し直して下さい。" + "\n");
- image_pass = "";
- }
- Console.WriteLine(image_pass);
- //■gif以外であればリサイズし、ブラウザのサイズに合わせる。
- if ( image_pass.Contains("gif") & image_pass != "")
- {
- //描画先のImageオブジェクトを作成
- /* var canvas = New Bitmap(CInt(numwid.Value), CInt(numhei.Value));
- Dim g As Graphics = Graphics.FromImage(canvas) 'ImageオブジェクトのGraphicsオブジェクトを作成
- Dim image = New Bitmap(image_pass) 'Bitmapオブジェクトの作成
- g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic '高品質双三次補間
- g.DrawImage(image, 0, 0, CInt(numwid.Value), CInt(numhei.Value))
- image.Dispose()
- g.Dispose()
- canvas.Save("./temp_preparation.png")
- image_pass = My.Application.Info.DirectoryPath & "\temp_preparation.png"
- */
- }
- if (image_pass != "") {
- browser.Load(image_pass);
- }
- //■フォントの設定
- FontStyle style = FontStyle.Regular;
- if (numstyle.Value == 0)
- {
- style = FontStyle.Regular;
- }
- if (numstyle.Value == 1)
- {
- style = FontStyle.Bold;
- }
- if (numstyle.Value == 0)
- {
- style = FontStyle.Italic;
- }
- lblname.Font = new Font(txtfontname.Font, style);
- /*lblname.ForeColor = Color.FromArgb(numfore_r.Value, numfore_g.Value, numfore_b.Value);
- lblname.BackColor = Color.FromArgb(numback_r.Value, numback_g.Value, numback_b.Value);
- lblnote.Font = New Font(txtfontname.Text, numfontsize.Value, style)
- lblnote.ForeColor = Color.FromArgb(numfore_r.Value, numfore_g.Value, numfore_b.Value)
- lblnote.BackColor = Color.FromArgb(numback_r.Value, numback_g.Value, numback_b.Value)
- Panel1.BackColor = Color.FromArgb(numback_r.Value, numback_g.Value, numback_b.Value);
- */
- //ラベル関係の表示(まだ設定フォーム入れてないためコメントアウト...)
- /* if (Setting.chklabelview.Checked == True){
- lblname.Visible = True;
- if (Setting.chkover.Checked == False) {
- txtlabel_height.Text = lblname.Height.ToString();
- Panel1.Height = lblname.Height;
- }
- else if (Setting.chkover.Checked = True) {
- if (Setting.chklocklabel.Checked == True {
- //タイトルバー消去
- txtlabel_height.Text = 0;
- Panel1.Height = 0;
- }
- else if(Setting.chklocklabel.Checked == False){
- //タイトルバーの高さを20pxに
- txtlabel_height.Text = 20;
- Panel1.Height = 20;
- }
- }*/
- this.Size = new Size(Decimal.ToInt32(numwid.Value), Decimal.ToInt32(numhei.Value));
- }
- private void txtgettitle_TextChanged(object sender, EventArgs e)
- {
- string temp_name;
- if (txtgettitle.Text.Contains("_name"))
- {
- lblname.Text = txtgettitle.Text.Replace("name_", "");
- temp_name = txtgettitle.Text.Replace("name_", "");
- }
- else if (txtgettitle.Text.Contains("lv_nico_"))
- {
- browser.Load("http://live2.nicovideo.jp/watch/" + txtgettitle.Text.Replace("lv_nico_", ""));
- //エラー処理放置プレイ
- /*Do
- Application.DoEvents()
- Loop Until browser.IsBusy = False And
- Application.DoEvents()
- */
- /*f (Setting.chkfullscreen.Checked = True) {
- fullscreen();
- }*/
- }
- else if (txtgettitle.Text.Contains("lv_twitch_"))
- {
- browser.Load(txtgettitle.Text.Replace("lv_twitch_", ""));
- }
- else if (txtgettitle.Text.Contains("lv_youtube_"))
- {
- browser.Load(txtgettitle.Text.Replace("lv_youtube_", ""));
- }
- else if (txtgettitle.Text.Contains("lv_mixer_"))
- {
- // browser.Load(txtgettitle.Text.Replace("lv_mixer_", ""));
- }
- else if (txtgettitle.Text.Contains("lv_mixer_"))
- {
- browser.Load(txtgettitle.Text.Replace("lv_mixer_", ""));
- }
- else if (txtgettitle.Text.Contains("lv_blank_"))
- {
- if (image_pass != "")
- browser.Load(image_pass);
- }
- else if (txtgettitle.Text.Contains("sound_"))
- {
- sound_toggle();
- }
- else if (txtgettitle.Text.Contains("reload_screen_"))
- {
- //reload_screen();
- }
- else if (txtgettitle.Text.Contains("reload_browser_"))
- {
- //reload_browser();
- }
- }
- private void sound_toggle()
- {
- // if (txtgettitle.Text.Contains("nico"))
- //{
- string script = string.Format("document.getElementsByClassName('___button___P4VSB ___button-base___2v_kF ___button-skin___39Jyb ___local-tooltip___12dLk')[0].click();");
- browser.EvaluateScriptAsync(script);
- Console.WriteLine("音量ON/OFF変更を試みました");
- // }
- if (txtgettitle.Text.Contains("on")){
- // adjFontloc_noteon();
- }
- /* else{
- //adjFontloc_noteoff();
- }*/
- else if (txtgettitle.Text.Contains("twitch"))
- {
- script = string.Format("document.getElementsByClassName('player-button player-button--volume qa-control-volume')[0].click();");
- browser.EvaluateScriptAsync(script);
- Console.WriteLine("音量ON/OFF変更を試みました");
- }
- if (txtgettitle.Text.Contains("on"))
- {
- // adjFontloc_noteon();
- }
- /* else{
- //adjFontloc_noteoff();
- }*/
- else if (txtgettitle.Text.Contains("youtube"))
- {
- script = string.Format("document.getElementsByClassName('ytp-mute-button ytp-button')[0].click();");
- browser.EvaluateScriptAsync(script);
- Console.WriteLine("音量ON/OFF変更を試みました");
- }
- if (txtgettitle.Text.Contains("on"))
- {
- // adjFontloc_noteon();
- }
- /* else{
- //adjFontloc_noteoff();
- }*/
- else if (txtgettitle.Text.Contains("mixer"))
- {
- script = string.Format("document.getElementsByClassName('_ngcontent-c32')[0].click();");
- browser.EvaluateScriptAsync(script);
- Console.WriteLine("音量ON/OFF変更を試みました");
- }
- if (txtgettitle.Text.Contains("on"))
- {
- // adjFontloc_noteon();
- }
- /* else{
- //adjFontloc_noteoff();
- }*/
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement