Last active
August 14, 2019 09:23
-
-
Save andraaspar/db13315b634df92aac7c0997a05ad374 to your computer and use it in GitHub Desktop.
Replicon Web TimeSheet
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 Web Timesheet | |
// @namespace andraaspar | |
// @version 0.3.2 | |
// @description Tweaks. | |
// @author AP | |
// @match http://na1.replicon.com/ovitas/* | |
// @run-at document-idle | |
// @require https://code.jquery.com/jquery-3.2.1.slim.min.js | |
// @grant GM.setValue | |
// @grant GM.getValue | |
// ==/UserScript== | |
GM.getValue('namesByTaskValue', '{}') | |
.then(JSON.parse) | |
.then(namesByTaskValue => { | |
const taskValuesSeen = new Set() | |
let listJq = undefined | |
setInterval(() => { | |
const bodyIframeJq = jQuery(`#body`) | |
if (!bodyIframeJq.contents().find('#greasemonkey-style').length) { | |
bodyIframeJq.contents().find('head') | |
.append(`<style id="greasemonkey-style"> | |
.timesheetDropDown.hacked > span { | |
display: none !important; | |
} | |
.timesheetDropDown.hacked > mark, | |
.timesheetDropDown.ignored > mark { | |
float: right; | |
padding: 2px; | |
border: 1px solid gray; | |
background: peachpuff; | |
} | |
.hacked-list { | |
margin: 20px; | |
z-index: 1; | |
} | |
</style>`) | |
} | |
const namesJq = bodyIframeJq | |
.contents() | |
.find(`.timesheetDropDown:not(.hacked,.ignored)[taskvalue]`) | |
for (let i = 0; i < namesJq.length; i++) { | |
const nameJq = namesJq.eq(i) | |
const taskValue = nameJq.attr(`taskvalue`) | |
taskValuesSeen.add(taskValue) | |
const newName = namesByTaskValue[taskValue] | |
if (newName) { | |
const [group, activity] = newName.split(/\s?:\s?/) | |
nameJq | |
.append('<strong>') | |
.children('strong') | |
.text(group) | |
if (activity) { | |
nameJq | |
.append('<em>') | |
.children('em') | |
.text(': ' + activity) | |
} | |
nameJq.addClass(`hacked`) | |
} else { | |
nameJq.addClass(`ignored`) | |
} | |
$(`<mark class="hacked-edit-button">Edit</mark>`) | |
.on('mouseup', e => { | |
e.stopPropagation() | |
e.preventDefault() | |
let name = prompt( | |
`Enter name for ‘${taskValue}’`, | |
namesByTaskValue[taskValue], | |
) | |
if (name != null) { | |
if (name) { | |
namesByTaskValue[taskValue] = name | |
} else { | |
delete namesByTaskValue[taskValue] | |
} | |
GM.setValue( | |
'namesByTaskValue', | |
JSON.stringify(namesByTaskValue), | |
) | |
nameJq | |
.removeClass(`hacked ignored`) | |
.children('em,strong,mark') | |
.remove() | |
} | |
}) | |
.prependTo(nameJq) | |
} | |
if (!listJq && taskValuesSeen.size) { | |
listJq = $('<ul class="hacked-list">').appendTo( | |
'#sideMenuInnerMenuScroller', | |
) | |
for (const taskValue of Object.keys(namesByTaskValue)) { | |
if (!taskValuesSeen.has(taskValue)) { | |
const liJq = $(`<li><a>`) | |
.appendTo(listJq) | |
liJq.find('a') | |
.text( | |
`Remove: ${taskValue} – ${ | |
namesByTaskValue[taskValue] | |
}`, | |
) | |
.on('click', () => { | |
delete namesByTaskValue[taskValue] | |
GM.setValue( | |
'namesByTaskValue', | |
JSON.stringify(namesByTaskValue), | |
) | |
liJq.remove() | |
}) | |
} | |
} | |
} | |
}, 1000) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment