· 5 years ago · Sep 12, 2020, 08:48 AM
1using OpenQA.Selenium;
2using OpenQA.Selenium.Chrome;
3using OpenQA.Selenium.Firefox;
4using OpenQA.Selenium.Support.UI;
5using System;
6using System.Collections.Generic;
7using System.ComponentModel;
8using System.Data;
9using System.Drawing;
10using System.IO;
11using System.Linq;
12using System.Text;
13using System.Threading;
14using System.Windows.Forms;
15
16namespace cookie_exporter
17{
18 public partial class mainForm : Form
19 {
20 private IWebDriver _driver;
21 public mainForm()
22 {
23 InitializeComponent();
24 }
25
26 #region events
27 private void btnStart_Click(object sender, EventArgs e)
28 {
29 var text = btnStart.Text;
30 if (text == "Start") start();
31 else stop();
32 }
33 private void btnExport_Click(object sender, EventArgs e)
34 {
35 export();
36 }
37
38 private void btnImport_Click(object sender, EventArgs e)
39 {
40 import();
41 }
42 private void btnDeleteCookies_Click(object sender, EventArgs e)
43 {
44 delete_all_cookies();
45 }
46 #endregion
47
48 #region main
49
50
51 private static IWebElement FindElement(IWebDriver driver, By by, bool throwException = true)
52 {
53 IWebElement result;
54 try
55 {
56 result = driver.FindElement(by);
57 }
58 catch
59 {
60 if (throwException)
61 {
62 throw new Exception("Error");
63 }
64 result = null;
65 }
66 return result;
67 }
68 public static List<string> keywords = new List<string>();
69 public static List<string> comments = new List<string>();
70 public static List<string> comments2 = new List<string>();
71 public static List<string> urlslist = new List<string>();
72
73 public static Random rnd = new Random();
74 public static string rndtime()
75 {
76
77 int f = rnd.Next(1, 5);
78 int g = rnd.Next(1, 9);
79 int o = rnd.Next(1, 5);
80 int z = rnd.Next(1, 9);
81 string time = String.Format("{0}{1}:{2}{3}", f, g, o, z);
82
83 return time;
84 }
85 public static void tags()
86 {
87
88 string[] urls = File.ReadAllLines("urls.txt");
89
90 for (int i = 1; i < urls.Length; i++)
91 {
92 if (urls[i] == "")
93 continue;
94 string[] lineParts = urls[i].Split('\n');
95 urlslist.Add(urls[i]);
96 }
97
98 string[] lines = File.ReadAllLines("keywords.txt");
99
100 for (int i = 1; i < lines.Length; i++)
101 {
102 if (lines[i] == "")
103 continue;
104 string[] lineParts = lines[i].Split('\n');
105 keywords.Add(lines[i]);
106 }
107
108
109 string[] lines3 = File.ReadAllLines("comments3.txt");
110
111 for (int i = 1; i < lines3.Length; i++)
112 {
113 if (lines3[i] == "")
114 continue;
115 string[] lineParts = lines3[i].Split('\n');
116 comments2.Add(lines3[i]);
117 }
118
119 string[] lines2 = File.ReadAllLines("comments.txt");
120
121 for (int i = 1; i < lines2.Length; i++)
122 {
123 if (lines2[i] == "")
124 continue;
125 string[] lineParts = lines2[i].Split('\n');
126 comments.Add(rndtime() + " " + comments2[rnd.Next(comments2.Count)] + " " + "https://shorturl.ca/hotgirls4night" + " " + GlobalVars.emoji());
127 comments.Add("https://shorturl.ca/hotgirls4night" + " " + lines2[i] + GlobalVars.emoji() +" "+ comments2[rnd.Next(comments2.Count)]);
128 }
129
130 using (StreamWriter sw = new StreamWriter("comments2.txt"))
131 {
132 for (int i = 0; i < comments.Count; i++)
133 {
134 sw.Write(comments[i].ToString());
135 sw.Write("\n");
136 }
137 }
138
139
140 }
141 public void youtube()
142 {
143 IJavaScriptExecutor js = (IJavaScriptExecutor)this._driver;
144 tags();
145 js.ExecuteScript("window.location.href =\"chrome-extension://elehoigefplgmjinmaedfccpegffbmfk/index.html\"");
146 Thread.Sleep(3000);
147 js.ExecuteScript("document.querySelector(\"body > div.container-fluid > div > div > div.col-7 > div > div > div.text-center.mt-3 > div\").innerText='1'");
148 Thread.Sleep(3000);
149 string b = "document.querySelector(\"#kill_ch\").click()";
150 int f = rnd.Next(1, 5);
151 int g = rnd.Next(1, 9);
152 int o = rnd.Next(1, 5);
153 int z = rnd.Next(1, 9);
154 IWebElement webElement;
155 string time = String.Format("{0}{1}:{2}{3}", f, g, o,z);
156 string s = "document.querySelector(\"#form-tags-6_tagsinput > span:nth-child(1) > button\").click()";
157
158 for (int i = 0; i < 10; i++)
159 {
160 js.ExecuteScript(s);
161 }
162 js.ExecuteScript(b); //chanel unclick
163 js.ExecuteScript("document.querySelector(\"#min-delay\").value=30"); //min value
164 js.ExecuteScript("document.querySelector(\"#max-delay\").value=40"); //max value
165 // js.ExecuteScript("document.querySelector(\"#shared-limit\").value=3"); //comment limits
166 js.ExecuteScript("document.querySelector(\"body > div.container-fluid > div > div > div.col-7 > div > div > div:nth-child(1) > div.card-header.p-2 > div > div:nth-child(1) > div:nth-child(2) > label\").click()"); //list btn
167 Thread.Sleep(100);
168 webElement = FindElement(this._driver, By.XPath("/html/body/div[1]/div/div/div[2]/div/div/div[1]/div[2]/div[2]/div[1]/input"), false);
169 webElement.SendKeys(@"C:\Users\User\Desktop\pva\coockiecreator\coockies\cookies.txt-importer-for-chrome-master\cookie-exporter\bin\Debug\comments2.txt");
170
171
172
173 webElement = FindElement(this._driver, By.XPath("/html/body/div[1]/div/div/div[1]/div/div/div[1]/div[1]/div/div/input"), false); //tags
174
175 webElement.SendKeys(keywords[rnd.Next(keywords.Count)] + OpenQA.Selenium.Keys.Enter);
176 webElement.SendKeys(keywords[rnd.Next(keywords.Count)] + OpenQA.Selenium.Keys.Enter);
177
178 js.ExecuteScript("document.querySelector(\"#kill188\").click()"); //find button
179 Thread.Sleep(1500);
180 js.ExecuteScript("document.querySelector(\"#table_id_wrapper > div:nth-child(2) > div > div > div.dataTables_scrollHead > div > table > thead > tr > th.select-checkbox.sorting_disabled\").click()"); //tick
181 Thread.Sleep(3000);
182
183 js.ExecuteScript("document.querySelector(\"#stt\").click()"); //start bot
184 Thread.Sleep(3000);
185 comments.Clear();
186 keywords.Clear();
187 }
188 static Semaphore sem = new Semaphore(3, 3);
189 Thread myThread;
190 int count = 3;
191 public void bigfunc()
192 {
193 sem.WaitOne();
194 ChromeOptions chromeOptions = new ChromeOptions();
195 chromeOptions.AddExtension("ybot2.crx");
196 chromeOptions.AddArgument($"--user-agent={GlobalVars.randomuser()}");
197 this._driver = new ChromeDriver(chromeOptions);
198 import_cookies($"cookies{count}.txt");
199 youtube();
200 Thread.Sleep(1400000);
201 IJavaScriptExecutor js = (IJavaScriptExecutor)this._driver;
202 js.ExecuteScript("window.location.href =\"https://www.youtube.com\"");
203
204 this._driver.Manage().Cookies.DeleteAllCookies();
205 sem.Release();
206 count--;
207 }
208 private void start()
209 {
210 // UI init
211 bool is_chrome = radioChrome.Checked;
212 btnStart.Text = "Stop";
213 groupExport.Enabled = true;
214 btnDeleteCookies.Enabled = true;
215
216 // start driver
217 if (is_chrome)
218 {
219 myThread = new Thread(bigfunc);
220 myThread.Start();
221
222
223 //ChromeOptions chromeOptions = new ChromeOptions();
224 //chromeOptions.AddExtension("ybot2.crx");
225 //chromeOptions.AddArgument($"--user-agent={GlobalVars.randomuser()}");
226
227 ////ChromeDriver chromeDriver = new ChromeDriver();
228 //this._driver = new ChromeDriver(chromeOptions);
229 //int k = 1;
230 //for (int i = 0; i < 999; i++)
231 //{
232
233 // import_cookies($"cookies{k}.txt");
234 // youtube();
235 // Thread.Sleep(120000);
236 // MessageBox.Show("3 comments done");
237 // k++;
238 // if (k == 6) k = 1;
239 // this._driver.Manage().Cookies.DeleteAllCookies();
240 // sem.Release();
241
242 //}
243
244
245
246
247 }
248
249 else this._driver = new FirefoxDriver();
250
251
252 }
253 private void stop()
254 {
255 // UI init
256 btnStart.Text = "Start";
257 groupExport.Enabled = false;
258 btnDeleteCookies.Enabled = false;
259
260 // dispose browser (if not null)
261 if(this._driver != null)
262 {
263 try
264 {
265 this._driver.Dispose();
266 }
267 catch { }
268 }
269 }
270 private void export()
271 {
272 string filename = txtCookies.Text;
273 // check if filename was given
274 if (string.IsNullOrWhiteSpace(filename))
275 {
276 MessageBox.Show("Type a filename first");
277 return;
278 }
279 int exported = export_cookies(filename);
280 MessageBox.Show(string.Format("{0} cookies exported to {1}", exported, filename));
281 }
282 private void import()
283 {
284 string filename = txtImport.Text;
285 // check if file was given
286 if (string.IsNullOrWhiteSpace(filename))
287 {
288 MessageBox.Show("Type a filename first");
289 return;
290 }
291 // check if file exists
292 if(!File.Exists(filename))
293 {
294 MessageBox.Show(string.Format("{0} does not exist", filename));
295 return;
296 }
297 int imported = import_cookies(filename);
298 MessageBox.Show(string.Format("{0} cookie/s imported", imported));
299 }
300 private void delete_all_cookies()
301 {
302 if (this._driver == null) return;
303 this._driver.Manage().Cookies.DeleteAllCookies(); // clear all cookies
304 MessageBox.Show("Cookies cleared");
305 }
306 #endregion
307
308 #region cookie handling
309 private int export_cookies(string filename)
310 {
311 // Open streamwriter for writing to file
312 using (StreamWriter wr = new StreamWriter(filename))
313 {
314 foreach (var cookie in this._driver.Manage().Cookies.AllCookies)
315 {
316 // create cookie "line" with a custom format (we'll split by this when importing)
317 var c = string.Format("{0};;_^_;;{1};;_^_;;{2};;_^_;;{3};;_^_;;{4};;_^_;;{5}",
318 cookie.Name, cookie.Value, cookie.Domain, cookie.Path, cookie.Expiry, cookie.IsHttpOnly);
319 wr.WriteLine(c);
320 }
321 }
322 return this._driver.Manage().Cookies.AllCookies.Count;
323 }
324 private int import_cookies(string filename)
325 {
326 int imported = 0;
327 string last_domain = "";
328
329 // start reading from file
330 using (StreamReader wr = new StreamReader(filename))
331 {
332 string line = "";
333 while (wr.Peek() >= 0)
334 {
335 // line by line
336 line = wr.ReadLine();
337
338 // split it by our delimiter
339 var s = line.Split(new string[] { ";;_^_;;" }, StringSplitOptions.None);
340 // if no date given, set it to somewhere in the future
341 if (string.IsNullOrWhiteSpace(s[4])) s[4] = "05/01/2030";
342
343 // create cookie from string/s
344 Cookie c = new Cookie(s[0], s[1], s[2], s[3], Convert.ToDateTime(s[4]));
345
346 // IMPORTANT
347 // ---------
348 // go to domain, if not already there
349 // otherwise, import / adding the cookie will throw an error
350 if (!this._driver.Url.Contains(c.Domain))
351 this._driver.Navigate().GoToUrl(c.Domain.StartsWith("http") ? c.Domain : "http://" + c.Domain);
352 this._driver.Manage().Cookies.AddCookie(c); // add cookie to browser
353 imported++; // keep a counter
354 last_domain = this._driver.Url; // use it to go to it, once all imported, so we're logged in (eventually)
355 }
356 }
357 this._driver.Navigate().GoToUrl(last_domain); // go to last domain
358 return imported;
359 }
360 #endregion
361 }
362}
363