Skip to content

Instantly share code, notes, and snippets.

<script>
// JSON+LD Schema :: PDP
(function(){
var minPrice = null;
var maxPrice = null;
var isMaster = true;
var pdpData = app.pdp && app.pdp.data != undefined ? app.pdp.data : window.pageData != undefined ? window.pageData : {};
var productData = app.product && app.product.data && app.product.data.cache && app.product.data.cache[pdpData.productID] != undefined ? app.product.data.cache[pdpData.productID] : app.config && app.config.products && app.config.products[pdpData.productID] ? app.config.products[pdpData.productID] : null;
var oldObj = {
a:{value:1},
b:{value:2},
c:{value:3}
}
var newObj = {
// no a
b:{value:4}, // value change
c:{value:3},
@joelcardinal
joelcardinal / getElemOffsetFromBottom.js
Last active April 4, 2019 02:08
Get's element offset from bottom of page to bottom of given element. Useful for test automation to determine if pixel tags are pushing up your footer.
(function(){
var el = document.querySelector('.footer-wrapper'),
rect = el.getBoundingClientRect(),
scrollTopOffset = window.pageYOffset || document.documentElement.scrollTop,
offsetFromBottom = document.documentElement.scrollHeight - (rect.top + scrollTopOffset + rect.height);
return offsetFromBottom > 0;
})();
@joelcardinal
joelcardinal / smartibot_testing.js
Created March 18, 2019 15:38
Smartibot Testing
var smarti = require("Smartibot");
// why did this work with E1 when plugged into E2
var g = require("Smartibot-display").connect(smarti.E2);
var dist = require("Smartibot-distance").connect(smarti.E1);
var m1 = false;
var eyes = false;
// BTN A
setWatch(function(e) {
@joelcardinal
joelcardinal / static_site_search.html
Last active November 28, 2018 15:36
Prototype of a potential solution for search feature for static sites, where static site generator would produce a JSON file with potential search data to be used by client-side search algorithm.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>STATIC SITE SEARCH</title>
</head>
<body>
<h1>STATIC SITE SEARCH</h1>
<label for="queryz">Query:</label>
<input type="text" id="queryz" name="query" maxlength="80" size="10" autocomplete="off">
@joelcardinal
joelcardinal / before_after_prepend_append.js
Created June 18, 2018 20:57
Before, After, Prepend, Append DOM functions
(function(){
// Prepend
// put HTML string AFTER OPENING tag of another element
// (example hard to see because hidden behind promo drawer tag)
var selector = '#mainContent';
var htmlString = ''+
'<div style="text-align:center;" class="redText">'+
'<h2>Hello World - PREPEND</h2>'+
'</div>';
@joelcardinal
joelcardinal / extendXHR.js
Last active February 14, 2024 10:10
Extend XMLHttpRequest to get info of all XHR requests
(function() {
// Extend XMLHttpRequest to get info of all XHR requests
// TODO: Add Fetch extension
// https://stackoverflow.com/questions/5202296/add-a-hook-to-all-ajax-requests-on-a-page
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest#Monitoring_progress
// https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest
// https://developer.mozilla.org/en-US/docs/Web/Events/load
@joelcardinal
joelcardinal / mutationObserver.js
Created March 23, 2018 18:53
JavaScript MutationObserver Example
/*
JavaScript MutationObserver
https://caniuse.com/#feat=mutationobserver
https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
*/
@joelcardinal
joelcardinal / proxyExample.js
Created March 23, 2018 18:50
JavaScript Proxy Example
/*
JavaScript Proxy
First read this...
https://hacks.mozilla.org/2015/07/es6-in-depth-proxies-and-reflect/
Above is an old article, proxy is available, except in IE...
https://caniuse.com/proxy
@joelcardinal
joelcardinal / getSelectParams.js
Created February 2, 2018 20:29
Get Only Select Current URL Params
function getSelectParams(){
var selectParamsArr = [];
var paramsArr = window.location.search.replace('?','').split('&');
for(var i=0,len=paramsArr.length;i<len;i++){
if(/cgid=|cid=|sid=/.test(paramsArr[i]) ){
selectParamsArr.push(paramsArr[i]);
}
}
return selectParamsArr.join('&');
}