Advertisement
Guest User

Untitled

a guest
Dec 11th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.20 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Reflection;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Xml;
  10. using IMLokesh.Extensions;
  11. using IMLokesh.Http;
  12. using IMLokesh.RandomUtility;
  13. using Newtonsoft.Json;
  14. using Newtonsoft.Json.Linq;
  15. using ns0;
  16. using OpenQA.Selenium;
  17. using OpenQA.Selenium.Chrome;
  18. using OpenQA.Selenium.Interactions;
  19.  
  20. namespace Better_Nike_Bot.Utilities {
  21. // Token: 0x020000B1 RID: 177
  22. public static class WebUtilities {
  23. // Token: 0x060005DC RID: 1500 RVA: 0x0001ED48 File Offset: 0x0001CF48
  24. public static List < Cookie > GetAllCookies(this CookieContainer cc) {
  25. List < Cookie > list = new List < Cookie > ();
  26. Hashtable hashtable = (Hashtable) cc.GetType().InvokeMember("m_domainTable", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, cc, new object[0]);
  27. foreach(object obj in hashtable.Values) {
  28. SortedList sortedList = (SortedList) obj.GetType().InvokeMember("m_list", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, obj, new object[0]);
  29. foreach(object obj2 in sortedList.Values) {
  30. CookieCollection cookieCollection = (CookieCollection) obj2;
  31. foreach(object obj3 in cookieCollection) {
  32. Cookie item = (Cookie) obj3;
  33. list.Add(item);
  34. }
  35. }
  36. }
  37. return list;
  38. }
  39.  
  40. // Token: 0x060005DD RID: 1501 RVA: 0x0004BC34 File Offset: 0x00049E34
  41. public static JObject XmlToJson(this string xml) {
  42. XmlDocument xmlDocument = new XmlDocument();
  43. xmlDocument.LoadXml(xml);
  44. return JObject.Parse(JsonConvert.SerializeXmlNode(xmlDocument));
  45. }
  46.  
  47. // Token: 0x060005DE RID: 1502 RVA: 0x0004BC5C File Offset: 0x00049E5C
  48. public static string Base64Encode(this string plainText) {
  49. byte[] bytes = Encoding.UTF8.GetBytes(plainText);
  50. return Convert.ToBase64String(bytes);
  51. }
  52.  
  53. // Token: 0x060005DF RID: 1503 RVA: 0x0004BC7C File Offset: 0x00049E7C
  54. public static void SetLocaleChinaCookies(Http http) {
  55. foreach(string text in new string[] {
  56. "nike_locale=cn/zh_cn",
  57. "NIKE_COMMERCE_COUNTRY=CN",
  58. "NIKE_COMMERCE_LANG_LOCALE=zh_CN",
  59. "CONSUMERCHOICE=cn/zh_cn"
  60. }) {
  61. string[] array2 = text.Split(new char[] {
  62. '='
  63. });
  64. Cookie cookie = new Cookie(array2[0], array2[1]) {
  65. Secure = true,
  66. Domain = ".nike.com"
  67. };
  68. http.Cookies.Add(new Uri("https://nike.com/join"), cookie);
  69. }
  70. }
  71.  
  72. // Token: 0x060005E0 RID: 1504 RVA: 0x0004BD20 File Offset: 0x00049F20
  73. public static void SetLocaleCookies(Http http) {
  74. string str = "nike_locale={0}/{1}\r\nNIKE_COMMERCE_COUNTRY={2}\r\nNIKE_COMMERCE_LANG_LOCALE={1}\r\nCONSUMERCHOICE={0}/{1}".With(new object[] {
  75. Delegate905.smethod_0(),
  76. Delegate879.smethod_0(),
  77. Delegate677.smethod_0()
  78. });
  79. foreach(string text in str.GetLinesArray(true)) {
  80. string[] array = text.Split(new char[] {
  81. '='
  82. });
  83. Cookie cookie = new Cookie(array[0], array[1]) {
  84. Secure = true,
  85. Domain = ".nike.com"
  86. };
  87. http.Cookies.Add(new Uri("https://nike.com/join"), cookie);
  88. }
  89. }
  90.  
  91. // Token: 0x060005E1 RID: 1505 RVA: 0x0004BDD0 File Offset: 0x00049FD0
  92. public static IWebElement SelectElement(this IWebDriver driver, string selector) {
  93. IWebElement result = null;
  94. try {
  95. result = driver.FindElement(By.CssSelector(selector));
  96. } catch (Exception) {}
  97. return result;
  98. }
  99.  
  100. // Token: 0x060005E2 RID: 1506 RVA: 0x0004BE04 File Offset: 0x0004A004
  101. public static IEnumerable < IWebElement > SelectElements(this IWebDriver driver, string selector) {
  102. List < IWebElement > result = new List < IWebElement > ();
  103. try {
  104. result = driver.FindElements(By.CssSelector(selector)).ToList < IWebElement > ();
  105. } catch (Exception) {}
  106. return result;
  107. }
  108.  
  109. // Token: 0x060005E3 RID: 1507 RVA: 0x0004BE40 File Offset: 0x0004A040
  110. public static void SendKeysWithPause(this IWebElement element, string data, int pause = 10) {
  111. for(int i = 0; i < data.Length; i++) {
  112. element.SendKeys(data[i].ToString());
  113. Thread.Sleep(pause);
  114. }
  115. }
  116.  
  117. // Token: 0x060005E4 RID: 1508 RVA: 0x0004BE7C File Offset: 0x0004A07C
  118. public static void SendKeysWithClick(this IWebElement element, IWebDriver driver, string keys, bool randomOffset = true, int maxOffset = 20) {
  119. Actions actions = new Actions(driver);
  120. int num = randomOffset ? RandomHelper.RandomInt(0, maxOffset) : 0;
  121. int num2 = randomOffset ? RandomHelper.RandomInt(0, maxOffset) : 0;
  122. actions.MoveToElement(element, num, num2).Click().SendKeys(element, keys).Build().Perform();
  123. }
  124.  
  125. // Token: 0x060005E5 RID: 1509 RVA: 0x0004BED0 File Offset: 0x0004A0D0
  126. public static void SendClickWithMovement(this IWebElement element, IWebDriver driver, bool randomOffset = true, int maxOffset = 5) {
  127. Actions actions = new Actions(driver);
  128. int num = randomOffset ? RandomHelper.RandomInt(0, maxOffset) : 0;
  129. int num2 = randomOffset ? RandomHelper.RandomInt(0, maxOffset) : 0;
  130. actions.MoveToElement(element, num, num2).Click().Build().Perform();
  131. }
  132.  
  133. // Token: 0x060005E6 RID: 1510 RVA: 0x0004BF18 File Offset: 0x0004A118
  134. public static void MoveTo(this IWebElement element, IWebDriver driver, bool randomOffset = true, int maxOffset = 5) {
  135. Actions actions = new Actions(driver);
  136. int num = randomOffset ? RandomHelper.RandomInt(0, maxOffset) : 0;
  137. int num2 = randomOffset ? RandomHelper.RandomInt(0, maxOffset) : 0;
  138. actions.MoveToElement(element, num, num2).Build().Perform();
  139. }
  140.  
  141. // Token: 0x060005E7 RID: 1511 RVA: 0x00004DF3 File Offset: 0x00002FF3
  142. public static void AddRandomElements(this ChromeDriver driver, string selector = "body") {
  143. driver.ExecuteScript("function getRandomInt(max) {\r\n return Math.floor(Math.random() * Math.floor(max));\r\n }\r\n \r\n for(x=0; x<200;x++) {\r\n var mybnbdiv = document.createElement('div');\r\n var bnb_parent = document.querySelector('SELECTOR');\r\n mybnbdiv.className = 'bnbnike' + getRandomInt(10000);\r\n mybnbdiv.style.width = getRandomInt(50) + 'px';\r\n mybnbdiv.style.height = getRandomInt(50) + 'px';\r\n mybnbdiv.style.display = 'inline-block';\r\n bnb_parent.appendChild(mybnbdiv);\r\n }".Replace("SELECTOR", selector), new object[0]);
  144. }
  145.  
  146. // Token: 0x060005E8 RID: 1512 RVA: 0x0004BF5C File Offset: 0x0004A15C
  147. public static bool CheckAbck(this IWebDriver driver) {
  148. IJavaScriptExecutor javaScriptExecutor = (IJavaScriptExecutor) driver;
  149. string text = ((string) javaScriptExecutor.ExecuteScript("return document.cookie", new object[0])) ? ? "";
  150. return text.Contains("~0~");
  151. }
  152.  
  153. // Token: 0x060005E9 RID: 1513 RVA: 0x0004BF9C File Offset: 0x0004A19C
  154. public static string GetAkamaiCookies(this IWebDriver driver) {
  155. IJavaScriptExecutor javaScriptExecutor = (IJavaScriptExecutor) driver;
  156. string text = ((string) javaScriptExecutor.ExecuteScript("return document.cookie", new object[0])) ? ? "";
  157. if(text.Contains("~0~")) {
  158. return text;
  159. }
  160. return "";
  161. }
  162.  
  163. // Token: 0x060005EA RID: 1514 RVA: 0x0004BFE4 File Offset: 0x0004A1E4
  164. public static void TryClickRandomElement(this IWebDriver driver, IEnumerable < IWebElement > els) {
  165. try {
  166. if(els.IsAny < IWebElement > ()) {
  167. Actions actions = new Actions(driver);
  168. actions.MoveToElement(els.GetRandom < IWebElement > (), RandomHelper.RandomInt(0, 20), RandomHelper.RandomInt(0, 20)).Click().Build().Perform();
  169. }
  170. } catch (Exception) {}
  171. }
  172.  
  173. // Token: 0x060005EB RID: 1515 RVA: 0x0004C040 File Offset: 0x0004A240
  174. public static void TryRandomContextClick(this IWebDriver driver, int maxBodyOffset = 300) {
  175. try {
  176. Actions actions = new Actions(driver);
  177. actions.MoveToElement(Delegate133.smethod_0(driver, "body"), RandomHelper.RandomInt(0, maxBodyOffset), RandomHelper.RandomInt(0, maxBodyOffset)).ContextClick().SendKeys(Keys.Alt).Build().Perform();
  178. } catch (Exception) {}
  179. }
  180. }
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement