Created
April 26, 2021 19:39
-
-
Save lslv1243/6b9af41d6c67b11a9d51b0df5e825deb to your computer and use it in GitHub Desktop.
Apple Itunes Connect replace localized text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Script to replace localized text on the page (any element with the data-loc-key attribute) | |
*/ | |
function replaceLocalizedText(locObject) { | |
document.querySelectorAll('[data-loc-key]').forEach(function(textElement){ | |
const locKey = textElement.getAttribute('data-loc-key'); | |
textElement.innerHTML = locObject[locKey]; | |
}); | |
document.getElementById('getting-started-content').classList.remove('not-loaded'); | |
} | |
function replaceLocalizedLinks(locObject) { | |
document.querySelectorAll('[data-loc-link]').forEach(function(linkElement){ | |
const locLink = linkElement.getAttribute('data-loc-link'); | |
linkElement.setAttribute('href', locObject[locLink]); | |
}); | |
} | |
function loadLocalization () { | |
fetch('/WebObjects/iTunesConnect.woa/ra/l10n').then(function(response) { | |
return response.json(); | |
}).then(function(data){ | |
replaceLocalizedText(data.data); | |
replaceLocalizedLinks(data.data); | |
}); | |
} | |
function loadUserDetail() { | |
document.getElementById('rightgroup').style.display = 'none'; | |
fetch('/olympus/v1/session', { method: 'get', credentials: 'include' }).then(function(response) { | |
return response.json(); | |
}).then(function(data) { | |
const userDetail = data; | |
if (!userDetail.user.fullName && !userDetail.user.emailAddress) { | |
return; | |
} | |
const sessionMenuUserName = document.querySelector('.session-menu-username'); | |
const sessionMenu = ocument.getElementById('#session-menu'); | |
if (userDetail.user && userDetail.user.fullName) { | |
sessionMenuUserName.innerHTML = userDetail.user.fullName; | |
document.querySelector('.session-nav-username').innerHTML = userDetail.user.emailAddress; | |
} else if (!userDetail.user.fullName && userDetail.user.emailAddress) { | |
sessionMenuUserName.innerHTML = userDetail.user.emailAddress; | |
sessionMenuUserName.style.display = 'none'; | |
sessionMenu.classList.add('no-display-name'); | |
} | |
if (userDetail.provider && userDetail.provider.name) { | |
document.querySelector('.session-menu-providername').innerHTML = userDetail.provider.name; | |
} else { | |
sessionMenu.classList.add('no-provider-name'); | |
} | |
const rightGroup = document.getElementById('#rightgroup'); | |
rightGroup.style.transition = 'opacity 400ms'; | |
rightGroup.style.opacity = '1'; | |
}); | |
} | |
function setCopyrightYear() { | |
document.getElementById('#copyright-year').innerHTML = new Date().getFullYear(); | |
} | |
function setupEventListeners() { | |
document.getElementById('session-nav-info').addEventListener('click', function() { | |
document.getElementById('session-nav').classList.toggle('open'); | |
}); | |
document.getElementById('signoutlink').addEventListener('click', signOut); | |
} | |
function removeCookie(name) { | |
const date = new Date; | |
// set it to expire yesterday | |
date.setTime(date.getTime() - 86400000); | |
document.cookie = name + "='';path=/;expires=" + date.toUTCString(); | |
} | |
function signOut() { | |
removeCookie('wosid'); | |
removeCookie('ds01-uat'); | |
removeCookie('ds01_a'); | |
window.location.href = '/logout'; | |
} | |
setupEventListeners(); | |
loadLocalization(); | |
loadUserDetail(); | |
setCopyrightYear(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is the source code from Itunes Connect from the Getting Started screen to localize text.
It is possible to see a lot of problems in this code.
Esse é o código fonte do Itunes Connect na tela Getting Started para a localização do texto.
É possível ver vários problemas nesse código.