Chase offers

Automatically add chase offers

  1. // ==UserScript==
  2. // @name Chase offers
  3. // @namespace http://tampermonkey.net/
  4. // @version 2024-11-24
  5. // @description Automatically add chase offers
  6. // @author You
  7. // @match https://secure.chase.com/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=chase.com
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. // copied with minor adaptation from https://www.reddit.com/r/ChaseSapphire/comments/18pb8w5/auto_add_all_offers_to_chase_card/
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. const urlPattern = /https:\/\/secure\.chase\.com\/web\/auth\/dashboard#\/dashboard\/merchantOffers\/offer-hub\?accountId=.*/;
  18. const btnSelection = '[role="button"][tabindex="0"] > :nth-child(2)';
  19. //'.r9jbij9' manual button selection
  20.  
  21. const backFunction = () => {
  22. // shadow root back button click
  23. document.querySelectorAll(`[variant="back"]`)[0].shadowRoot.querySelectorAll(`#back-button`)[0].click()
  24. .click();
  25. // old back method
  26. // window.history.back();
  27. };
  28. const aa = () => {
  29. backFunction();
  30. setTimeout(checkUrlAndRun, Math.random() * 1000 + 300);
  31. };
  32.  
  33. let count = 1;
  34. const c = () => {
  35. try {
  36. const btns = [...document.querySelectorAll(btnSelection)]
  37. .filter(b => b.childNodes[1].childNodes[0].type !== 'ico_checkmark_filled');
  38. const b = btns.pop();
  39. if (!b) {
  40. console.log('added all!');
  41. return;
  42. }
  43. b.childNodes[0].click();
  44. updateProgress(count, btns.length);
  45. setTimeout(aa, Math.random() * 1000 + 300);
  46.  
  47. document.querySelector(btnSelection).click();
  48. } catch (e) {
  49. checkUrlAndRun();
  50. }
  51. };
  52. const updateProgress = (current, total) => {
  53. console.log(`Remaining: ${total}`);
  54. count++;
  55. };
  56.  
  57. const waitForElements = () => {
  58. const observer = new MutationObserver((mutations, observer) => {
  59. if (document.querySelectorAll(btnSelection).length > 0) {
  60. observer.disconnect();
  61. c();
  62. }
  63. });
  64.  
  65. observer.observe(document.body, { childList: true, subtree: true });
  66. };
  67.  
  68. const checkUrlAndRun = () => {
  69. if (urlPattern.test(window.location.href)) {
  70. waitForElements();
  71. }
  72. };
  73.  
  74. // Initial check
  75. checkUrlAndRun();
  76.  
  77. // Monitor URL changes
  78. let oldHref = document.location.href;
  79. const body = document.querySelector("body");
  80. const observer = new MutationObserver(mutations => {
  81. if (oldHref !== document.location.href) {
  82. oldHref = document.location.href;
  83. checkUrlAndRun();
  84. }
  85. });
  86. observer.observe(body, { childList: true, subtree: true });
  87.  
  88. })();