Skip to content

Instantly share code, notes, and snippets.

@caleblloyd
Last active January 4, 2021 16:20
Show Gist options
  • Save caleblloyd/fc1cce8aecbaa66265a0be7d80f019d2 to your computer and use it in GitHub Desktop.
Save caleblloyd/fc1cce8aecbaa66265a0be7d80f019d2 to your computer and use it in GitHub Desktop.
Tampermonkey Zoho Expense Auto Reference
// ==UserScript==
// @name Zoho Expense Auto Reference
// @namespace https://boxboat.com/
// @version 0.1
// @description Auto add reference to Zoho Expense
// @author Caleb Lloyd
// @match https://expense.zoho.com/*
// @grant none
// ==/UserScript==
(function(e, s) {
var jq
var name = metaInfo.user.name
var hasRef = false
var run = function() {
var jqRef
var date = ""
var category = ""
var foundRef = false
jq(".form-group").each(function(k, v){
var label = jq(v).find("label").first().html().trim()
if (label.includes("Reference")) {
foundRef = true
if (!hasRef) {
jqRef = jq(v).find("input").first()
hasRef = true
}
}
})
if (!foundRef) {
hasRef = false
}
if (jqRef) {
var setRef = function() {
jqRef.val(name + " - " + date + " - " + category)
}
jq(".form-group").each(function(k, v){
var label = jq(v).find("label").first().html().trim()
if (label.includes("Date")) {
var jqDate = jq(v).find("input").first()
date = jqDate.val()
jqDate.blur(function(){
setTimeout(function(){
date = jqDate.val()
setRef()
}, 100)
})
}
if (label.includes("Category")) {
var jqCategory = jq(v).find(".ac-selected > span").first()
category = jqCategory.html()
var observer = new MutationObserver(function(){
category = jqCategory.html()
setRef()
})
observer.observe(jqCategory[0], {attributes: true, characterData: true, childList: true})
}
})
setRef()
}
}
e.src = s
e.onload = function() {
jq = jQuery.noConflict(true)
setInterval(run, 1000)
}
document.head.appendChild(e)
})(document.createElement('script'), 'https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js')
@caleblloyd
Copy link
Author

Faheem's version is simpler and probably works better: https://gist.github.com/faheem556/d899422d29893545c8cdbf45e5a9ca39

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