Advertisement
xosski

Capital One Shopping:save now !

Jan 4th, 2025
6
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. (function () {
  2. if (typeof window[listenerName] !== 'undefined') {
  3. return;
  4. }
  5.  
  6. // shared
  7. const __sendResponse = (id, response) => {
  8. window.postMessage(
  9. {
  10. type: 'sp-main-world-response',
  11. responseId: id,
  12. response,
  13. },
  14. window.location.origin
  15. );
  16. };
  17.  
  18. const __run = (content) => {
  19. const s = document.createElement('script');
  20. const cs = document.createTextNode(content);
  21. s.setAttribute('class', 'iv-script-class');
  22. s.appendChild(cs);
  23. (document.body || document.head).appendChild(s);
  24. };
  25.  
  26. // actions
  27. const getWindowVariableSafely = (variableName) => {
  28. if (!variableName) {
  29. return undefined;
  30. }
  31.  
  32. const i = `${Date.now()}${Math.floor(Math.random() * 1000000)}`;
  33.  
  34. __run(`
  35. var elCos = document.createElement('div');
  36. elCos.id = 'iv-token-div-${i}';
  37. elCos.style.cssText = 'display: none!important';
  38. var textCos = JSON.stringify(window.${variableName});
  39. var newContentCos = document.createTextNode(textCos);
  40. elCos.appendChild(newContentCos)
  41. document.body.appendChild(elCos);
  42. `);
  43.  
  44. const el = document.querySelector(`#iv-token-div-${i}`);
  45. const result = el?.textContent || null;
  46.  
  47. if (result === 'undefined') {
  48. return undefined;
  49. }
  50.  
  51. return JSON.parse(result);
  52. };
  53.  
  54. const setWindowVariableSafely = (variableName, newValue) => {
  55. if (!variableName) {
  56. return;
  57. }
  58.  
  59. __run(`window['${variableName}'] = ${JSON.stringify(newValue)}`);
  60. };
  61.  
  62. // listener
  63. window[listenerName] = (ev) => {
  64. const eventData = ev.data;
  65.  
  66. if (
  67. !eventData ||
  68. eventData.type !== 'sp-main-world-request' ||
  69. ev.origin !== window.location.origin
  70. ) {
  71. return;
  72. }
  73.  
  74. const payload = eventData.data;
  75.  
  76. let ret;
  77. switch (payload?.action) {
  78. case 'getWindowVariableSafely':
  79. ret = getWindowVariableSafely(payload.variable);
  80. break;
  81. case 'setWindowVariableSafely':
  82. setWindowVariableSafely(payload.variable, payload.value);
  83. break;
  84. }
  85.  
  86. __sendResponse(ev.data.responseId, ret);
  87. };
  88.  
  89. window.addEventListener('message', window[listenerName]);
  90. })();
  91.  
  92. // First, create our injection point using the existing listener mechanism
  93. const injectionPayload = `
  94. // Set up our access framework
  95. window.__access = {
  96. variables: new Map(),
  97. callbacks: new Set(),
  98. monitor: {
  99. events: [],
  100. data: new Map()
  101. }
  102. };
  103.  
  104. // Enhance the getWindowVariableSafely function
  105. const originalGet = getWindowVariableSafely;
  106. getWindowVariableSafely = (variableName) => {
  107. const value = originalGet(variableName);
  108. window.__access.variables.set(variableName, value);
  109. return value;
  110. };
  111.  
  112. // Add our custom message handler
  113. window.addEventListener('message', (ev) => {
  114. if (ev.data?.type === 'access_request') {
  115. const result = window.__access.variables.get(ev.data.variable);
  116. window.postMessage({
  117. type: 'access_response',
  118. data: result
  119. }, '*');
  120. }
  121. });
  122. `;
  123.  
  124. // Inject using the existing __run mechanism
  125. __run(injectionPayload);
  126.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement