Skip to content

Instantly share code, notes, and snippets.

@zhouqt
Forked from roylez/SFComment.user.js
Last active January 13, 2021 08:37
Show Gist options
  • Save zhouqt/587824647f7f8964dbae8a4317f87e57 to your computer and use it in GitHub Desktop.
Save zhouqt/587824647f7f8964dbae8a4317f87e57 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name SFComment
// @namespace http://tampermonkey.net/
// @version 0.11
// @description Workaround negative timecard caused by time drift
// @description Some SF comment window hacks
// @author roylez
// @include https://canonical*.visual.force.com/servlet/servlet.Integration*
// @license MIT
// @require https://code.jquery.com/jquery-2.2.4.min.js
// @updateURL https://gist.github.com/zhouqt/587824647f7f8964dbae8a4317f87e57/raw/SFComment.user.js
// @downloadURL https://gist.github.com/zhouqt/587824647f7f8964dbae8a4317f87e57/raw/SFComment.user.js
// @run-at document-idle
// ==/UserScript==
function inject_css() {
$("head").append('<meta name="viewport" content="width=device-width, initial-scale=1">')
$("head").append('<link ' + 'href="//unpkg.zhimg.com/tachyons@4/css/tachyons.min.css" ' + 'rel="stylesheet" type="text/css">')
}
function update_timecard(window) {
var w;
if (typeof unsafeWindow != undefined) {
w = unsafeWindow
} else {
w = window;
}
var timecard = $('input[name="vfpage:caseForm:caseBlock:CommentsSection:TimeSpentRequired:timeSpent"]')
function listener(event){
if ( event.data.timecard && !timecard.val() ) {
var t = event.data.timecard
if ( t <= 0 ) { t = 5 }
timecard.val( t )
}
}
w.addEventListener("message", listener,false)
timecard.on("focusin", function() { w.parent.postMessage("getTime","*") })
}
function default_inputs() {
let status = $('select[name="vfpage:caseForm:caseBlock:CommentsSection:StatusRequired:caseStatus"]')
status.val("Waiting on Customer")
let comment = $('textarea[name="vfpage:caseForm:caseBlock:CommentsSection:CaseCommentRequired:caseComment"]')
comment.addClass('code black bg-washed-green db border-box hover-black br2 b--black-20 w-90')
comment.val("Hello,\n\n\n\nThanks,\nTom")
}
inject_css()
update_timecard(window)
default_inputs()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment