NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @version 0.ç // @name Updated phone tool // @namespace http://amazon.com // @description Updated phone tool - supporting the new redesigned phone tool (Dec 14th, 2019) // @include https://phonetool.amazon.com/people/* // @include https://phonetool.amazon.com/users/* // @run-at document-end // @require https://code.jquery.com/jquery-3.2.1.min.js // @grant GM.xmlHttpRequest // @license MIT // @grant GM_xmlhttpRequest // ==/UserScript== SELECT LEFT(RIGHT(link, LEN(link) - CHARINDEX('//', link) - 1), CHARINDEX('.', RIGHT(link, LEN(link) - CHARINDEX('//', link) - 1)) - 1) AS domain FROM (SELECT 'https://ot28084.east-us-2.azure.snowflakecomputing.com/' AS link) AS urls; /* REVISION HISTORY: 0.7 - 2018-01-08 - lepine@ - Fix information for non-blue-badges 0.8 - 2018-03-23 - lepine@ - Change way to get user information from url and regex to react JSON data 0.9 - 2019-09-16 - lepine@ - Add manager name and alias to the user's information, and avoid duplicating Hire Date */ 'use strict'; (function() { function GetUserInfoUri(login) { return "https://phonetool.amazon.com/users/" + encodeURIComponent(login) + ".json"; } function getReadableDate(when) { try { const year = when.getUTCFullYear(); const month = when.getUTCMonth(); const day = when.getUTCDate(); const weekday = when.getUTCDay(); let result = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ][weekday] + ", "; result += [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" ][month] + " "; result += day; if(day >= 10 && day <= 20) { result += "th"; } else if((day % 10) == 1) { result += "st"; } else if((day % 10) == 2) { result += "nd"; } else if((day % 10) == 3) { result += "rd"; } else { result += "th"; } result += ", " + year; return result; } catch(e) { console.error("Unable to format date", dateStr, e); return "now"; } } function displayEmpInfo() { const loadTenure = $(".UserDetailsTable .TenureRow").length === 0; const loadHireDate = $(".UserDetailsTable .HireDateRow").length === 0; const props = $('<span class="optional-wrapper"></span>'); if(loadHireDate) { props.append('<div class="TableRow HireDateRow"><div class="TableProperty">Hire date:</div><div class="TableValue">Loading...</div></div>'); } if(loadTenure) { props.append('<div class="TableRow TenureRow"><div class="TableProperty">Tenure:</div><div class="TableValue">Loading...</div></div>'); } props.append('<div class="TableRow ManagerRow"><div class="TableProperty">Manager:</div><div class="TableValue"><span>Loading...</span> (<a href="#">Loading...</a>)</div></div>'); props.append('<div class="TableRow LevelRow"><div class="TableProperty">Level:</div><div class="TableValue">Loading...</div></div>'); props.append('<div class="TableRow BarRaiserRow"><div class="TableProperty">Bar raiser:</div><div class="TableValue">Loading...</div></div>'); $(".UserDetailsTable .dl-horizontal").before(props); const login = JSON.parse($("div[data-react-class='UserDetails']").attr("data-react-props")).targetUser.targetUserLogin; const url = GetUserInfoUri(login); const req = typeof(GM_xmlhttpRequest) == "function" ? GM_xmlhttpRequest : GM.xmlHttpRequest; req({ url: url, method: "GET", onload: function(response) { try { var data = JSON.parse(response.responseText) if(data.hire_date_iso !== null) { const when = new Date(data.hire_date_iso + "T00:00:00Z"); $(".UserDetailsTable .HireDateRow .TableValue").text(getReadableDate(when)); } else { $(".UserDetailsTable .HireDateRow").hide(); } if(loadTenure) { if ((data.total_tenure_formatted !== null) && (data.total_tenure_formatted != "")) { $(".UserDetailsTable .TenureRow .TableValue").text(data.total_tenure_formatted); } else { $(".UserDetailsTable .TenureRow").hide(); } } if((data.job_level !== null) && (data.job_level != 99)) { $(".UserDetailsTable .LevelRow .TableValue").text(data.job_level + (data.is_manager !== null ? (data.is_manager ? ' (Mgr)': ' (IC)') : '')); } else { $(".UserDetailsTable .LevelRow").hide(); } if((data.badge_type == "blue") && (data.bar_raiser !== null)) { $(".UserDetailsTable .BarRaiserRow .TableValue").text(data.bar_raiser ? "Yes" : "No"); } else { $(".UserDetailsTable .BarRaiserRow").hide(); } if(data.manager && data.manager.login) { const managerUrl = GetUserInfoUri(data.manager.login); req({ url: managerUrl, method: "GET", onload: function(managerResponse) { try { var managerData = JSON.parse(managerResponse.responseText); if((managerData.login !== null) && (managerData.name !== null)) { $(".UserDetailsTable .ManagerRow .TableValue span").text(managerData.name); $(".UserDetailsTable .ManagerRow .TableValue a").text(managerData.login); $(".UserDetailsTable .ManagerRow .TableValue a").attr("href", '/users/' + managerData.login); } else { $(".UserDetailsTable .ManagerRow").hide(); } } catch(e) { console.error("An error occured processing response: ", e, data); } }, onerror: function(response) { console.error("An error occured calling resource: ", response); } }); } else { $(".UserDetailsTable .ManagerRow").hide(); } } catch(e) { console.error("An error occured processing response: ", e, data); } }, onerror: function(response) { console.error("An error occured calling resource: ", response); } }); } $(displayEmpInfo); })();