Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var insertDOMIteration = 0;
- document.querySelector('.position-container').addEventListener('DOMNodeInserted', function (e) {
- // --- Listen to .position-container.for updates ---
- insertDOMIteration++;
- if (insertDOMIteration === 1) {
- setTimeout(function () {
- var country = getCountryCookie(),
- countryTitle = document.querySelector('#job_list .content_header .jSearchSubtitle'),
- countryTitleInner = document.querySelector('.position-full-card > .row .position-location'),
- titleIsRu = countryTitle ? countryTitle.innerText.toLowerCase().includes("russian federation") : false,
- innerTitleIsRu = countryTitleInner ? countryTitleInner.innerText.toLowerCase().includes("russian federation") : false,
- cssRule = `
- .position-details>.row>div:nth-child(2){display:none !important}
- .position-details>.row>div:nth-child(1){width:100% !important}
- .primary_btn{
- margin-right: 10px;
- background: #004b87;
- color: #fff;
- line-height: 1;
- display: inline-block;
- border-radius: 5px;
- letter-spacing: 1px;
- padding: 10px 20px;
- }
- .primary_btn:active,
- .primary_btn:focus,
- .primary_btn:hover{color:#c8eaff}`;
- console.log('---= Dr.Watson is here 210920:2222 =---');
- if (countryTitle && titleIsRu ||
- countryTitleInner && innerTitleIsRu) {
- magicJS("RU");
- console.log('Country Source: ', (countryTitle) ? 'CountryTitle' : 'CountryTitleInner');
- } else {
- if (country) {
- magicJS(country);
- console.log('Country Source: Cookies, country is:', country);
- } else {
- getCountryAjax();
- console.log('Country Source: ipGeolocation, country is:', country);
- }
- }
- insertDOMIteration = 0;
- function magicJS(country) {
- if (country == "RU") {
- addCss(cssRule);
- }
- if (country == "RU" || (countryTitle && titleIsRu)
- || (countryTitleInner && innerTitleIsRu)) {
- if (document.querySelector('#container')) document.querySelector('#container').classList.add('countryRU');
- if (document.querySelector('#header_settings_language+div')) document.querySelector('#header_settings_language+div').style.display = 'none';
- if (document.querySelector('#join_tc_btn')) document.querySelector('#join_tc_btn').style.display = 'none';
- }
- if (countryTitleInner && (country == "RU" || innerTitleIsRu)) {
- var $applyBtn = document.querySelector('.position-apply-button'),
- requisitionTitle = document.querySelector('h1.position-title').innerText,
- requisitionID = (document.querySelector('.position-full-card .position-id-text').innerText || '').replace('ID:', '').trim(),
- backURL = encodeURIComponent(window.location.href.toString() + '#apply'),
- $applyAnchor = document.createElement('a');
- $applyAnchor.classList.add("primary_btn");
- $applyAnchor.innerHTML = $applyBtn.innerHTML;
- $applyBtn.parentNode.insertBefore($applyAnchor, $applyBtn);
- $applyBtn.parentNode.removeChild($applyBtn);
- $applyAnchor.href = 'https://medtronic.talentsys.ru/gateway.html?recTitle=' + requisitionTitle + '&requisition=' + requisitionID + '&redirect=' + backURL;
- // $applyAnchor.target = "_blank";
- }
- }
- function getCountryAjax() {
- var _askInfo = Date.now();
- ajax('https://ipgeolocation.abstractapi.com/v1/?api_key=4f98016a1ba14957a42d89074099f781', 'get', function (obj) {
- country = obj && obj.responseText && JSON.parse(obj.responseText) ? JSON.parse(obj.responseText).country_code : 'ipInfoFail';
- console.log('currentLocation::: ', country);
- if (country && country != "ipInfoFail") {
- document.cookie = "currentCountry=" + country + "; expires=" +
- (new Date((new Date().getFullYear()) + 1, new Date().getMonth(), new Date().getDate()).toUTCString())
- + "; path=/";
- }
- magicJS(country);
- console.log("|| ipInfo timing:", (Date.now() - _askInfo).toString() + 'ms ||');
- });
- }
- function getCountryCookie() {
- var out = {},
- cooks = document.cookie.split('; ');
- cooks.forEach(function (it) {
- var el = it.replace(' ', '').split('=');
- out[el[0]] = el[1];
- });
- //console.log('JSONed cooks', out);
- return out.currentCountry ? out.currentCountry : null;
- }
- function addCss(rule) {
- let css = document.createElement('style');
- css.type = 'text/css';
- if (css.styleSheet) css.styleSheet.cssText = rule; // Support for IE
- else css.appendChild(document.createTextNode(rule)); // Support for the rest
- document.getElementsByTagName("head")[0].appendChild(css);
- }
- function ajax(url, method, callback) {
- var obj, params = null;
- try {
- obj = new XMLHttpRequest();
- } catch (e) {
- try {
- obj = new ActiveXObject("Msxml2.XMLHTTP");
- } catch (e) {
- try {
- obj = new ActiveXObject("Microsoft.XMLHTTP");
- } catch (e) {
- alert("Your browser does not support Ajax.");
- return false;
- }
- }
- }
- obj.onreadystatechange = function () {
- if (obj.readyState == 4) {
- callback(obj);
- }
- };
- obj.open(method, url, true);
- obj.send(params);
- return obj;
- }
- }, 200)
- }
- });// --- } DOM EventListener
Add Comment
Please, Sign In to add comment