Skip to content

Instantly share code, notes, and snippets.

@vanadium23
Created April 12, 2023 05:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanadium23/b18b7e9a9efafe625cc1c12653407b79 to your computer and use it in GitHub Desktop.
Save vanadium23/b18b7e9a9efafe625cc1c12653407b79 to your computer and use it in GitHub Desktop.
Tampermonkey script to view "office" time
// ==UserScript==
// @name Second timezone for Slack web client
// @namespace http://vanadium23.me/
// @version 0.1
// @description Add second time on element hover
// @author vanadium23
// @match https://app.slack.com/client/*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function() {
'use strict';
// set your targetTimezone different from local
const targetTimezone = 'Europe/Belgrade';
document.body.addEventListener('mouseover', (event) => {
if (event.target.classList.contains('c-timestamp__label')) {
let localTime = event.target.innerText;
if (localTime.indexOf('/') !== -1) {
// already converted
return;
}
const parentNode = event.target.parentNode;
const timestamp = parseInt(parentNode.dataset.ts)*1000;
const localDateTime = new Date(timestamp);
const targetTime = new Intl.DateTimeFormat('en-US', {
timeZone: targetTimezone,
hour: '2-digit',
minute: '2-digit',
hour12: false,
timeZoneName: "shortGeneric",
}).format(localDateTime);
event.target.innerText = `${localTime} / ${targetTime}`;
}
});
})();
@vanadium23
Copy link
Author

example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment