Extract Session from CityIndex iFrame

Extracts the session parameter from the iFrame URL and copies it to the clipboard

  1. // ==UserScript==
  2. // @name Extract Session from CityIndex iFrame
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.0
  5. // @description Extracts the session parameter from the iFrame URL and copies it to the clipboard
  6. // @match https://www.cityindex.com/*/forex-trading/*/
  7. // @license MIT
  8. // @grant GM_setClipboard
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function extractSession() {
  15. const iframe = document.getElementsByTagName("iframe")[0];
  16. if (!iframe) {
  17. console.log("No iframe found.");
  18. return;
  19. }
  20.  
  21. const url = new URL(iframe.src);
  22. const session = url.searchParams.get("session");
  23.  
  24. if (session) {
  25. GM_setClipboard(session);
  26. console.log("Session copied to clipboard:", session);
  27. } else {
  28. console.log("Session parameter not found.");
  29. }
  30. }
  31.  
  32. // Wait for the iframe to load
  33. window.addEventListener('load', () => {
  34. setTimeout(extractSession, 3000); // Wait a bit to ensure the iframe is loaded
  35. });
  36. })();