//<script>
(() => {
  // 1) &#1057;&#1086;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; utm_* &#1089; &#1090;&#1077;&#1082;&#1091;&#1097;&#1077;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099;
  const pageParams = new URLSearchParams(window.location.search);
  const utmEntries = [];
  for (const [k, v] of pageParams) {
    if (k.toLowerCase().startsWith('utm_') && v !== '') utmEntries.push([k, v]);
  }
  const hasUtm = utmEntries.length > 0;

  // 2) &#1053;&#1072;&#1093;&#1086;&#1076;&#1080;&#1084; &#1094;&#1077;&#1083;&#1077;&#1074;&#1099;&#1077; &#1089;&#1089;&#1099;&#1083;&#1082;&#1080; (&#1080;&#1089;&#1082;&#1083;&#1102;&#1095;&#1072;&#1103; mailto:/tel:/javascript:)
  const anchors = Array.from(document.querySelectorAll('a[href*=".dukascopy.com/rto3"]'))
    .filter(a => {
      const href = a.getAttribute('href') || '';
      return !/^(mailto:|tel:|javascript:)/i.test(href);
    });

  // 3) &#1052;&#1086;&#1076;&#1080;&#1092;&#1080;&#1094;&#1080;&#1088;&#1091;&#1077;&#1084; &#1089;&#1089;&#1099;&#1083;&#1082;&#1080;: &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1103;&#1077;&#1084; &#1080;&#1093; query &#1080; hash, &#1076;&#1086;&#1073;&#1072;&#1074;&#1083;&#1103;&#1077;&#1084; utm_* &#1080;&#1079; &#1090;&#1077;&#1082;&#1091;&#1097;&#1077;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099;
  //    (&#1087;&#1088;&#1072;&#1074;&#1080;&#1083;&#1086;: utm_* &#1080;&#1079; &#1090;&#1077;&#1082;&#1091;&#1097;&#1077;&#1081; &#1089;&#1090;&#1088;&#1072;&#1085;&#1080;&#1094;&#1099; &#1080;&#1084;&#1077;&#1102;&#1090; &#1087;&#1088;&#1080;&#1086;&#1088;&#1080;&#1090;&#1077;&#1090; &#1080; &#1087;&#1077;&#1088;&#1077;&#1079;&#1072;&#1087;&#1080;&#1089;&#1099;&#1074;&#1072;&#1102;&#1090; &#1086;&#1076;&#1085;&#1086;&#1080;&#1084;&#1105;&#1085;&#1085;&#1099;&#1077; &#1074; &#1089;&#1089;&#1099;&#1083;&#1082;&#1077;)
  const base = document.baseURI || window.location.href;
  let modified = 0;

  anchors.forEach(a => {
    // &#1056;&#1072;&#1079;&#1073;&#1080;&#1088;&#1072;&#1077;&#1084; &#1089;&#1089;&#1099;&#1083;&#1082;&#1091; &#1082;&#1086;&#1088;&#1088;&#1077;&#1082;&#1090;&#1085;&#1086; &#1076;&#1072;&#1078;&#1077; &#1077;&#1089;&#1083;&#1080; &#1086;&#1085;&#1072; &#1086;&#1090;&#1085;&#1086;&#1089;&#1080;&#1090;&#1077;&#1083;&#1100;&#1085;&#1072;&#1103;
    const url = new URL(a.getAttribute('href'), base);
    if (hasUtm) {
      const sp = url.searchParams;
      for (const [k, v] of utmEntries) sp.set(k, v);
      url.search = sp.toString(); // &#1086;&#1089;&#1090;&#1072;&#1083;&#1100;&#1085;&#1099;&#1077; &#1087;&#1072;&#1088;&#1072;&#1084;&#1077;&#1090;&#1088;&#1099; &#1089;&#1089;&#1099;&#1083;&#1082;&#1080; &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1103;&#1102;&#1090;&#1089;&#1103; &#1072;&#1074;&#1090;&#1086;&#1084;&#1072;&#1090;&#1080;&#1095;&#1077;&#1089;&#1082;&#1080;
      a.setAttribute('href', url.toString()); // hash/fragment &#1089;&#1086;&#1093;&#1088;&#1072;&#1085;&#1103;&#1077;&#1090;&#1089;&#1103; &#1086;&#1073;&#1098;&#1077;&#1082;&#1090;&#1086;&#1084; URL
      modified++;
    }
  });

  // &#1053;&#1077;&#1084;&#1085;&#1086;&#1075;&#1086; &#1090;&#1077;&#1083;&#1077;&#1084;&#1077;&#1090;&#1088;&#1080;&#1080; &#1074; &#1082;&#1086;&#1085;&#1089;&#1086;&#1083;&#1100; &#8212; &#1095;&#1090;&#1086;&#1073;&#1099; &#1073;&#1099;&#1089;&#1090;&#1088;&#1086; &#1087;&#1088;&#1086;&#1074;&#1077;&#1088;&#1080;&#1090;&#1100;, &#1095;&#1090;&#1086; &#1074;&#1089;&#1105; &#1089;&#1088;&#1072;&#1073;&#1086;&#1090;&#1072;&#1083;&#1086;
  console.log({
    hasUtm,
    utmKeys: utmEntries.map(([k]) => k),
    targetsFound: anchors.length,
    targetsModified: modified
  });
})();
