Advertisement
packyy

nicobrowser_cef_as_of_2018_03_07

Mar 6th, 2018
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 10.56 KB | None | 0 0
  1. // Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
  2. //
  3. // Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
  4.  
  5. //nicobrowserのC#移行&Chrome化しようと試みたもの
  6. //出来はお察し
  7.  
  8. using System;
  9. using System.Diagnostics;
  10. using System.Drawing;
  11. using System.IO;
  12. using System.Windows.Forms;
  13. using CefSharp.MinimalExample.WinForms.Controls;
  14. using CefSharp.WinForms;
  15.  
  16.  
  17. namespace CefSharp.MinimalExample.WinForms
  18. {
  19.     public partial class BrowserForm : Form
  20.     {
  21.        
  22.         private string image_pass;
  23.         private string _name;
  24.  
  25.         private readonly ChromiumWebBrowser browser;
  26.  
  27.         public BrowserForm()
  28.         {
  29.             InitializeComponent();
  30.  
  31.             Text = "CefSharp";
  32.             //WindowState = FormWindowState.Minimized;
  33.  
  34.             browser = new ChromiumWebBrowser("www.google.com")
  35.             {
  36.                 Dock = DockStyle.Fill,
  37.             };
  38.             toolStripContainer.ContentPanel.Controls.Add(browser);
  39.  
  40.            
  41.         }
  42.         private void BrowserForm_Load(object sender, EventArgs e)
  43.         {
  44.            
  45.  
  46.             // 現在のプロセスを取得する
  47.        var hProcess  = Process.GetCurrentProcess();
  48.  
  49.         lblname.Text = hProcess.Id.ToString();
  50.  
  51.             hProcess.Close();
  52.             //不要になった時点で破棄する
  53.             hProcess.Dispose();
  54.  
  55.  
  56.             //■画像ファイルのパスを決める。(jpg,gif,png)
  57.             if (File.Exists(Application.ExecutablePath + "準備中.gif")) {
  58.                 image_pass = Application.ExecutablePath + "準備中.gif";
  59.                 Console.WriteLine(DateTime.Now + "  準備中.gifの存在を確認。" + "\n");
  60.             }
  61.             else if (File.Exists(Application.ExecutablePath + "準備中.png"))
  62.             {
  63.                 image_pass = Application.ExecutablePath + "準備中.png";
  64.                 Console.WriteLine(DateTime.Now + "  準備中.pngの存在を確認。" + "\n");
  65.             }
  66.            else if (File.Exists(Application.ExecutablePath + "準備中.jpg"))
  67.             {
  68.                 image_pass = Application.ExecutablePath + "準備中.jpg";
  69.                 Console.WriteLine(DateTime.Now + "  準備中.jpgの存在を確認。" + "\n");
  70.             }
  71.            else if (File.Exists(Application.ExecutablePath + "準備中.gif"))
  72.             {
  73.                 image_pass = Application.ExecutablePath + "準備中.jpeg";
  74.                 Console.WriteLine(DateTime.Now + "  準備中.jpegの存在を確認。" + "\n");
  75.             }
  76.             else
  77.             {
  78.                 Console.WriteLine(DateTime.Now + "  画像ファイル 準備中.[jpg, png, gif]が存在しません。画像ファイルをこのアプリケーションのあるフォルダ内に置き、起動し直して下さい。" + "\n");
  79.                 image_pass = "";
  80.             }
  81.             Console.WriteLine(image_pass);
  82.  
  83.             //■gif以外であればリサイズし、ブラウザのサイズに合わせる。
  84.             if ( image_pass.Contains("gif") & image_pass != "")
  85.             {
  86.                 //描画先のImageオブジェクトを作成
  87.               /*  var canvas = New Bitmap(CInt(numwid.Value), CInt(numhei.Value));
  88.             Dim g As Graphics = Graphics.FromImage(canvas) 'ImageオブジェクトのGraphicsオブジェクトを作成
  89.             Dim image = New Bitmap(image_pass)   'Bitmapオブジェクトの作成
  90.  
  91.             g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic '高品質双三次補間
  92.             g.DrawImage(image, 0, 0, CInt(numwid.Value), CInt(numhei.Value))
  93.  
  94.             image.Dispose()
  95.             g.Dispose()
  96.  
  97.             canvas.Save("./temp_preparation.png")
  98.             image_pass = My.Application.Info.DirectoryPath & "\temp_preparation.png"
  99.             */
  100.             }
  101.             if (image_pass != "") {
  102.                 browser.Load(image_pass);
  103.             }
  104.             //■フォントの設定
  105.             FontStyle style = FontStyle.Regular;
  106.             if (numstyle.Value == 0)
  107.             {
  108.                 style = FontStyle.Regular;
  109.             }
  110.             if (numstyle.Value == 1)
  111.             {
  112.                 style = FontStyle.Bold;
  113.             }
  114.             if (numstyle.Value == 0)
  115.             {
  116.                 style = FontStyle.Italic;
  117.             }
  118.             lblname.Font =  new Font(txtfontname.Font,  style);
  119.             /*lblname.ForeColor = Color.FromArgb(numfore_r.Value, numfore_g.Value, numfore_b.Value);
  120.             lblname.BackColor = Color.FromArgb(numback_r.Value, numback_g.Value, numback_b.Value);
  121.  
  122.         lblnote.Font = New Font(txtfontname.Text, numfontsize.Value, style)
  123.         lblnote.ForeColor = Color.FromArgb(numfore_r.Value, numfore_g.Value, numfore_b.Value)
  124.         lblnote.BackColor = Color.FromArgb(numback_r.Value, numback_g.Value, numback_b.Value)
  125.  
  126.         Panel1.BackColor = Color.FromArgb(numback_r.Value, numback_g.Value, numback_b.Value);
  127.         */
  128.             //ラベル関係の表示(まだ設定フォーム入れてないためコメントアウト...)
  129.             /*  if (Setting.chklabelview.Checked == True){
  130.                   lblname.Visible = True;
  131.  
  132.  
  133.  
  134.                   if (Setting.chkover.Checked == False) {
  135.                       txtlabel_height.Text = lblname.Height.ToString();
  136.                       Panel1.Height = lblname.Height;
  137.                   }
  138.                   else if (Setting.chkover.Checked = True) {
  139.  
  140.                       if (Setting.chklocklabel.Checked == True {
  141.                           //タイトルバー消去
  142.                           txtlabel_height.Text = 0;
  143.                           Panel1.Height = 0;
  144.                       }
  145.  
  146.                  else if(Setting.chklocklabel.Checked == False){
  147.                           //タイトルバーの高さを20pxに
  148.                           txtlabel_height.Text = 20;
  149.                           Panel1.Height = 20;
  150.  
  151.                   }
  152.  
  153.              }*/
  154.             this.Size = new Size(Decimal.ToInt32(numwid.Value), Decimal.ToInt32(numhei.Value));
  155.          
  156.         }
  157.  
  158.         private void txtgettitle_TextChanged(object sender, EventArgs e)
  159.         {
  160.             string temp_name;
  161.             if (txtgettitle.Text.Contains("_name"))
  162.             {
  163.                 lblname.Text = txtgettitle.Text.Replace("name_", "");
  164.                 temp_name = txtgettitle.Text.Replace("name_", "");
  165.             }
  166.             else if (txtgettitle.Text.Contains("lv_nico_"))
  167.             {
  168.                 browser.Load("http://live2.nicovideo.jp/watch/" + txtgettitle.Text.Replace("lv_nico_", ""));
  169.                 //エラー処理放置プレイ
  170.                 /*Do
  171.                         Application.DoEvents()
  172.                     Loop Until browser.IsBusy = False And
  173.                         Application.DoEvents()
  174.                         */
  175.  
  176.                 /*f (Setting.chkfullscreen.Checked = True) {
  177.                          fullscreen();
  178.                      }*/
  179.             }
  180.             else if (txtgettitle.Text.Contains("lv_twitch_"))
  181.             {
  182.                 browser.Load(txtgettitle.Text.Replace("lv_twitch_", ""));
  183.             }
  184.             else if (txtgettitle.Text.Contains("lv_youtube_"))
  185.             {
  186.                 browser.Load(txtgettitle.Text.Replace("lv_youtube_", ""));
  187.             }
  188.             else if (txtgettitle.Text.Contains("lv_mixer_"))
  189.             {
  190.                 // browser.Load(txtgettitle.Text.Replace("lv_mixer_", ""));
  191.             }
  192.             else if (txtgettitle.Text.Contains("lv_mixer_"))
  193.             {
  194.                 browser.Load(txtgettitle.Text.Replace("lv_mixer_", ""));
  195.             }
  196.             else if (txtgettitle.Text.Contains("lv_blank_"))
  197.             {
  198.                 if (image_pass != "")
  199.                     browser.Load(image_pass);
  200.            
  201.             }
  202.             else if (txtgettitle.Text.Contains("sound_"))
  203.             {
  204.                 sound_toggle();
  205.             }
  206.             else if (txtgettitle.Text.Contains("reload_screen_"))
  207.             {
  208.                 //reload_screen();
  209.             }
  210.             else if (txtgettitle.Text.Contains("reload_browser_"))
  211.             {
  212.                 //reload_browser();
  213.             }
  214.         }
  215.         private void sound_toggle()
  216.         {
  217.            
  218.            
  219.            // if (txtgettitle.Text.Contains("nico"))
  220.             //{
  221.                 string script = string.Format("document.getElementsByClassName('___button___P4VSB ___button-base___2v_kF ___button-skin___39Jyb ___local-tooltip___12dLk')[0].click();");
  222.                 browser.EvaluateScriptAsync(script);
  223.                 Console.WriteLine("音量ON/OFF変更を試みました");
  224.             // }
  225.             if (txtgettitle.Text.Contains("on")){
  226.               //  adjFontloc_noteon();
  227.             }
  228.            /* else{
  229.                 //adjFontloc_noteoff();
  230.             }*/
  231.             else if (txtgettitle.Text.Contains("twitch"))
  232.             {
  233.                  script = string.Format("document.getElementsByClassName('player-button player-button--volume qa-control-volume')[0].click();");
  234.                 browser.EvaluateScriptAsync(script);
  235.                 Console.WriteLine("音量ON/OFF変更を試みました");
  236.             }
  237.             if (txtgettitle.Text.Contains("on"))
  238.             {
  239.                 //  adjFontloc_noteon();
  240.             }
  241.             /* else{
  242.                  //adjFontloc_noteoff();
  243.              }*/
  244.             else if (txtgettitle.Text.Contains("youtube"))
  245.             {
  246.                 script = string.Format("document.getElementsByClassName('ytp-mute-button ytp-button')[0].click();");
  247.                 browser.EvaluateScriptAsync(script);
  248.                 Console.WriteLine("音量ON/OFF変更を試みました");
  249.             }
  250.             if (txtgettitle.Text.Contains("on"))
  251.             {
  252.                 //  adjFontloc_noteon();
  253.             }
  254.             /* else{
  255.                  //adjFontloc_noteoff();
  256.              }*/
  257.  
  258.             else if (txtgettitle.Text.Contains("mixer"))
  259.             {
  260.                 script = string.Format("document.getElementsByClassName('_ngcontent-c32')[0].click();");
  261.                 browser.EvaluateScriptAsync(script);
  262.                 Console.WriteLine("音量ON/OFF変更を試みました");
  263.             }
  264.             if (txtgettitle.Text.Contains("on"))
  265.             {
  266.                 //  adjFontloc_noteon();
  267.             }
  268.             /* else{
  269.                  //adjFontloc_noteoff();
  270.              }*/
  271.  
  272.         }
  273.  
  274.  
  275.     }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement