Skip to content

Instantly share code, notes, and snippets.

@dineshdeveloper1
Last active January 5, 2024 08:50
Show Gist options
  • Save dineshdeveloper1/1770f1bb31c4f842d4d59eee311ce49a to your computer and use it in GitHub Desktop.
Save dineshdeveloper1/1770f1bb31c4f842d4d59eee311ce49a to your computer and use it in GitHub Desktop.
EndlessGain Gist
const config = [
{
selector: 'body h4',
copy: 'We added the following items to basket from your previous visit.',
},
{
selector: '.classname .btn--green',
copy: 'Thank you',
},
{
selector: '.cart .btn',
copy: 'Please click here'
},
];
config.forEach(item => {
$(item.selector).html(item.copy);
});
const { Observer } = require('@egn/observer');
// template 1 ===============================================================================
new Observer($('#some-element'), () => {
//do something
}, {
attributes: true,
childList: true,
subtree: true
}).start();
// template 2 ===============================================================================
const myObserver = new Observer($('#some-element'), () => {
//do something
myObserver.stop();
},{
attributes: true,
childList: true,
subtree: true
})
$('element').on('someEvent', () => {
myObserver.start();
});
$('element').on('someEvent', () => {
myObserver.stop();
});
// template 3 ===============================================================================
const { Observer } = require('@egn/observer');
new Observer(
jQuery(".container"),
(mutationsList) => {
for (const mutation of mutationsList) {
if (mutation.type === 'childList') {
console.log("changes on container class");
}
}
},
{
childList: true,
subtree: false,
}
).start();
// add after link
?EGn_Zoltar=true
// use in javascrip code
_d.log('LTS 005');
// GA Event ============================================================
function gaEvents() {
ga("create", "UA-126062696-1", {
name: "gtmEG",
cookieDomain: "auto"
});
jQuery('.shk26_feature_button').click(function () {
ga('gtmEG.send', {
hitType: 'event',
eventCategory: 'EG_Event',
eventAction: 'View Product Button : Click',
eventLabel: 'SHK026'
})
})
}
setTimeout(function () {
gaEvents()
}, 1000)
function iOS() {
return [
'iPad Simulator',
'iPhone Simulator',
'iPod Simulator',
'iPad',
'iPhone',
'iPod'
].includes(navigator.platform)
// iPad on iOS 13 detection
|| (navigator.userAgent.includes("Mac") && "ontouchend" in document)
}
if (iOS()) {
console.log('iOS Device')
document.querySelector('#abl12_icon_option img').src = 'https://test.endlessgain.com/ABL/012/applepay.png'
}
const isMobile = /iPhone|Android/i.test(navigator.userAgent);
if(isMobile){ }
const bodyElement = document.querySelector("body");
const observer = new MutationObserver(() => {
let isProductPage = document.querySelector('.hot-ProductGallery.--pdp')
if (isProductPage) {
console.log('this is product page')
} else {
console.log('this is not product page')
}
});
observer.observe(bodyElement, {
subtree: true,
childList: true
});
==============================================================================
const observer = new MutationObserver((mutations, obs) => {
if (document.querySelector('body')) {
console.log('elements change in body')
}
});
observer.observe(document, {
childList: true,
subtree: true
});
===============================================================================
const container = document.getElementById('container')
setTimeout(() => {
const div = document.createElement('div')
div.textContent = 'hello'
div.id = 'hello'
container.appendChild(div)
}, 2000)
const observer = new MutationObserver((mutations, obs) => {
const hello = document.getElementById('hello');
if (hello) {
console.log(hello.innerText)
obs.disconnect();
return;
}
});
observer.observe(document, {
childList: true,
subtree: true
});
// js file =========
const mainHTML = require('./main.html');
document.querySelector('.class_name').insertAdjacentHTML('beforeend', mainHTML("htmlContainer"))
// html page
<!-- [htmlContainer] -->
<h1>Hello World!!</h1>
function() {
if ($('.content-container.product-list-advanced').length || $('.category-list').length || $('.pull-right.switch-layout').length) {
return true;
}
return false;
}
const {poller} = require('@egn/poller');
poller([
'window.jQuery',
], ($) => {
if ($) {
_d.log('Found jQuery')
run({});
}
})
// poller for checking element ========================
const { poller } = require('@egn/poller');
module.exports = function activation(run) {
poller([
'window.jQuery',
'.product-info,#sticky-basket > .panel',
], ($, $anchor) => {
_d.log('poller passed...', $anchor);
run({ $, $anchor });
});
};
function waitForElementToExist(selector) {
return new Promise(resolve => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(() => {
if (document.querySelector(selector)) {
resolve(document.querySelector(selector));
observer.disconnect();
}
});
observer.observe(document.body, {
subtree: true,
childList: true,
});
});
}
// 👇️ using the function
waitForElementToExist('#box').then(element => {
console.log('The element exists', element);
});
// qubit settings =====================================================================
const uv = window.universal_variable;
const pageType = uv.page.type;
const checkoutType = uv.page.checkout_step;
if (pageType == 'Checkout' && checkoutType == 'Review Order') {}
//click event --------------------------------------------
let element = document.querySelector('.classname');
element.addEventListener('click', function (event) {
event.preventDefault();
let clickEvent = new Event('click');
document.querySelector('.new_classname').dispatchEvent(clickEvent)
});
//added review script file
const newScript = document.createElement('script');
newScript.src = 'https://widget.reviews.co.uk/carousel-inline-iframeless/dist.js?_t=2023110210';
document.head.append(newScript)
//added review css file
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'https://assets.reviews.io/css/widgets/carousel-widget.css?_t=2023110210';
document.head.appendChild(link);
var link2 = document.createElement('link');
link2.rel = 'stylesheet';
link2.type = 'text/css';
link2.href = 'https://assets.reviews.io/iconfont/reviewsio-icons/style.css?_t=2023110210';
document.head.appendChild(link2);
//add html where we need to show the widget
<div id="reviewsio-carousel-widget"></div>
//add css
#reviewsio-carousel-widget{
max-width: 100%;
}
//add script after script load
newScript.onload = () => {
new carouselInlineWidget('reviewsio-carousel-widget', {
/*Your REVIEWS.io account ID:*/
store: 'abbottlyon-com',
sku: '',
lang: 'en',
carousel_type: 'default',
styles_carousel: 'CarouselWidget--sideHeader--withcards',
/*Widget settings:*/
options: {
general: {
/*What reviews should the widget display? Available options: company, product, third_party. You can choose one type or multiple separated by comma.*/
review_type: 'company, product',
/*Minimum number of reviews required for widget to be displayed*/
min_reviews: '1',
/*Maximum number of reviews to include in the carousel widget.*/
max_reviews: '20',
address_format: 'CITY, COUNTRY',
/*Carousel auto-scrolling speed. 3000 = 3 seconds. If you want to disable auto-scroll, set this value to false.*/
enable_auto_scroll: 10000,
},
header: {
/*Show overall rating stars*/
enable_overall_stars: true,
rating_decimal_places: 2,
},
reviews: {
/*Show customer name*/
enable_customer_name: true,
/*Show customer location*/
enable_customer_location: true,
/*Show "verified review" badge*/
enable_verified_badge: true,
/*Show "verified subscriber" badge*/
enable_subscriber_badge: true,
/*Show "I recommend this product" badge (Only for product reviews)*/
enable_recommends_badge: true,
/*Show photos attached to reviews*/
enable_photos: true,
/*Show videos attached to reviews*/
enable_videos: true,
/*Show when review was written*/
enable_review_date: true,
/*Hide reviews written by the same customer (This may occur when customer reviews multiple products)*/
disable_same_customer: true,
/*Minimum star rating*/
min_review_percent: 4,
/*Show 3rd party review source*/
third_party_source: true,
/*Hide reviews without comments (still shows if review has a photo)*/
hide_empty_reviews: true,
/*Show product name*/
enable_product_name: true,
/*Show only reviews which have specific tags (multiple semicolon separated tags allowed i.e tag1;tag2)*/
tags: "",
/*Show branch, only one input*/
branch: "",
enable_branch_name: false,
},
popups: {
/*Make review items clickable (When they are clicked, a popup appears with more information about a customer and review)*/
enable_review_popups: true,
/*Show "was this review helpful" buttons*/
enable_helpful_buttons: true,
/*Show how many times review was upvoted as helpful*/
enable_helpful_count: true,
/*Show share buttons*/
enable_share_buttons: true,
},
},
translations: {
verified_customer: "Verified Customer",
},
styles: {
/*Base font size is a reference size for all text elements. When base value gets changed, all TextHeading and TexBody elements get proportionally adjusted.*/
'--base-font-size': '16px',
'--base-maxwidth': '100%',
/*Logo styles:*/
'--reviewsio-logo-style': 'var(--logo-normal)',
/*Star styles:*/
'--common-star-color': '#D5B371',
'--common-star-disabled-color': ' rgba(0,0,0,0.25)',
'--medium-star-size': '24px',
'--small-star-size': '19px', /*Modal*/
'--x-small-star-size': '16px',
'--x-small-star-display': 'inline-flex',
/*Header styles:*/
'--header-order': '1',
'--header-width': '280px',
'--header-bg-start-color': '#D5B371',
'--header-bg-end-color': '#D5B371',
'--header-gradient-direction': '135deg',
'--header-padding': '1.5em',
'--header-border-width': '0px',
'--header-border-color': 'rgba(0,0,0,0.1)',
'--header-border-radius': '0px',
'--header-shadow-size': '10px',
'--header-shadow-color': 'rgba(0, 0, 0, 0.05)',
/*Header content styles:*/
'--header-star-color': '#000000',
'--header-disabled-star-color': '#000000',
'--header-heading-text-color': '#000000',
'--header-heading-font-size': '16',
'--header-heading-font-weight': 'inherit',
'--header-heading-line-height': 'inherit',
'--header-heading-text-transform': 'inherit',
'--header-subheading-text-color': '#000000',
'--header-subheading-font-size': '14',
'--header-subheading-font-weight': '300',
'--header-subheading-line-height': 'inherit',
'--header-subheading-text-transform': 'inherit',
/*Review item styles:*/
'--item-maximum-columns': '5',/*Must be 3 or larger*/
'--item-background-start-color': '#ffffff',
'--item-background-end-color': '#ffffff',
'--item-gradient-direction': '135deg',
'--item-padding': '1.5em',
'--item-border-width': '0px',
'--item-border-color': 'rgba(0,0,0,0.1)',
'--item-border-radius': '0px',
'--item-shadow-size': '10px',
'--item-shadow-color': 'rgba(0,0,0,0.05)',
/*Heading styles:*/
'--heading-text-color': ' #0E1311',
'--heading-text-font-weight': ' 600',
'--heading-text-font-family': ' inherit',
'--heading-text-line-height': ' 1.4',
'--heading-text-letter-spacing': '0',
'--heading-text-transform': 'none',
/*Body text styles:*/
'--body-text-color': ' #0E1311',
'--body-text-font-weight': '400',
'--body-text-font-family': ' inherit',
'--body-text-line-height': ' 1.4',
'--body-text-letter-spacing': '0',
'--body-text-transform': 'none',
/*Scroll button styles:*/
'--scroll-button-icon-color': '#0E1311',
'--scroll-button-icon-size': '24px',
'--scroll-button-bg-color': 'transparent',
'--scroll-button-border-width': '0px',
'--scroll-button-border-color': 'rgba(0,0,0,0.1)',
'--scroll-button-border-radius': '60px',
'--scroll-button-shadow-size': '0px',
'--scroll-button-shadow-color': 'rgba(0,0,0,0.1)',
'--scroll-button-horizontal-position': '3px',
'--scroll-button-vertical-position': '0px',
/*Badge styles:*/
'--badge-icon-color': '#D5B371',
'--badge-icon-font-size': '15px',
'--badge-text-color': '#0E1311',
'--badge-text-font-size': 'inherit',
'--badge-text-letter-spacing': 'inherit',
'--badge-text-transform': 'inherit',
/*Author styles:*/
'--author-font-size': 'inherit',
'--author-font-weight': 'inherit',
'--author-text-transform': 'inherit',
/*Product photo or review photo styles:*/
'--photo-video-thumbnail-size': '60px',
'--photo-video-thumbnail-border-radius': '0px',
/*Popup styles:*/
'--popup-backdrop-color': 'rgba(0,0,0,0.75)',
'--popup-color': '#ffffff',
'--popup-star-color': 'inherit',
'--popup-disabled-star-color': 'inherit',
'--popup-heading-text-color': 'inherit',
'--popup-body-text-color': 'inherit',
'--popup-badge-icon-color': 'inherit',
'--popup-badge-icon-font-size': '19px',
'--popup-badge-text-color': 'inherit',
'--popup-badge-text-font-size': '14px',
'--popup-border-width': '0px',
'--popup-border-color': 'rgba(0,0,0,0.1)',
'--popup-border-radius': '0px',
'--popup-shadow-size': '0px',
'--popup-shadow-color': 'rgba(0,0,0,0.1)',
'--popup-icon-color': '#0E1311',
/*Tooltip styles:*/
'--tooltip-bg-color': '#0E1311',
'--tooltip-text-color': '#ffffff',
},
});
}
const mainHTML = require('./main.html');
// Create a MutationObserver instance
const observerForPriceValue2 = new MutationObserver((mutationsList, observer) => {
for(let mutation of mutationsList) {
if (mutation.type === 'childList') {
const priceValue2Element = document.querySelector('.product-value .price.recharge-inner-most-price');
if(priceValue2Element && document.querySelector('#shopify-section-footer')) {
testInit();
observer.disconnect();
}
}
}
});
observerForPriceValue2.observe(document, { childList: true, subtree: true });
function testInit() {
document.body.classList.add('ab61')
//code
let targetElement = document.querySelector('.page-container')
$(targetElement).prepend($(mainHTML("htmlContainer")));
let div = document.createElement('div')
div.classList.add('hxh6_sestion')
div.innerHTML += `<h1>hello, world</h1>`
}
<!-- [htmlContainer] -->
<div>testing</div>
=====================================================================================================================================
=====================================================================================================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment