Last active
March 27, 2024 14:30
-
-
Save riccjohn/276efa3bac5ab0cb2e1d2cd1af759b7c to your computer and use it in GitHub Desktop.
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
// ==UserScript== | |
// @name Display current year PTO only | |
// @namespace MetricAi | |
// @version 2024-03-26 | |
// @description Hides PTO from previous & future calendar years | |
// @author You | |
// @match https://psa.metric.ai/home/my-timeoff/policies/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=metric.ai | |
// @grant none | |
// ==/UserScript== | |
'use strict'; | |
const addWarningText = () => { | |
const toolbar = document.getElementsByClassName('toolbar'); | |
const warning = document.createElement('h3'); | |
warning.textContent = 'WARNING: SCRIPT ONLY DISPLAYING CURRENT YEAR'; | |
warning.style.color = '#FF0000'; | |
warning.style.fontWeight = 'bold'; | |
toolbar[0].insertAdjacentElement('afterend', warning); | |
}; | |
const filterRows = () => { | |
const currentYear = new Date().getFullYear(); | |
const tableBody = document.querySelector('tbody'); | |
const rows = Array.from(tableBody.querySelectorAll('tr')); | |
rows.forEach((row) => { | |
const yearCell = row.querySelector('.clippable-text'); | |
if (!yearCell) { | |
row.remove(); // Remove empty rows | |
return; | |
} | |
const year = yearCell.textContent.trim(); | |
const isCurrentYear = year.includes(currentYear); | |
if (!isCurrentYear) { | |
row.remove(); | |
} else { | |
row.style.fontWeight = 'bold'; | |
const valueCell = row.querySelector('td:nth-child(3) .clippable-text'); | |
const value = parseFloat(valueCell.textContent); | |
valueCell.style.color = value > 0 ? 'green' : value < 0 ? 'red' : ''; | |
} | |
}); | |
}; | |
const hideNonCurrentYearPto = () => { | |
const table = document.querySelector('table'); | |
if (table) { | |
addWarningText(); | |
filterRows(); | |
observer.disconnect(); | |
} | |
}; | |
const observer = new MutationObserver(hideNonCurrentYearPto); | |
observer.observe(document.body, { childList: true, subtree: true }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment