Advertisement
Guest User

Untitled

a guest
Jan 27th, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. class PRICING_MODE_ON {
  2. element(element) {
  3. if (element.tagName === "body") {
  4. 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>';
  5. element.append(html, { html: true });
  6. }
  7. }
  8. }
  9.  
  10. class NOT_US_CA {
  11. element(element) {
  12. if (element.tagName === "body") {
  13. const html = '<style type="text/css">#column-international-buttons{text-align:center}#hide-international{display:none!important}</style>';
  14. element.append(html, { html: true });
  15. }
  16. }
  17. }
  18.  
  19. class US_CA {
  20. element(element) {
  21. if (element.tagName === "body") {
  22. const html = '<style type="text/css">#hide-usca{display:none!important}</style>';
  23. element.append(html, { html: true });
  24. }
  25. }
  26. }
  27.  
  28. export default {
  29. async fetch(req, env, ctx) {
  30. ctx.passThroughOnException();
  31.  
  32. const cookies = req.headers.get("Cookie") || "";
  33. const country = req.cf.country;
  34.  
  35. const northAmerica = country == "US" || country == "CA"
  36.  
  37. let response = await fetch(req);
  38. response = new Response(response.body, response);
  39.  
  40. const url = new URL(req.url);
  41.  
  42. if (
  43. url.search.includes("gclid") ||
  44. url.search.includes("bing") ||
  45. url.search.includes("fbclid") ||
  46. url.pathname.includes("pricing")
  47. ) {
  48. response.headers.set(
  49. "Set-Cookie",
  50. "pricing-mode=on;max-age=604800;Path=/"
  51. );
  52. return response;
  53. }
  54.  
  55. let html = new HTMLRewriter();
  56.  
  57. if (northAmerica) {
  58. const contentType = response.headers.get("Content-Type") || "";
  59. if (!contentType.startsWith("text/html")) {
  60. return response;
  61. }
  62.  
  63. html.on("body", new US_CA());
  64. }
  65.  
  66. if (!northAmerica) {
  67. const contentType = response.headers.get("Content-Type") || "";
  68. if (!contentType.startsWith("text/html")) {
  69. return response;
  70. }
  71.  
  72. html.on("body", new NOT_US_CA());
  73. }
  74.  
  75. if (cookies.includes("pricing-mode=on")) {
  76. const contentType = response.headers.get("Content-Type") || "";
  77. if (!contentType.startsWith("text/html")) {
  78. return response;
  79. }
  80.  
  81. html.on("body", new PRICING_MODE_ON());
  82. }
  83.  
  84. return html.transform(response);
  85. },
  86. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement