watsdesign

Medtronic - II

Sep 20th, 2021 (edited)
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var insertDOMIteration = 0;
  2. document.querySelector('.position-container').addEventListener('DOMNodeInserted', function (e) {
  3.     // --- Listen to .position-container.for updates ---
  4.     insertDOMIteration++;
  5.     if (insertDOMIteration === 1) {
  6.         setTimeout(function () {
  7.             var country = getCountryCookie(),
  8.                 countryTitle = document.querySelector('#job_list .content_header .jSearchSubtitle'),
  9.                 countryTitleInner = document.querySelector('.position-full-card > .row .position-location'),
  10.                 titleIsRu = countryTitle ? countryTitle.innerText.toLowerCase().includes("russian federation") : false,
  11.                 innerTitleIsRu = countryTitleInner ? countryTitleInner.innerText.toLowerCase().includes("russian federation") : false,
  12.                 cssRule = `
  13.                 .position-details>.row>div:nth-child(2){display:none !important}
  14.                 .position-details>.row>div:nth-child(1){width:100% !important}
  15.                 .primary_btn{    
  16.                     margin-right: 10px;
  17.                     background: #004b87;
  18.                     color: #fff;
  19.                     line-height: 1;
  20.                     display: inline-block;
  21.                     border-radius: 5px;
  22.                     letter-spacing: 1px;
  23.                     padding: 10px 20px;
  24.                 }
  25.                  .primary_btn:active,
  26.                  .primary_btn:focus,
  27.                  .primary_btn:hover{color:#c8eaff}`;
  28.  
  29.             console.log('---= Dr.Watson is here  210920:2222 =---');
  30.  
  31.  
  32.             if (countryTitle && titleIsRu ||
  33.                 countryTitleInner && innerTitleIsRu) {
  34.                 magicJS("RU");
  35.                 console.log('Country Source: ', (countryTitle) ? 'CountryTitle' : 'CountryTitleInner');
  36.             } else {
  37.                 if (country) {
  38.                     magicJS(country);
  39.                     console.log('Country Source: Cookies, country is:', country);
  40.                 } else {
  41.                     getCountryAjax();
  42.                     console.log('Country Source: ipGeolocation, country is:', country);
  43.                 }
  44.             }
  45.  
  46.             insertDOMIteration = 0;
  47.  
  48.             function magicJS(country) {
  49.  
  50.                 if (country == "RU") {
  51.                     addCss(cssRule);
  52.                 }
  53.                 if (country == "RU" || (countryTitle && titleIsRu)
  54.                     || (countryTitleInner && innerTitleIsRu)) {
  55.                     if (document.querySelector('#container')) document.querySelector('#container').classList.add('countryRU');
  56.                     if (document.querySelector('#header_settings_language+div')) document.querySelector('#header_settings_language+div').style.display = 'none';
  57.                     if (document.querySelector('#join_tc_btn')) document.querySelector('#join_tc_btn').style.display = 'none';
  58.                 }
  59.  
  60.                 if (countryTitleInner && (country == "RU" || innerTitleIsRu)) {
  61.                     var $applyBtn = document.querySelector('.position-apply-button'),
  62.                         requisitionTitle = document.querySelector('h1.position-title').innerText,
  63.                         requisitionID = (document.querySelector('.position-full-card .position-id-text').innerText || '').replace('ID:', '').trim(),
  64.                         backURL = encodeURIComponent(window.location.href.toString() + '#apply'),
  65.                         $applyAnchor = document.createElement('a');
  66.                     $applyAnchor.classList.add("primary_btn");
  67.                     $applyAnchor.innerHTML = $applyBtn.innerHTML;
  68.  
  69.                     $applyBtn.parentNode.insertBefore($applyAnchor, $applyBtn);
  70.                     $applyBtn.parentNode.removeChild($applyBtn);
  71.  
  72.                     $applyAnchor.href = 'https://medtronic.talentsys.ru/gateway.html?recTitle=' + requisitionTitle + '&requisition=' + requisitionID + '&redirect=' + backURL;
  73.                     // $applyAnchor.target = "_blank";
  74.                 }
  75.             }
  76.  
  77.             function getCountryAjax() {
  78.                 var _askInfo = Date.now();
  79.                 ajax('https://ipgeolocation.abstractapi.com/v1/?api_key=4f98016a1ba14957a42d89074099f781', 'get', function (obj) {
  80.                     country = obj && obj.responseText && JSON.parse(obj.responseText) ? JSON.parse(obj.responseText).country_code : 'ipInfoFail';
  81.                     console.log('currentLocation::: ', country);
  82.                     if (country && country != "ipInfoFail") {
  83.                         document.cookie = "currentCountry=" + country + "; expires=" +
  84.                             (new Date((new Date().getFullYear()) + 1, new Date().getMonth(), new Date().getDate()).toUTCString())
  85.                             + "; path=/";
  86.                     }
  87.                     magicJS(country);
  88.                     console.log("|| ipInfo timing:", (Date.now() - _askInfo).toString() + 'ms ||');
  89.                 });
  90.             }
  91.  
  92.             function getCountryCookie() {
  93.                 var out = {},
  94.                     cooks = document.cookie.split('; ');
  95.  
  96.                 cooks.forEach(function (it) {
  97.                     var el = it.replace(' ', '').split('=');
  98.                     out[el[0]] = el[1];
  99.                 });
  100.  
  101.                 //console.log('JSONed cooks', out);
  102.                 return out.currentCountry ? out.currentCountry : null;
  103.             }
  104.  
  105.             function addCss(rule) {
  106.                 let css = document.createElement('style');
  107.                 css.type = 'text/css';
  108.                 if (css.styleSheet) css.styleSheet.cssText = rule; // Support for IE
  109.                 else css.appendChild(document.createTextNode(rule)); // Support for the rest
  110.                 document.getElementsByTagName("head")[0].appendChild(css);
  111.             }
  112.  
  113.             function ajax(url, method, callback) {
  114.                 var obj, params = null;
  115.                 try {
  116.                     obj = new XMLHttpRequest();
  117.                 } catch (e) {
  118.                     try {
  119.                         obj = new ActiveXObject("Msxml2.XMLHTTP");
  120.                     } catch (e) {
  121.                         try {
  122.                             obj = new ActiveXObject("Microsoft.XMLHTTP");
  123.                         } catch (e) {
  124.                             alert("Your browser does not support Ajax.");
  125.                             return false;
  126.                         }
  127.                     }
  128.                 }
  129.                 obj.onreadystatechange = function () {
  130.                     if (obj.readyState == 4) {
  131.                         callback(obj);
  132.                     }
  133.                 };
  134.                 obj.open(method, url, true);
  135.                 obj.send(params);
  136.                 return obj;
  137.             }
  138.         }, 200)
  139.     }
  140.  
  141.  
  142. });// --- } DOM EventListener
  143.  
Add Comment
Please, Sign In to add comment