Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class PRICING_MODE_ON {
- element(element) {
- if (element.tagName === "body") {
- const html = '<style type="text/css">.cart-item, .ht-notification-section, .wcct_footer_area, .postid-46227 .pewc-total-field-wrapper, .postid-46501 .pewc-total-field-wrapper, .price,.price-wrapper,.single_add_to_cart_button,.quantity,#welcome-notice, .wcct_custom_text_wrap, .wcct_countdown_timer_wrap, .badge-container, .wcct_custom_text_wrap, .wcct_timer_wrap, #hide-catalog, #wcpay-payment-request-wrapper, #wcpay-payment-request-button-separator, #menu-item-64460, #menu-item-64457, .message__container locale--US, .wmc-list-currencies {display: block!important} #show-catalog {visibility: hidden!important;}#pewc-per-product-label, #pewc-per-product-total, #pewc-grand-total-label, #pewc-grand-total, #pewc-group-64059, #pewc-group-64060, #price-match, .saletg {display: inline!important;} .header-bottom, #menu-item-76425, #menu-item-76493 {display:none;} </style>';
- element.append(html, { html: true });
- }
- }
- }
- class NOT_US_CA {
- element(element) {
- if (element.tagName === "body") {
- const html = '<style type="text/css">#column-international-buttons{text-align:center}#hide-international{display:none!important}</style>';
- element.append(html, { html: true });
- }
- }
- }
- class US_CA {
- element(element) {
- if (element.tagName === "body") {
- const html = '<style type="text/css">#hide-usca{display:none!important}</style>';
- element.append(html, { html: true });
- }
- }
- }
- export default {
- async fetch(req, env, ctx) {
- ctx.passThroughOnException();
- const cookies = req.headers.get("Cookie") || "";
- const country = req.cf.country;
- const northAmerica = country == "US" || country == "CA"
- let response = await fetch(req);
- response = new Response(response.body, response);
- const url = new URL(req.url);
- if (
- url.search.includes("gclid") ||
- url.search.includes("bing") ||
- url.search.includes("fbclid") ||
- url.pathname.includes("pricing")
- ) {
- response.headers.set(
- "Set-Cookie",
- "pricing-mode=on;max-age=604800;Path=/"
- );
- return response;
- }
- let html = new HTMLRewriter();
- if (northAmerica) {
- const contentType = response.headers.get("Content-Type") || "";
- if (!contentType.startsWith("text/html")) {
- return response;
- }
- html.on("body", new US_CA());
- }
- if (!northAmerica) {
- const contentType = response.headers.get("Content-Type") || "";
- if (!contentType.startsWith("text/html")) {
- return response;
- }
- html.on("body", new NOT_US_CA());
- }
- if (cookies.includes("pricing-mode=on")) {
- const contentType = response.headers.get("Content-Type") || "";
- if (!contentType.startsWith("text/html")) {
- return response;
- }
- html.on("body", new PRICING_MODE_ON());
- }
- return html.transform(response);
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement