using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using FaucetCollector.Script; using OpenQA.Selenium.Remote; using System.Drawing; using OpenQA.Selenium; using System.IO; using System.Globalization; using OpenQA.Selenium.Interactions; public class TemplateScript : FaucetScript { /// /// List of Settings that will be shown in the bot when selecting this Faucet in the bot. /// You can get the value the user entered with the methods: GetSetting("[Name of the FaucetSetting]"), GetBoolSetting and GetDateTimeSetting /// You can also create a new setting value using SetSetting("[Name you want to use]", "value") /// public override FaucetSettings Settings { get { return new FaucetSettings("http://freek.in/") { new FaucetSetting() { Name = "Dodg_Wallet", Display = "FaucetHub Dodge Wallet", Type = EditorType.TextBox, Required = true }, new FaucetSetting(){Name="Disable",Display="Disable Faucet after finished", Type=EditorType.CheckBox, Default=false} }; } } /// /// This method gets called when the faucet is enabled and the GO button is clicked /// public override void Start() { //Title that shows in the browser. Is used to identify and close popup windows Title = "Free dodgecoin Faucet"+"|"+"Watching ads ... -Freek.in"; //After we did try to claim on the faucet we search for these elements to determine if it was a success or a fail SuccessXPath = "//div[@class='wc_red wc_font']"; FailXPath = ""; //Let Faucet Collector start up everything base.Start(); } /// /// This is the first method to run after the browser is opened and the first page is loaded. /// public override int DoInit() { //Let Faucet Collector continue. return base.DoInit(); } /// /// This method gets called after the Start method, here you need to return if we are logged in or not. /// If you return false then it will call the BeforeLogin, Login and AfterLogin methods so you can login. /// After those Login methods are called it will call this IsLoggedIn method again to see if the login did succeed. /// If you return true Faucet Collector will store all cookies so it will probably be already logged in on the next attempt. /// public override bool IsLoggedIn() { try { bool enc = false; var log = Driver.FindElements(By.TagName("button")); foreach (var log_ in log) { if (log_.Text == "LOGOUT") { enc = true; } } if (enc == false) { return false; } else { return true; } } catch (Exception) { return false; } } /// /// This method gets called if IsLoggedIn returned false, right before the DoLogin method is called. /// public override int BeforeLogin() { //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.BeforeLogin(); } /// /// This method gets called after BeforeLogin, but only if IsLoggedIn returned false. /// It can be used to actually login the user/enter wallet details in the faucet /// /// public override int DoLogin() { Wait(5); var CoinAdress = ElementByName("coinaddress"); if (!IsVisible(CoinAdress)) { return Fail("Signin Addres not found"); } SetText(CoinAdress, GetSetting("Dodg_Wallet")); int solution = getIconCaptchaSol(); if (solution == -1) { return Fail("Fail solve icon captcha"); } solution--; Wait(); try { ExecuteScript("var a=document.getElementsByClassName('captcha-image');var element =a[0];element.addEventListener('mouseover', function() {console.log('Event triggered');});var event = new MouseEvent('mouseover', {'view': window,'bubbles': true,'cancelable': true});element.dispatchEvent(event);a[" + solution + "].click();"); } catch (Exception) { return Fail("Fail Solve icon captcha"); } Wait(5); bool clicked = false; var loginb = Driver.FindElements(By.TagName("button")); foreach (var loginb_ in loginb) { if (loginb_.Text.Contains("LOGIN")) { loginb_.Click(); clicked = true; } } if (clicked == false) { return Fail("Fail to click button"); } Wait(); return base.DoLogin(); } /// /// This method gets called after the DoLogin method. /// public override int AfterLogin() { //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.AfterLogin(); } /// /// This method gets called after the login methods are successful, so we are logged into the faucet. /// If the faucet is not yet ready to claim you should return a TimeStamp value to return how long it takes before the Faucet claim can be done. /// This is used to pause the script while the faucet its timer runs out. /// Return the number of seconds the bot should wait. /// public override int GetFaucetWaitTime() { GoToUrl("http://freek.in/ptc/"); Wait(); var ads = Driver.FindElements(By.TagName("a")); int cont = 0; foreach (var ads_ in ads) { if (ads_.GetAttribute("href").Contains("freek.in/ptcview/")) { cont++; } } if (cont == 0) { return 4000; } else { return 0; } //let Faucet Collector continue. } /// /// This method is called right before a captcha will be solved. /// If you call SolveCaptcha() in other methods it will start this flow and tries to solve the captcha on the page. /// public override int BeforeSolveCaptcha() { //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.BeforeSolveCaptcha(); } /// /// This method gets called after BeforeSolveCaptcha and it does the actual captcha solving /// It will automatically try to see if there is a SolveMedia captcha active or a reCAPTCHA active. /// If it finds either one it will then use the selected method on the Captcha tab of FaucetCollector to solve the Captcha. /// public override int DoSolveCaptcha() { //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.DoSolveCaptcha(); } /// /// This method will get called after DoSolveCaptcha returned it was a success. /// /// public override int AfterSolveCaptcha() { //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.AfterSolveCaptcha(); } /// /// This method is called right before we attempt to claim on the faucet. So we are logged in and good to go. /// Next methods that will be called are DoSolveFaucet, AfterSolveFaucet and CheckFaucetResult. /// /// private static int n_ads; public override int BeforeSolveFaucet() { GoToUrl("http://freek.in/ptc/"); Wait(); var ads = Driver.FindElements(By.TagName("a")); int cont = 0; foreach(var ads_ in ads) { if (ads_.GetAttribute("href").Contains("freek.in/ptcview/")) { cont++; } } if (cont == 0) { if (GetBoolSetting("Disable")) { Disable(); } return Fail("no ads found"); } else { Log(cont.ToString() + " ads found"); n_ads = cont; } //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.BeforeSolveCaptcha(); } /// /// This method gets called after the BeforeSolveFaucet. You can do the actual claiming of the faucet in here. /// /// public override int DoSolveFaucet() { bool found; do { if (!Driver.Url.Contains("freek.in/ptc/")) { GoToUrl("http://freek.in/ptc/"); } Wait(); found = false; var ads = Driver.FindElements(By.TagName("a")); int cont = 0; foreach (var ads_ in ads) { if (ads_.GetAttribute("href").Contains("freek.in/ptcview/")) { Click(ads_); found = true; Wait(4); break; } } var timer = ElementById("myTimer"); while (IsVisible(timer)) { Wait(); } Wait(3); string urlad = Driver.Url; try { Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(25); var button2 = ElementById("myBtn"); if (!IsVisible(button2)) { return Fail("Fail click ad"); } Click((button2)); Wait(); if (!Driver.Url.Contains("freek.in")) { doShortLink("freek.in"); } } catch (Exception) { } Wait(4); } while (found == true); //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.DoSolveCaptcha(); } public bool doShortLink(string url) { bool iscorrect = true; DateTime t1; int cont = 0; bool bypassed = false; string url_a = Driver.Url; do { Title += "|" + Driver.Title; Wait(); try { int cont2 = 0; while (true) { Driver.SwitchTo().Frame(cont2); var b_deny = ElementById("B1"); if (IsVisible(b_deny)) { Click(b_deny); Wait(1); } cont2++; Driver.SwitchTo().DefaultContent(); } } catch (Exception) { Driver.SwitchTo().DefaultContent(); } Wait(); if (Driver.Url.Contains("dwindly.io")) { Wait(); var but = Driver.FindElement(By.Id("btd1")); Click(but); Wait(12); var but2 = Driver.FindElement(By.Id("btd")); Click(but); } else if (Driver.Url.Contains("zap.in")) { ExecuteScript("var v = document.getElementsByClassName('btn btn-primary'); v[0].click();"); var result = SolveCaptcha(); Wait(5); ExecuteScript("var v = document.getElementsByClassName('btn btn-primary'); v[1].click();"); } else { bool clicked = false; Wait(); var button = ElementById("invisibleCaptchaShortlink"); if (IsVisible(button)) { var img = ElementById("adcopy-outer-captchaShortlink"); var text = ElementById("adcopy_response-captchaShortlink"); if (img != null && text != null) { var result = DoSolveImageCaptcha(img, text); } else { var result = SolveCaptcha(); try { ExecuteScript("try{window.grecaptcha.getResponse = function(nr) { return '" + Context.CaptchaResult.Result + "'; }}catch(Exception){};"); } catch (Exception) { } } Wait(2, 3); button = ElementById("invisibleCaptchaShortlink"); if (button.Enabled == true) { button = ElementById("invisibleCaptchaShortlink"); Click(button); clicked = true; Wait(); } else { ExecuteScript("var but=document.getElementById(\"invisibleCaptchaShortlink\");but.outerHTML=but.outerHTML.replace('disabled=\"disabled\"','');"); Wait(3); button = ElementById("invisibleCaptchaShortlink"); Click(button); clicked = true; } } else { var button_2 = Driver.FindElements(By.TagName("button")); foreach (var _button_2 in button_2) { if (_button_2.Text.ToLower().Contains("continue")) { if (_button_2.Enabled == true) { Click(_button_2); clicked = true; Wait(); break; } else { ExecuteScript("var but=document.getElementsByTagName('button');for(i=0;i t1) { break; } } Click(button_p); clicked = true; Wait(); } } if (!clicked) { Wait(); if (IsVisible(ElementByXPath("//div[@id='pause']")) || IsVisible(ElementById("btd1"))) { var but = ElementById("btd1"); t1 = DateTime.Now.AddMinutes(1); while (!IsVisible(but)) { Wait(); but = ElementById("btd1"); if (DateTime.Now > t1) { break; } } Click(but); clicked = true; } } ///// CLICK FIRST BUTTON FINISHED if (clicked) { bool clicked_2 = false; var button_skip = ElementByXPath("//a[@class='btn btn-success btn-lg get-link']"); if (IsVisible(ElementByXPath("//a[@class='btn btn-success btn-lg get-link disabled']")) || IsVisible(ElementByXPath("//a[@class='btn btn-success btn-lg get-link']"))) { t1 = DateTime.Now.AddMinutes(1); while (button_skip == null) { Wait(); button_skip = ElementByXPath("//a[@class='btn btn-success btn-lg get-link']"); if (DateTime.Now > t1) { break; } } Click(button_skip); clicked_2 = true; } if (!clicked_2) { if (IsVisible(ElementByXPath("//div[@class='skip-ad']")) || IsVisible(ElementByXPath("//a[@class='btn']"))) { var button_skip_a = ElementByXPath("//a[@class='btn']"); t1 = DateTime.Now.AddMinutes(1); while (button_skip_a == null) { Wait(); button_skip_a = ElementByXPath("//a[@class='btn']"); if (DateTime.Now > t1) { break; } } Click(button_skip_a); clicked_2 = true; } } if (!clicked_2) { if (IsVisible(ElementByXPath("//a[@class='btn btn-success get-link disabled']")) || IsVisible(ElementByXPath("//a[@class='btn btn-success get-link']"))) { var button_skip_a = ElementByXPath("//a[@class='btn btn-success get-link']"); t1 = DateTime.Now.AddMinutes(1); while (button_skip_a == null) { Wait(); button_skip_a = ElementByXPath("//a[@class='btn btn-success get-link']"); if (DateTime.Now > t1) { break; } } Click(button_skip_a); clicked_2 = true; } } if (!clicked_2) { if (IsVisible(ElementByXPath("//a[@class='btn btn-primary btn-goo get-link disabled']")) || IsVisible(ElementByXPath("//a[@class='btn btn-primary btn-goo get-link']"))) { var button_skip_a = ElementByXPath("//a[@class='btn btn-primary btn-goo get-link']"); t1 = DateTime.Now; while (!IsVisible(button_skip_a)) { Wait(); button_skip_a = ElementByXPath("//a[@class='btn btn-primary btn-goo get-link']"); if (DateTime.Now > t1) { break; } } try { button_skip_a.Click(); try { Driver.SwitchTo().Alert().Accept(); } catch (Exception) { } } catch (Exception) { Click(button_skip_a); } clicked_2 = true; } } if (!clicked_2) { if (ElementByXPath("//a[@id='btn2']") != null) { var button_skip_a = ElementByXPath("//a[@id='btn2']"); t1 = DateTime.Now.AddMinutes(1); while (!button_skip_a.Enabled) { Wait(); button_skip_a = ElementByXPath("//a[@id='btn2']"); if (DateTime.Now > t1) { break; } } Click(button_skip_a); clicked_2 = true; } } if (!clicked_2) { if (IsVisible(ElementByXPath("//a[@class='getlinkbtn get-link disabled']")) || IsVisible(ElementByXPath("/a[@class='getlinkbtn get-link']"))) { var button_skip_a = ElementByXPath("/a[@class='getlinkbtn get-link']"); while (button_skip_a == null) { Wait(); button_skip_a = ElementByXPath("/a[@class='getlinkbtn get-link']"); } Click(button_skip_a); clicked_2 = true; } } } } try { Driver.SwitchTo().Alert().Accept(); } catch (Exception) { } if (Driver.Url.Contains(url)) { bypassed = true; Wait(3, 4); } else { bypassed = false; if (Driver.Url.Contains(url_a)) { Driver.Navigate().Refresh(); } else { GoToUrl(url_a); } } if (cont >= 3) { if (Driver.Url.Contains(url)) { iscorrect = true; } else { iscorrect = false; } break; } cont++; } while (!bypassed); return iscorrect; } /// /// This method will get called after the DoSolveFaucet is completed and returned it was a success. /// For example you can wait for a processing popup to go away until actual faucet claim result is on the page. /// public override int AfterSolveFaucet() { //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.AfterSolveFaucet(); } /// /// This method gets called in the end after the BeforeSolveFaucet/DoSolveFaucet and AfterSolveFaucet methods were done. /// The base.CheckFaucetResult will try to find a visible element on the page using the XPath from SuccessXPath and FailXPath (see the Start method) /// These properties should contain XPath expressions to find certain elements on the page. /// For example if it finds one of the elements from the SuccessXPath, and it is visible, then it will flag the claim attempt as a success. /// Or if it finds one of the elements from the FailXPath, and it is visible, then it will flag the claim attempt as a failure. /// public override int CheckFaucetResult() { GoToUrl("http://freek.in/ptc/"); Wait(); var ads = Driver.FindElements(By.TagName("a")); int cont = 0; foreach (var ads_ in ads) { if (ads_.GetAttribute("href").Contains("freek.in/ptcview/")) { cont++; } } if (cont == 0) { Log("Success " + n_ads.ToString() + " viewned"); if (GetBoolSetting("Disable")) { Disable(); } } else { return Fail("Not all ads have been seen"); } //This faucet has nothing to do here. We will let Faucet Collector handle it. return base.CheckFaucetResult(); } private Bitmap GetElementScreenShort(IWebDriver driver, IWebElement element) { Actions actions = new Actions(driver); actions.MoveToElement(element); actions.Perform(); Screenshot sc = ((ITakesScreenshot)driver).GetScreenshot(); var img = Image.FromStream(new MemoryStream(sc.AsByteArray)) as Bitmap; var x = ExecuteScript("let coords = arguments[0].getBoundingClientRect();return coords.left;", element); var y = ExecuteScript("let coords = arguments[0].getBoundingClientRect();return coords.top;", element); int x2 = Convert.ToInt32(x); int y2 = Convert.ToInt32(y); var width = ExecuteScript("let coords = arguments[0].getBoundingClientRect();return coords.width;", element); var height = ExecuteScript("let coords = arguments[0].getBoundingClientRect();return coords.height;", element); int width2 = Convert.ToInt32(width); int height2 = Convert.ToInt32(height); return img.Clone(new Rectangle(x2, y2, width2, height2), img.PixelFormat); } private int getIconCaptchaSol() { int sol = 0; Bitmap[] icons = new Bitmap[5]; var Icons = Driver.FindElements(By.ClassName("captcha-image")); int cont = 0; // foreach (var icon in Icons) // { foreach (var icon in Icons) { icons[cont] = GetElementScreenShort(Driver, icon); cont++; } // } int one_two, one_three, one_four, one_five; one_two = CompareImage(icons[0], icons[1]); one_three = CompareImage(icons[0], icons[2]); one_four = CompareImage(icons[0], icons[3]); one_five = CompareImage(icons[0], icons[4]); int m = one_two; int one_one = (one_five + one_four + one_two + one_three) / 4; if (one_one > 2200) { sol = 1; return sol; } if (m < one_three) { m = one_three; } if (m < one_four) { m = one_four; } if (m < one_five) { m = one_five; } if (m == one_two) { sol = 2; } else if (m == one_three) { sol = 3; } else if (m == one_four) { sol = 4; } else if (m == one_five) { sol = 5; } return sol; } private int CompareImage(Bitmap image1, Bitmap image2) { int cont = 0; for (int i = 0; i < image1.Height; i++) { for (int j = 0; j < image1.Width; j++) { if (image1.GetPixel(j, i) != image2.GetPixel(j, i)) { cont++; } } } return cont; } }