Advertisement
watsdesign

Medtronic JS Magic

Aug 9th, 2019 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. document.addEventListener('DOMContentLoaded', function(){
  2. setTimeout(function(){
  3.  
  4.     var country = getCountryCookie(),
  5.         countryTitle = document.querySelector('#job_list .content_header .jSearchSubtitle'),
  6.         countryTitleInner = document.querySelector('.content_header .primary_location'),
  7.         cssRule = '#container.countryRU #right_holder {display:none !important}; .chzn-drop{z-index:99000000} ';
  8.  
  9.     console.log('---= Dr.Watson is here  2611:1331 =---');
  10.  
  11.     if (country) {
  12.         magicJS(country);
  13.         console.log('Country Source: Cookies, country is:', country);
  14.     } else if (countryTitle && countryTitle.innerText.toLowerCase() == "russian federation" ||
  15.         countryTitleInner && countryTitleInner.innerText.toLowerCase().includes("russian federation")) {
  16.         magicJS("RU");
  17.         console.log('Country Source: ', (countryTitle) ? 'CountryTitle' : 'CountryTitleInner');
  18.     } else {
  19.         getCountryAjax();
  20.         console.log('Country Source: ipInfo, country is:', country);
  21.     }
  22.  
  23.     if (document.querySelector('#container')) addCss(cssRule);
  24.  
  25.     function getCountryAjax() {
  26.         var _askInfo = Date.now();
  27.         ajax('https://ipinfo.io?token=42d65fdffa6d45', 'get', function (obj) {
  28.             var country = (obj && obj.responseText && JSON.parse(obj.responseText)) ? JSON.parse(obj.responseText).country : 'ipInfoFail';
  29.             console.log('currentLocation::: ', country);
  30.             if (country && country != "ipInfoFail") document.cookie = "currentCountry=" + country + "; expires=Mon, 28 Dec 2115 12:00:00 UTC; path=/";
  31.             magicJS(country);
  32.             console.log("|| ipInfo timing:", (Date.now() - _askInfo).toString() + 'ms ||');
  33.         });
  34.     }
  35.  
  36.     function magicJS(country) {
  37.  
  38.         if (country == "RU" || (countryTitle && countryTitle.innerText.toLowerCase() == "russian federation") || (countryTitleInner && countryTitleInner.innerText.toLowerCase().includes("russian federation"))) {
  39.             if (document.querySelector('#container')) document.querySelector('#container').classList.add('countryRU');
  40.         }
  41.  
  42.         if (countryTitleInner && (country == "RU" || countryTitleInner.innerText.toLowerCase().includes("russian federation"))) {
  43.             var $applyBtn = document.querySelector('[id*="apply_btn"]'),
  44.                 requisitionTitle = document.querySelector('h1.title').innerText,
  45.                 requisitionID = document.querySelector('.job_external_id .field_value').innerText,
  46.                 //backURL = 'https://medtronic.taleo.net/careersection/2/jobapply.ftl?job=' + requisitionID + '&lang=en',
  47.                 backURL = 'https://medtronic.taleo.net/careersection/2/jobapply.ftl?job=' + requisitionID,
  48.                 $applyAnchor = document.createElement('a');
  49.             $applyAnchor.classList.add("primary_btn");
  50.             $applyAnchor.innerHTML = $applyBtn.innerHTML;
  51.  
  52.             $applyBtn.parentNode.insertBefore($applyAnchor, $applyBtn);
  53.             $applyBtn.parentNode.removeChild($applyBtn);
  54.  
  55.             //backURL = window.location.href.toString();
  56.             //backURL = backURL.replace('jobs/', 'flow/');
  57.             $applyAnchor.href = encodeURI('https://medtronic.talentsys.ru/gateway.html?recTitle=' + requisitionTitle + '&requisition=' + requisitionID + '&redirect=' + backURL);
  58.             $applyAnchor.style.marginRight = '10px';
  59.             $applyAnchor.target = "_blank";
  60.         }
  61.     }
  62.  
  63.     function getCountryCookie() {
  64.         var out = {},
  65.             cooks = document.cookie.split('; ');
  66.  
  67.         cooks.forEach(function (it) {
  68.             var el = it.replace(' ', '').split('=');
  69.             out[el[0]] = el[1];
  70.         });
  71.  
  72.         //console.log('JSONed cooks', out);
  73.         return out.currentCountry ? out.currentCountry : null;
  74.     }
  75.  
  76.     function addCss(rule) {
  77.         let css = document.createElement('style');
  78.         css.type = 'text/css';
  79.         if (css.styleSheet) css.styleSheet.cssText = rule; // Support for IE
  80.         else css.appendChild(document.createTextNode(rule)); // Support for the rest
  81.         document.getElementsByTagName("head")[0].appendChild(css);
  82.     }
  83.  
  84.     function ajax(url, method, callback) {
  85.         var obj, params = null;
  86.         try {
  87.             obj = new XMLHttpRequest();
  88.         } catch (e) {
  89.             try {
  90.                 obj = new ActiveXObject("Msxml2.XMLHTTP");
  91.             } catch (e) {
  92.                 try {
  93.                     obj = new ActiveXObject("Microsoft.XMLHTTP");
  94.                 } catch (e) {
  95.                     alert("Your browser does not support Ajax.");
  96.                     return false;
  97.                 }
  98.             }
  99.         }
  100.         obj.onreadystatechange = function () {
  101.             if (obj.readyState == 4) {
  102.                 callback(obj);
  103.             }
  104.         };
  105.         obj.open(method, url, true);
  106.         obj.send(params);
  107.         return obj;
  108.     }
  109. }, 1000);
  110. }, false);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement