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,31 +317,28 @@ 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
344
acc . Wb . UpdateHtml ( ) ;
@@ -365,20 +362,17 @@ private async Task<bool> TryFastUpgrade(Account acc)
365
362
}
366
363
catch
367
364
{
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 ( ) ;
365
+ acc . Wb . UpdateHtml ( ) ;
366
+ if ( acc . Wb . Html . GetElementbyId ( "dontShowThisAgain" ) != null )
367
+ {
368
+ await DriverHelper . ClickById ( acc , "dontShowThisAgain" ) ;
369
+ await Task . Delay ( 800 ) ;
370
+ await DriverHelper . ClickByClassName ( acc , "dialogButtonOk ok" ) ;
371
+ }
372
+ else
373
+ {
374
+ await acc . Wb . Refresh ( ) ;
375
+ }
382
376
}
383
377
384
378
return true ;
0 commit comments