-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathURLLoader.cs
More file actions
86 lines (74 loc) · 2.38 KB
/
URLLoader.cs
File metadata and controls
86 lines (74 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
using CefSharp;
using CefSharp.WinForms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
namespace LoadRandom
{
public partial class URLLoader : Form
{
private string proxy;
private string url;
private int time;
private ChromiumWebBrowser chromeBrowser;
private Timer proxyChangeTimer;
private void InitializeChromium()
{
try
{
var settings = new CefSettings();
Cef.Initialize(settings);
}
catch (Exception e) { }
chromeBrowser = new ChromiumWebBrowser(this.url);
chromeBrowser.IsBrowserInitializedChanged += OnBrowserInitializedChanged;
this.Controls.Add(chromeBrowser);
chromeBrowser.Dock = DockStyle.Fill;
}
private void OnBrowserInitializedChanged(object sender, EventArgs e)
{
if (chromeBrowser.IsBrowserInitialized)
{
ChangeProxy(this.proxy);
}
}
private void ChangeProxy(string proxyAddress)
{
var requestContext = chromeBrowser.GetBrowser().GetHost().RequestContext;
var proxySettings = new Dictionary<string, object>
{
["mode"] = "fixed_servers",
["server"] = proxyAddress
};
bool success = requestContext.SetPreference("proxy", proxySettings, out string errorMessage);
if (!success)
{
MessageBox.Show("Error setting proxy: " + errorMessage);
}
}
public URLLoader(string url, string proxy, int time)
{
this.url = url;
this.proxy = proxy;
this.time = time;
InitializeComponent();
InitializeChromium();
StartProxyChangeTimer();
}
private void StartProxyChangeTimer()
{
proxyChangeTimer = new Timer();
proxyChangeTimer.Interval = this.time *1000;
proxyChangeTimer.Tick += ProxyChangeTimer_Tick;
proxyChangeTimer.Start();
}
private void ProxyChangeTimer_Tick(object sender, EventArgs e)
{
this.Close();
}
private void URLLoader_Load(object sender, EventArgs e)
{
}
}
}