|
1 | 1 | using HtmlAgilityPack;
|
2 | 2 | using OpenQA.Selenium;
|
| 3 | +using OpenQA.Selenium.Interactions; |
3 | 4 | using System;
|
4 | 5 | using System.Linq;
|
5 | 6 | using System.Threading.Tasks;
|
@@ -248,9 +249,8 @@ private async Task<bool> Upgrade(Account acc)
|
248 | 249 | var watchAd = false;
|
249 | 250 | if (acc.AccInfo.ServerVersion == ServerVersionEnum.T4_5 && buildDuration.TotalMinutes > acc.Settings.WatchAdAbove)
|
250 | 251 | {
|
251 |
| - // watchAd = await TryFastUpgrade(acc); |
252 | 252 | acc.Logger.Information("Try using watch ads upgrade button");
|
253 |
| - acc.Logger.Information("Watch ads function is disable because of bugs from Chrome. We cannot do anything about this"); |
| 253 | + watchAd = await TryFastUpgrade(acc); |
254 | 254 | }
|
255 | 255 |
|
256 | 256 | if (!watchAd)
|
@@ -317,68 +317,71 @@ private void PostTaskCheckDorf(Account acc)
|
317 | 317 | /// <returns>Whether bot watched the ad</returns>
|
318 | 318 | private async Task<bool> TryFastUpgrade(Account acc)
|
319 | 319 | {
|
320 |
| - acc.Wb.UpdateHtml(); |
321 | 320 | var nodeFastUpgrade = acc.Wb.Html.DocumentNode.Descendants("button").FirstOrDefault(x => x.HasClass("videoFeatureButton") && x.HasClass("green"));
|
322 | 321 | if (nodeFastUpgrade == null) return false;
|
323 |
| - var elementFastUpgrade = acc.Wb.Driver.FindElement(By.XPath(nodeFastUpgrade.XPath)); |
324 |
| - if (elementFastUpgrade == null) return false; |
325 |
| - elementFastUpgrade.Click(); |
326 |
| - |
327 |
| - await Task.Delay(rand.Next(1000, 2000)); |
328 |
| - |
| 322 | + var href = nodeFastUpgrade.GetAttributeValue("onclick", ""); |
| 323 | + var script = href.Replace("&", "&"); |
| 324 | + acc.Wb.Driver.ExecuteScript(script); |
| 325 | + await Task.Delay(rand.Next(900, 1300)); |
329 | 326 | // Confirm
|
330 |
| - acc.Wb.UpdateHtml(); |
331 |
| - var node = acc.Wb.Html.DocumentNode.SelectSingleNode("//input[@name='adSalesVideoInfoScreen']"); |
332 |
| - if (node != null) |
| 327 | + |
333 | 328 | {
|
334 |
| - var element = acc.Wb.Driver.FindElement(By.XPath(node.XPath)); |
335 |
| - if (element == null) |
336 |
| - { |
337 |
| - await acc.Wb.Refresh(); |
338 |
| - return false; |
339 |
| - } |
340 |
| - element.Click(); |
341 |
| - await DriverHelper.ExecuteScript(acc, "jQuery(window).trigger('showVideoWindowAfterInfoScreen')"); |
| 329 | + var result = await Update(acc); |
| 330 | + if (!result) return false; |
342 | 331 | }
|
343 | 332 |
|
344 |
| - await Task.Delay(rand.Next(10000, 18000)); |
| 333 | + var nodeNotShowAgainConfirm = acc.Wb.Html.DocumentNode.SelectSingleNode("//input[@name='adSalesVideoInfoScreen']"); |
| 334 | + if (nodeNotShowAgainConfirm != null) |
| 335 | + { |
| 336 | + acc.Logger.Information("Detected Watch AD diaglog. Choose Don't show again. ..."); |
| 337 | + var element = acc.Wb.Driver.FindElement(By.XPath(nodeNotShowAgainConfirm.XPath)); |
| 338 | + Actions act = new Actions(acc.Wb.Driver); |
| 339 | + act.MoveToElement(element).Click().Build().Perform(); |
| 340 | + acc.Wb.Driver.ExecuteScript("jQuery(window).trigger('showVideoWindowAfterInfoScreen')"); |
| 341 | + } |
345 | 342 |
|
346 | 343 | // click to play video
|
347 |
| - acc.Wb.UpdateHtml(); |
| 344 | + acc.Logger.Information("Waiting ads video load before clicking play button"); |
| 345 | + |
| 346 | + { |
| 347 | + var result = await Update(acc); |
| 348 | + if (!result) return false; |
| 349 | + } |
348 | 350 | var nodeIframe = acc.Wb.Html.GetElementbyId("videoFeature");
|
349 | 351 | if (nodeIframe == null)
|
350 | 352 | {
|
351 |
| - await acc.Wb.Refresh(); |
352 | 353 | return false;
|
353 | 354 | }
|
354 |
| - var elementIframe = acc.Wb.Driver.FindElementById("videoFeature"); |
355 |
| - if (elementIframe == null) |
| 355 | + |
356 | 356 | {
|
357 |
| - await acc.Wb.Refresh(); |
358 |
| - return false; |
| 357 | + await Task.Delay(rand.Next(20000, 30000)); |
| 358 | + |
| 359 | + var elementIframe = acc.Wb.Driver.FindElement(By.XPath(nodeIframe.XPath)); |
| 360 | + Actions act = new Actions(acc.Wb.Driver); |
| 361 | + act.MoveToElement(elementIframe).Click().Build().Perform(); |
359 | 362 | }
|
360 |
| - elementIframe.Click(); |
| 363 | + |
| 364 | + acc.Logger.Information("Clicked play button, if ads doesn't play please click to help bot"); |
| 365 | + acc.Logger.Information("Cooldown 3 mins. If building cannot upgrade will use normal button"); |
361 | 366 |
|
362 | 367 | try
|
363 | 368 | {
|
364 | 369 | await DriverHelper.WaitPageChange(acc, "dorf", 3);
|
365 | 370 | }
|
366 | 371 | catch
|
367 | 372 | {
|
368 |
| - await acc.Wb.Refresh(); |
369 |
| - return false; |
370 |
| - } |
371 |
| - |
372 |
| - // Don't show again |
373 |
| - await Task.Delay(rand.Next(1000, 2000)); |
374 |
| - acc.Wb.UpdateHtml(); |
375 |
| - |
376 |
| - if (acc.Wb.Html.GetElementbyId("dontShowThisAgain") != null) |
377 |
| - { |
378 |
| - await DriverHelper.ClickById(acc, "dontShowThisAgain"); |
379 |
| - await Task.Delay(800); |
380 |
| - await DriverHelper.ClickByClassName(acc, "dialogButtonOk ok"); |
381 |
| - await acc.Wb.Refresh(); |
| 373 | + acc.Wb.UpdateHtml(); |
| 374 | + if (acc.Wb.Html.GetElementbyId("dontShowThisAgain") != null) |
| 375 | + { |
| 376 | + await DriverHelper.ClickById(acc, "dontShowThisAgain"); |
| 377 | + await Task.Delay(800); |
| 378 | + await DriverHelper.ClickByClassName(acc, "dialogButtonOk ok"); |
| 379 | + } |
| 380 | + else |
| 381 | + { |
| 382 | + await acc.Wb.Refresh(); |
| 383 | + return false; |
| 384 | + } |
382 | 385 | }
|
383 | 386 |
|
384 | 387 | return true;
|
|
0 commit comments