Skip to content

Instantly share code, notes, and snippets.

@m-jan
m-jan / refresh.js
Created January 25, 2022 10:30
refresh lambda
(async () => {
const https = require('https')
const BEARER_TOKEN = '9a2715843372050bafa3c118bfbd9a6a'
try {
let response = await getActiveZones()
let zones = JSON.parse(response.body)
let resZones = zones.map(z => z.name).filter(r => r.includes('captcha_buster'))
let productId = '47095835'
let apiKey = 'feaf228eb2777fd3eee0fd5192ae7107d6224b39'
console.log('performing request')
let data = await page.evaluate(async (productId, apiKey) => {
let response = await fetch(`https://carts.target.com/web_checkouts/v1/cart_items?field_groups=CART%2CCART_ITEMS%2CSUMMARY&key=${apiKey}`, {
"body": `{\"cart_item\":{\"item_channel_id\":\"10\",\"tcin\":\"${productId}\",\"quantity\":1},\"fulfillment\":{\"type\":\"PICKUP\",\"location_id\":1771,\"ship_method\":\"STORE_PICKUP\"},\"cart_type\":\"REGULAR\",\"channel_id\":\"10\",\"shopping_context\":\"DIGITAL\"}`,
"method": "POST",
"mode": "cors",
"credentials": "include",
@m-jan
m-jan / adimoevents.js
Created May 25, 2021 10:08
Adimo events
App.events = {
// the very first event that gets called as soon as the page appears, but before any
// HTTP calls are made, or any processing is done
beforeCampaignLoaded: () => { },
// called after HTTP requests are made for the Campaign data (including retailers) but before
// any page rendering is done. Use this opportunity to manipulate the "data" object
// which includes ".campaign" and ".retailers" before sending it on.
campaignLoading: (data, callback) => {
callback(data);
@m-jan
m-jan / fbpixel.js
Created May 25, 2021 10:04
Facebook pixel
App.events = {
afterCampaignLoaded: (campaign, retailers, previewCollections) => {
!function (f, b, e, v, n, t, s) {
if (f.fbq) return; n = f.fbq = function () {
n.callMethod ?
n.callMethod.apply(n, arguments) : n.queue.push(arguments)
};
if (!f._fbq) f._fbq = n; n.push = n; n.loaded = !0; n.version = '2.0';
n.queue = []; t = b.createElement(e); t.async = !0;
@m-jan
m-jan / trackingPixel.js
Created May 21, 2021 12:42
tracking pixel
function addTrackingPixel(src, h, w) {
let height = h || 1
let width = w || 1
let img = document.createElement("img");
img.width = width
img.height = height
img.src = src;
document.body.appendChild(img);
}
response = await page.evaluate(async (url) => {
let res = await fetch(url)
let data = await res.json()
return data
}, url);
@m-jan
m-jan / wtb.js
Created May 12, 2021 14:27
WTB psuedocode
urls = []
urls = getStoreUrls
(async () => {
stores = []
for (let url of urls) {
try {
const browser = await puppeteer.launch({ headless: false });
<div>
<style>
#theball {
position: absolute;
z-index: 2
}
#theball.hidden {
z-index: 0
}
@m-jan
m-jan / loadFaster.js
Created June 12, 2020 11:44
Improve script speed by only waiting until image loads
await page.goto(url, {
waitUntil: ['domcontentloaded']
})
await page.waitForFunction('.main_image', n => n.getAttribute('src').length > 0)
//Or sometimes this simpler selector is enough
await page.waitForSelector('.main_image[src]')
@m-jan
m-jan / searchProducts.js
Created May 18, 2020 11:41
search products variant example
'use strict';
const cheerio = require('cheerio');
const apiUtils = local('/lib/apiUtils');
const request = local('/lib/requestUtils');
const utils = local('/lib/utils');
const unitsParser = local('/lib/unitsParser');
const SearchResponse = local('/restApi/responses/SearchResponse');
const statusCodes = local('/lib/apiStatusCodes');