Advertisement
Kappapastes

Untitled

Mar 7th, 2020
2,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.76 KB | None | 0 0
  1. var ADIDAS_YS_PAYMENT_PAGE_REGEX = new RegExp("^https?://(?:www.)?(?:adidas|yeezysupply).+?/(?:delivery|payment|COShipping-Show|COSummary2-Start).*", "i");
  2. var OFFWHITE_PAYMENT_PAGE_REGEX = new RegExp("^https?://(?:www.)?off---white.com/.+?/checkout/payment.*", "i");
  3. var FOOTSITE_PAYMENT_PAGE_REGEX = new RegExp("^https?://(?:www.)?(?:footlocker|champssports|footaction|eastbay).+?/checkout.*", "i");
  4. var FOOTSITE_EU_REGEX = new RegExp("^https?://(?:www.)?(?:footlocker).+?/INTERSHOP.*", "i");
  5. var GLOBAL_E_PAGE_REGEX = new RegExp("^https?://webservices.global-e.com/Checkout/v2/.*", "i");
  6. var GOOGLE_FORM_REGEX = new RegExp("^https?://docs.google.com/forms/.*?/viewform", "i");
  7. var ADD_LISTENER = "addListener";
  8. var mutationObserver = new MutationObserver(mutationCallback);
  9. var DELAY = 25;
  10. var CARD_TYPE_MAP = new Map(); /* Thanks to https://gist.github.com/genecyber/5a13ba6a553e3995bbcc9cc2e61075fa */
  11. var AUTO_FILL_ICON = "https://i.imgur.com/dI7i9Wl.png";
  12.  
  13. CARD_TYPE_MAP.set(new RegExp("^4"), "Visa");
  14. CARD_TYPE_MAP.set(new RegExp("^5[1-5]"), "Mastercard");
  15. CARD_TYPE_MAP.set(new RegExp("^3[47]"), "American Express");
  16. CARD_TYPE_MAP.set(new RegExp("^(6011|622(12[6-9]|1[3-9][0-9]|[2-8][0-9]{2}|9[0-1][0-9]|92[0-5]|64[4-9])|65)"), "Discover");
  17. CARD_TYPE_MAP.set(new RegExp("^36"), "Diners");
  18. CARD_TYPE_MAP.set(new RegExp("^30[0-5]"), "Diners - Carte Blanche");
  19. CARD_TYPE_MAP.set(new RegExp("^35(2[89]|[3-8][0-9])"), "JCB");
  20. CARD_TYPE_MAP.set(new RegExp("^(4026|417500|4508|4844|491(3|7))"), "Visa Electron");
  21.  
  22. var booleanMapDefault = new Map();
  23. booleanMapDefault.set(ADD_LISTENER, true);
  24.  
  25. var href = getVal(window.location.href);
  26. var ref = isIframe() && document.referrer ? getVal(document.referrer) : getVal(document.location.href);
  27. var items = [];
  28. var elements = [];
  29.  
  30. function dispatchInputEvent(elem) {
  31. if (elem) {
  32. dispatchEvent(elem, EVENT_PARAMS, "input");
  33. }
  34. }
  35.  
  36. function dispatchKeydownEvent(elem) {
  37. if (elem) {
  38. dispatchEvent(elem, EVENT_PARAMS, "keydown");
  39. }
  40. }
  41.  
  42. function setSelectValue(elem, val, isNumeric) {
  43. if (elem && elem.options && val) {
  44. for (var val of val.split("/")) {
  45. for (var opt of elem.options) {
  46. value = getStringOrNumeric(val, isNumeric);
  47. if (getStringOrNumeric(opt.value, isNumeric) === value || getStringOrNumeric(opt.innerText, isNumeric) === value
  48. || (opt.getAttribute("data-code") && getStringOrNumeric(opt.getAttribute("data-code"), isNumeric) === value)) {
  49. if (opt.selected || elem.value === opt.value || elem.getAttribute("af")) {
  50. elem.setAttribute("af", true);
  51. break;
  52. } else {
  53. opt.selected = true;
  54. elem.value = opt.value;
  55. elem.setAttribute("af", true);
  56. dispatchChangeEvent(elem);
  57. return true;
  58. }
  59. }
  60. }
  61. }
  62. }
  63.  
  64. return false;
  65. }
  66.  
  67. function setValue(elem, val) {
  68. if (elem) {
  69. elem.value = val;
  70. return true;
  71. }
  72. return false;
  73. }
  74.  
  75. function getValue(elem) {
  76. if (elem) {
  77. return elem.value.trim();
  78. }
  79.  
  80. return "";
  81. }
  82.  
  83. function getValNumeric(value) {
  84. if (value) {
  85. return parseInt(value);
  86. }
  87. return NaN;
  88. }
  89.  
  90. function getStringOrNumeric(value, isNumeric) {
  91. if (isNumeric) {
  92. return getValNumeric(value);
  93. }
  94.  
  95. return getVal(value);
  96. }
  97.  
  98. function focusElement(elem) {
  99. if (elem) {
  100. elem.focus();
  101. }
  102. }
  103.  
  104. function blurElement(elem) {
  105. if (elem) {
  106. elem.blur();
  107. }
  108. }
  109.  
  110. function processInputWithDispatchEvent(elem, value, mode) {
  111. if (elem && getValue(elem).length == 0) {
  112. if (value) {
  113. focusElement(elem);
  114. if (isDefaultMode(mode)) {
  115. dispatchKeydownEvent(elem);
  116. }
  117. setValue(elem, value ? value.trim() : value);
  118. if (isDefaultMode(mode)) {
  119. dispatchChangeEvent(elem);
  120. dispatchInputEvent(elem);
  121. }
  122. blurElement(elem);
  123. }
  124. return true;
  125. }
  126. return false;
  127. }
  128.  
  129. function isDocumentInteractiveComplete() {
  130. return document.readyState === "interactive" || document.readyState === "complete";
  131. }
  132.  
  133. function validElement(elem) {
  134. return elem && isVisible(elem) && (!isElementInViewport(elem) || isShopifyCheckoutPages()) && !isDisabled(elem);
  135. }
  136.  
  137. function isVisible(elem) {
  138. return elem.offsetWidth > 0 && elem.offsetHeight > 0;
  139. }
  140.  
  141. function isDisabled(elem) {
  142. return (elem.getAttribute("disabled") && elem.getAttribute("disabled").toLowerCase() === "disabled") || elem.disabled;
  143. }
  144.  
  145. function isShopifyCheckoutPages() {
  146. if (window.location.href.toLowerCase().includes("/checkouts/")) {
  147. if (document.getElementById("shopify-digital-wallet")) {
  148. return true;
  149. }
  150.  
  151. var html = document.getElementsByTagName("html")[0];
  152. if (html) {
  153. var text = html.innerHTML.toLowerCase();
  154.  
  155. return text.includes("shopify.com") || text.includes("shopify-bag-outline") || text.includes("window.shopifybuy");
  156. }
  157. }
  158.  
  159. return false;
  160. }
  161.  
  162. function isElementInViewport(elem) {
  163. /** Credit to http://jsfiddle.net/cferdinandi/b13ctvd7/ */
  164. var bounding = elem.getBoundingClientRect();
  165. var out = {};
  166. out.top = Math.trunc(bounding.top) < 0;
  167. out.left = Math.trunc(bounding.left) < 0;
  168. out.bottom = Math.trunc(bounding.bottom) > (Math.trunc(window.innerHeight) || Math.trunc(document.documentElement.clientHeight));
  169. out.right = Math.trunc(bounding.right) > (Math.trunc(window.innerWidth) || Math.trunc(document.documentElement.clientWidth));
  170. out.any = out.top || out.left || out.bottom || out.right;
  171.  
  172. return out.any;
  173. }
  174.  
  175. /** accepts excluded sites list paramter **/
  176. function isIncludedSite(excludedSites) {
  177. if (excludedSites) {
  178. var sites = excludedSites.toLowerCase().split(",");
  179. if (sites && sites.length > 0) {
  180. var referrer = isIframe() && document.referrer ? document.referrer.toLowerCase() : document.location.href;
  181. for (var site of sites) {
  182. site = getVal(site);
  183. if (site === "") {
  184. continue;
  185. }
  186. if (referrer.includes(site)) {
  187. return false;
  188. }
  189. }
  190. }
  191. }
  192.  
  193. return true;
  194. }
  195.  
  196. function isIframe () {
  197. try {
  198. return window.self !== window.top;
  199. } catch (e) {
  200. return true;
  201. }
  202. }
  203.  
  204. function processName(regex, name, elem, value, mode) {
  205. if (name.match(regex)) {
  206. return processInputWithDispatchEvent(elem, value, mode);
  207. }
  208. return false;
  209. }
  210.  
  211. function processNameSelect(regex, name, elem, value, isNumeric) {
  212. if (name.match(regex)) {
  213. return setSelectValue(elem, value, isNumeric);
  214. }
  215. return false;
  216. }
  217.  
  218. function processAc(ac, attribute, elem, value, mode) {
  219. if (ac === attribute || ac.includes(attribute)) {
  220. return processInputWithDispatchEvent(elem, value, mode);
  221. }
  222. return false;
  223. }
  224.  
  225. function processAcSelect(ac, attribute, elem, value) {
  226. if (ac === attribute || ac.includes(attribute)) {
  227. return setSelectValue(elem, value, false);
  228. }
  229. return false;
  230. }
  231.  
  232. function getSelectName(input) {
  233. var attr = getAttr(input, "data-auto-id");
  234. if (attr) {
  235. return attr;
  236. }
  237.  
  238. var parent = input.parentElement;
  239. if (parent) {
  240. attr = getAttr(parent, "data-auto-id");
  241. if (attr) {
  242. return attr;
  243. }
  244. }
  245.  
  246. var name = getVal(input.name);
  247.  
  248. if (name) {
  249. return name;
  250. }
  251.  
  252. return null;
  253. }
  254.  
  255. function processAcNameAndEmail(ac, input, email, address, mode) {
  256. return processAc(ac, "email", input, email, mode) ||
  257. processAc(ac, "given-name", input, address.fName, mode) ||
  258. processAc(ac, "family-name", input, address.lName, mode) ||
  259. processAc(ac, "name", input, address.fName + " " + address.lName, mode) ||
  260. processAc(ac, "cc-name", input, address.fName + " " + address.lName, mode);
  261. }
  262.  
  263. function processAcCard(ac, input, card, mode) {
  264. return processAc(ac, "cc-number", input, card.number, mode) ||
  265. processAc(ac, "cc-exp-month", input, card.expMonth, mode) ||
  266. processAc(ac, "cc-exp-year", input, card.expYear, mode) ||
  267. processAc(ac, "cc-exp", input, card.expMonth + " / " + card.expYear.substring(2,4), mode) ||
  268. processAc(ac, "cc-csc", input, card.cvv, mode);
  269. }
  270.  
  271. function processRegexNameAndEmail(name, input, result, address, mode) {
  272. return processName(REGEX_NAME_FULL_NAME, name, input, address.fName + " " + address.lName, mode) ||
  273. processName(REGEX_NAME_FIRST_NAME, name, input, address.fName, mode) ||
  274. processName(REGEX_NAME_LAST_NAME, name, input, address.lName, mode) ||
  275. processName(REGEX_NAME_EMAIL, name, input, result.data.profile.email, mode) ||
  276. processName(REGEX_NAME_CARD_NAME, name, input, address.fName + " " + address.lName, mode) ||
  277. processName(REGEX_NAME_DISCORD_TAG, name, input, result.data.discord, mode) ||
  278. processName(REGEX_NAME_TWITTER_HANDLE, name, input, result.data.twitter, mode);
  279. }
  280.  
  281. function processRegexCard(name, input, card, mode) {
  282. return processName(REGEX_NAME_CARD_NUMBER, name, input, card.number, mode) ||
  283. processName(REGEX_NAME_CARD_EXP_MONTH, name, input, card.expMonth, mode) ||
  284. processName(REGEX_NAME_CARD_EXP_YEAR, name, input, card.expYear, mode) ||
  285. processName(REGEX_NAME_CARD_EXP_DATE, name, input, card.expMonth + card.expYear.substring(2,4), mode) ||
  286. processName(REGEX_NAME_CARD_EXP_DATE_MMYY, name, input, card.expMonth + "/" + card.expYear.substring(2,4), mode) ||
  287. processName(REGEX_NAME_CARD_EXP_DATE_MM, name, input, card.expMonth, mode) ||
  288. processName(REGEX_NAME_CARD_EXP_DATE_YY, name, input, card.expYear.substring(2,4), mode) ||
  289. processName(REGEX_NAME_CARD_EXP_DATE_YYYY, name, input, card.expYear, mode) ||
  290. processName(REGEX_NAME_CARD_CVV, name, input, card.cvv, mode);
  291. }
  292.  
  293. function processRegexCheckbox(name, input) {
  294. return processCheckboxOrRadio(REGEX_NAME_CHECKBOX, name, input);
  295. }
  296.  
  297. function processCheckboxOrRadio(regex, name, input) {
  298. if (input && (getVal(input.type) === "checkbox" || getVal(input.type) === "radio")) {
  299. if (input.checked) {
  300. return true;
  301. } else if (name.match(regex) || getAttr(input, "data-auto-id").match(regex)) {
  302. if (input.nextElementSibling && getVal(input.nextElementSibling.tagName) === "ins") {
  303. input.nextElementSibling.click();
  304. } else {
  305. input.click();
  306. input.checked = true;
  307. }
  308. return true;
  309. }
  310. }
  311.  
  312. return false;
  313. }
  314.  
  315. function getCardType(number) {
  316. for (const [key, value] of CARD_TYPE_MAP) {
  317. if (number.match(key)) {
  318. return value;
  319. }
  320. }
  321.  
  322. return "";
  323. }
  324.  
  325. function getLabelText(input) {
  326. var id = input.id;
  327. if (id) {
  328. var label = document.querySelector("label[for='" + id + "']");
  329. if (label) {
  330. return getVal(label.innerText);
  331. }
  332. }
  333.  
  334. var parent = input.parentElement;
  335. if (parent) {
  336. if (parent.tagName.toLowerCase() === "label") {
  337. return getVal(parent.innerText);
  338. }
  339.  
  340. var previous = parent.previousElementSibling;
  341. if (previous && previous.tagName.toLowerCase() === "label") {
  342. return getVal(previous.innerText);
  343. }
  344. }
  345.  
  346. return "";
  347. }
  348.  
  349. function getAddress(name, result) {
  350. var address = result.data.profile.bill;
  351. if (result.data.profile.ship && name.includes("ship")) {
  352. address = result.data.profile.ship;
  353. }
  354.  
  355. return address;
  356. }
  357.  
  358. function getAttr(input, attr) {
  359. var attribute = "";
  360. if (input) {
  361. attribute = getVal(input.getAttribute(attr));
  362. }
  363.  
  364. return attribute;
  365. }
  366.  
  367. function isDefaultMode(mode) {
  368. return mode === undefined || mode === "1"
  369. }
  370.  
  371. chrome.extension.sendMessage({msgType: "data"}, result => {
  372. if (result.data && result.data.profile && isIncludedSite(result.data.excludedSites)) {
  373. setInterval(function() {
  374. processAIO(result);
  375. },
  376. DELAY
  377. );
  378. }
  379. });
  380.  
  381. function processAIO(result) {
  382. if (isDocumentInteractiveComplete()) {
  383. process(result);
  384. }
  385. }
  386.  
  387. function process(result) {
  388. processInputAIO(result, "input");
  389. processInputAIO(result, "textarea");
  390. processSelect(result);
  391. }
  392.  
  393. function addListeners(result) {
  394. if (booleanMapDefault.get(ADD_LISTENER)) {
  395. for (var input of document.getElementsByTagName("input")) {
  396. input.addEventListener("focus", function(evt) {
  397. focusEvent(evt, result);
  398. });
  399. mutationObserver.observe(input, {attributes: true});
  400. booleanMapDefault.set(ADD_LISTENER, false);
  401. }
  402.  
  403. for (var input of document.getElementsByTagName("textarea")) {
  404. input.addEventListener("focus", function(evt) {
  405. focusEvent(evt, result);
  406. });
  407. mutationObserver.observe(input, {attributes: true});
  408. booleanMapDefault.set(ADD_LISTENER, false);
  409. }
  410. }
  411. }
  412.  
  413. function focusEvent(evt, result) {
  414. processSingleInput(evt.target, result);
  415. }
  416.  
  417. function processRegex(name, input, result) {
  418. if (name === undefined || name === null || name === "") {
  419. return false;
  420. }
  421.  
  422. var address = getAddress(name, result);
  423. var mode = getMode(result.data.mode);
  424.  
  425. return processRegexNameAndEmail(name, input, result, address, mode) ||
  426. processName(REGEX_NAME_ADDRESS_2, name, input, address.address2, mode) ||
  427. processName(REGEX_NAME_ADDRESS_1, name, input, address.address1, mode) ||
  428. processName(REGEX_NAME_CITY, name, input, address.city, mode) ||
  429. processName(REGEX_NAME_STATE, name, input, address.province ? address.province.split("/")[0] : "", mode) ||
  430. processName(REGEX_NAME_ZIP, name, input, address.zip, mode) ||
  431. processName(REGEX_NAME_PHONE, name, input, address.phone, mode) ||
  432. processName(REGEX_NAME_DISCOUNT_CODE, name, input, result.data.discount, mode) ||
  433. processRegexCard(name, input, result.data.profile.card, mode) ||
  434. processRegexCheckbox(name, input) ||
  435. processRegexCard(name, input, result.data.profile.card, mode) ||
  436. processRegexDIY(name, input, result, mode) ||
  437. (isShopifyCheckoutPages() && result.data.profile.ship && processCheckboxOrRadio(REGEX_NAME_DIFFERENT_BILLING_ADDRESS, name, input));
  438. }
  439.  
  440. function processRegexDIY(name, elem, result, mode) {
  441. if (result.data.diy) {
  442. for (var diy of result.data.diy) {
  443. if (matchKeyword(name, diy.keyword)) {
  444. return processInputWithDispatchEvent(elem, diy.answer, mode);
  445. }
  446. }
  447. }
  448. return false;
  449. }
  450.  
  451. function processMath(regex, name, input, mode) {
  452. var m = name.replace(/\s/, "").match(regex);
  453.  
  454. if (m) {
  455. try {
  456. var val = eval(m[0].replace(/x/, "*").replace(/\[/, "(").replace(/\]/, ")").replace(/\{/, "(").replace(/\}/, ")").replace(/\=/, "").replace(/\?/, ""));
  457. if (val) {
  458. return processInputWithDispatchEvent(input, getVal(new String(val)), mode);
  459. }
  460. } catch (e) {
  461. // do nothing
  462. }
  463. }
  464.  
  465. return false;
  466. }
  467.  
  468. function matchKeyword(title, keywords) {
  469. if (title) {
  470. for (var group of keywords) {
  471. var isMatch = true;
  472. for (var keyword of group) {
  473. if (keyword.startsWith("-")) {
  474. if (title.toLowerCase().includes(keyword.replace("-", ""))) {
  475. isMatch = false;
  476. break;
  477. }
  478. continue;
  479. }
  480.  
  481. if (!title.toLowerCase().includes(keyword)) {
  482. isMatch = false;
  483. break;
  484. }
  485. }
  486.  
  487. if (isMatch) {
  488. return true;
  489. }
  490. }
  491.  
  492. return false;
  493. }
  494.  
  495. return true;
  496. }
  497.  
  498. function processRegexSelect(name, input, result) {
  499. if (name === undefined || name === null || name === "") {
  500. return false;
  501. }
  502.  
  503. var address = getAddress(name, result);
  504.  
  505. return processNameSelect(REGEX_NAME_STATE, name, input, address.province, false) ||
  506. processNameSelect(REGEX_NAME_COUNTRY, name, input, address.country, false) ||
  507. processNameSelect(REGEX_NAME_CARD_EXP_MONTH, name, input, result.data.profile.card.expMonth, true) ||
  508. processNameSelect(REGEX_NAME_CARD_EXP_YEAR, name, input, result.data.profile.card.expYear, true) ||
  509. processNameSelect(REGEX_NAME_CARD_EXP_YEAR, name, input, result.data.profile.card.expYear.substring(2,4), true) ||
  510. processNameSelect(REGEX_NAME_CARD_TYPE, name, input, getCardType(result.data.profile.card.number), false);
  511. }
  512.  
  513. function processInputAIO(result, tagName) {
  514. for (var input of document.getElementsByTagName(tagName)) {
  515. processSingleInput(input, result);
  516. }
  517. }
  518.  
  519. function processSingleInput(input, result) {
  520. if (validElement(input) || href.includes("pci-connect.square")) {
  521. if (elements.includes(input)) {
  522. return;
  523. }
  524.  
  525. if (processRegex(getAttr(input, "data-auto-id"), input, result)) {
  526. postProcess(input);
  527. return;
  528. }
  529.  
  530. var ac = getVal(input.getAttribute("autocomplete"));
  531. if (ac) {
  532. var address = getAddress(ac, result);
  533. var mode = getMode(result.data.mode);
  534.  
  535. if (processAcNameAndEmail(ac, input, result.data.profile.email, address, mode) ||
  536. processAc(ac, "street-address", input, address.address1 + " " + address.address2, mode) ||
  537. processAc(ac, "address-line1", input, address.address1, mode) ||
  538. processAc(ac, "address-line2", input, address.address2, mode) ||
  539. processAc(ac, "country", input, address.country, mode) ||
  540. processAc(ac, "address-level1", input, address.province, mode) ||
  541. processAc(ac, "address-level2", input, address.city, mode) ||
  542. processAc(ac, "postal-code", input, address.zip, mode) ||
  543. processAc(ac, "tel", input, address.phone, mode) ||
  544. processAcCard(ac, input, result.data.profile.card, mode)) {
  545. postProcess(input);
  546. return;
  547. }
  548. }
  549.  
  550. if (processRegex(getLabelText(input), input, result)) {
  551. postProcess(input);
  552. return;
  553. }
  554.  
  555. if (processRegex(getVal(input.name), input, result)) {
  556. postProcess(input);
  557. return;
  558. }
  559.  
  560. if (processRegex(getValCustomSite(input.placeholder), input, result)) {
  561. postProcess(input);
  562. return;
  563. }
  564.  
  565. if (processRegex(getVal(input.id), input, result) || processRegex(input.getAttribute("data-checkout"), input, result) || processMath(REGEX_MATH, getLabelText(input), input, mode)) {
  566. postProcess(input);
  567. return;
  568. }
  569.  
  570. var text = decodeHTML(input.getAttribute("aria-label"));
  571. if (href.includes("docs.google.com/forms") && (processRegex(text, input, result) || processMath(REGEX_MATH, text, input, mode))) {
  572. postProcess(input);
  573. return;
  574. }
  575. }
  576. }
  577.  
  578. function processSelect(result) {
  579. for (var input of document.getElementsByTagName("select")) {
  580. if (validElement(input) || href.includes("pci-connect.square")) {
  581. if (elements.includes(input)) {
  582. continue;
  583. }
  584.  
  585. if (processRegexSelect(getSelectName(input), input, result)) {
  586. postProcess(input);
  587. continue;
  588. }
  589.  
  590. var ac = getVal(input.getAttribute("autocomplete"));
  591. if (ac) {
  592. var address = result.data.profile.bill;
  593. if (result.data.profile.ship && ac.includes("shipping")) {
  594. address = result.data.profile.ship;
  595. }
  596.  
  597. if (processAcSelect(ac, "country", input, address.country) ||
  598. processAcSelect(ac, "address-level1", input, address.province)) {
  599. postProcess(input);
  600. continue;
  601. }
  602. }
  603.  
  604. if (processRegexSelect(getLabelText(input), input, result)) {
  605. postProcess(input);
  606. continue;
  607. }
  608.  
  609. if (processRegexSelect(getVal(input.id), input, result)) {
  610. postProcess(input);
  611. continue;
  612. }
  613. }
  614. }
  615. }
  616.  
  617. function postProcess(input) {
  618. elements.push(input);
  619. if (items.length == 0) {
  620. var url = null;
  621. href = getVal(window.location.href);
  622.  
  623. if (isShopifyCheckoutPages()) {
  624. var products = document.getElementsByClassName("product__image");
  625. if (products) {
  626. for (var product of products) {
  627. var image = product.getElementsByTagName("img")[0];
  628. if (image) {
  629. items.push({"src": image.src, "alt": image.getAttribute("alt")});
  630. }
  631. }
  632. sendItems(items, url);
  633. }
  634. return;
  635. }
  636.  
  637. if (href.includes("checkout.bigcartel.com")) {
  638. var products = document.getElementsByClassName("product");
  639. if (products) {
  640. for (var product of products) {
  641. items.push({"src": AUTO_FILL_ICON, "alt": getVal(product.innerText)});
  642. }
  643.  
  644. var sf = document.getElementsByName("storefront")[0];
  645. var a = document.getElementsByTagName("a")[0];
  646.  
  647. url = sf ? sf.content : (a ? a.href : "https://checkout.bigcartel.com/")
  648. sendItems(items, url);
  649. }
  650. return;
  651. }
  652.  
  653. if (href.match(ADIDAS_YS_PAYMENT_PAGE_REGEX)) {
  654. var products = document.getElementsByClassName("line_item___1coA5") && document.getElementsByClassName("line_item___1coA5").length > 0 ? document.getElementsByClassName("line_item___1coA5") : document.getElementsByClassName("line-item");
  655. if (products) {
  656. for (var product of products) {
  657. var image = product.getElementsByTagName("img")[0];
  658. if (image) {
  659. var alt;
  660. try {
  661. alt = product.innerText.split("\n").slice(0,3).join("\n");
  662. } catch (e) {
  663. alt = img.alt;
  664. }
  665. items.push({"src": image.src, "alt": alt});
  666. }
  667. }
  668. }
  669. sendItems(items, url);
  670. return;
  671. }
  672.  
  673. if (href.match(OFFWHITE_PAYMENT_PAGE_REGEX)) {
  674. var products = document.getElementsByClassName("cart-items-image");
  675. if (products) {
  676. for (var product of products) {
  677. var image = product.getElementsByTagName("img")[0];
  678. if (image) {
  679. items.push({"src": image.src, "alt": image.getAttribute("alt")});
  680. }
  681. }
  682. }
  683. sendItems(items, url);
  684. return;
  685. }
  686.  
  687. if (href.match(FOOTSITE_PAYMENT_PAGE_REGEX)) {
  688. var products = document.getElementsByClassName("FulfillmentProducts-product");
  689. if (products) {
  690. for (var product of products) {
  691. var image = product.getElementsByTagName("img")[0];
  692. if (image) {
  693. items.push({"src": image.src, "alt": product.innerText});
  694. }
  695. }
  696. }
  697. sendItems(items, url);
  698. return;
  699. }
  700.  
  701. if (href.match(FOOTSITE_EU_REGEX)) {
  702. var products = document.getElementsByClassName("fl-cart-summary--list--item");
  703. if (products) {
  704. for (var product of products) {
  705. var image = product.getElementsByTagName("img")[0];
  706. if (image && image.src.startsWith("http")) {
  707. var alt;
  708. try {
  709. alt = product.innerText.split("\n").slice(1,5).join("\n");
  710. } catch (e) {
  711. alt = img.alt;
  712. }
  713. items.push({"src": image.src, "alt": alt});
  714. }
  715. }
  716. }
  717. sendItems(items, url);
  718. return;
  719. }
  720.  
  721. if (href.match(GLOBAL_E_PAGE_REGEX)) {
  722. url = getGlobalEMerchant();
  723. items.push({"src": "", "alt": ""});
  724. sendItems(items, url);
  725. return;
  726. }
  727.  
  728. if (href.includes("supremenewyork.com/checkout") || href.match(GOOGLE_FORM_REGEX)) {
  729. items.push({"src": "", "alt": ""});
  730. sendItems(items, url);
  731. return;
  732. }
  733.  
  734. if (href.includes("js.stripe.com/v3/elements-inner-card")) {
  735. items.push({"src": "", "alt": ""});
  736. chrome.extension.sendMessage({
  737. msgType: "items",
  738. url: document.referrer
  739. });
  740. return;
  741. }
  742. }
  743. }
  744.  
  745. function sendItems(items, url) {
  746. if (items.length > 0) {
  747. chrome.extension.sendMessage({
  748. msgType: "items",
  749. items: items,
  750. url: url
  751. });
  752. }
  753. }
  754.  
  755. function getValCustomSite(val) {
  756. if (val === "number" && href.includes("supremenewyork.com")) {
  757. return "card number";
  758. }
  759.  
  760. return getVal(val);
  761. }
  762.  
  763. function mutationCallback(mutationsList) {
  764. mutationsList.forEach(mutation => {
  765. if (mutation.attributeName === "class") {
  766. var target = mutation.target;
  767. if (target && getVal(target.className).includes("invalid")) {
  768. focusElement(target);
  769. }
  770. }
  771. });
  772. }
  773.  
  774. function decodeHTML(text) {
  775. var textArea = document.createElement("textarea");
  776. textArea.innerHTML = text;
  777. return textArea.value;
  778. }
  779.  
  780. function getMode(mode) {
  781. if (ref.includes("cybersole.io")) {
  782. return "2";
  783. }
  784.  
  785. return mode;
  786. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement