Skip to content

Instantly share code, notes, and snippets.

@scottw-kr
Forked from mbruno-kr/README.md
Last active March 20, 2023 19:33
Show Gist options
  • Save scottw-kr/bb9daf54081307ad54acfd2849d2aa60 to your computer and use it in GitHub Desktop.
Save scottw-kr/bb9daf54081307ad54acfd2849d2aa60 to your computer and use it in GitHub Desktop.

Auto-fill OneView Timesheets

Forked from Michael Bruno

Install

  1. Download a plugin called Tamper Monkey.
  2. Navigate to http://oneview.kroger.com/
  3. Add a new script.
  4. Paste the script into the function body.

Configure

  1. Update the task list with the tasks you have and the values you'd like to enter for them.
// ==UserScript==
// @name Autofill OneView Timesheet
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Help you save some time filling out your timesheet
// @author mbruno-kr, scottw-kr
// @match http://oneview.kroger.com/niku/nu
// @icon https://www.google.com/s2/favicons?sz=64&domain=kroger.com
// @grant none
// ==/UserScript==
(function() {
'use strict';
// TODO: FILL IN YOUR LINE ITEMS AND THE TIME TO GIVE EACH
const tasks = [
{
name: "Pickup Readiness – Phase 3 Cue - Capital", // CODING
time: 5
}, {
name: "Pickup Readiness – Phase 3 Cue - Expense", // MEETINGS
time: 2
}, {
name: "Support & Maintenance", // ON SUPPORT
time: 0
}, {
name: "General Admin", // EMAILS, HR, FILLING OUT TIME SHEETS, ETC.
time: 1
}, {
name: "PTO/ Vacation/ Approved Absences", // PTO
time: 0
}, {
name: "Non Project Training", // LEARNING & DEVELOPMENT DAYS, OTHER TRAINING
time: 0
}, {
name: "Holiday", // FEDERAL HOLIDAYS
time: 0
}
]
function getDays() {
let days = []
document.querySelectorAll('[data-columnid="day"]').forEach(e => {
let content = e.innerText;
if (content.length > 0) {
days.push(content.replace(/\n/g, " ").trim().replace(" ", ", "))
}
})
return days;
}
function autoFill() {
let days = getDays();
let weekDays = days.slice(1,6);
// For each weekday, fill each task's values
weekDays.forEach(dayOfWeek => {
tasks.forEach(task => {
let day = document.querySelector(`input[alt*='${dayOfWeek}'][title*='${task.name}']`)
if (!day) {
const msg = `Cannot find activity "${task.name}" on ${dayOfWeek}`
alert(msg)
throw Error(msg)
}
// If there's no value in there already, add the configured time
if (!day.value) day.value = task.time
})
})
// submitForm('page','timeadmin.saveTimesheet')
}
function addAutofillButton() {
let container = document.querySelector('div[class*="ppm_button_bar"]');
if (!container) {
setTimeout(main, 200)
return;
}
if (isEntryPage()) {
// if ther is no button
if (!container.querySelector('button[id="auto-fill"]')) {
let button = document.createElement("button");
button.id = "auto-fill"
button.innerText = "Auto Fill"
button.className = "ppm_button"
button.style = "box-shadow: 0 0 15px 3px rgb(182 148 92, 1);"
button.onclick = autoFill;
container.appendChild(button)
// } else {
// const input = document.querySelectorAll('input[name="actuals_hours"]')[1];
// // if the form is still empty
// if (input && input.value === '') {
// const xpath = "//button[text()='Auto Fill']";
// const matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
// matchingElement.click()
// }
}
}
}
const isEntryPage = () => document.querySelectorAll('img[title="Delete"]')[0] !== undefined
// function populate() {
// const xpath = "//button[text()='Populate']";
// setTimeout(() => {
// const matchingElement = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
// if (isEntryPage()) matchingElement.click()
// }, 500)
// }
function main() {
// http://oneview.kroger.com/niku/nu#action:timeadmin.editTimesheet&tpid=5009371&resid=5426061
const onTimeSheetPage = window.location.hash.indexOf('editTimesheet') !== -1
if (onTimeSheetPage) {
setTimeout(() => {
console.log('AutoFill Running')
// populate()
setInterval(addAutofillButton, 100)
}, 500)
}
}
main();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment