Skip to content

Instantly share code, notes, and snippets.

@Tiny-Giant
Created August 22, 2016 23:47
Show Gist options
  • Save Tiny-Giant/b3d7aeac7f5c9a2024b08c949e3141b8 to your computer and use it in GitHub Desktop.
Save Tiny-Giant/b3d7aeac7f5c9a2024b08c949e3141b8 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name BRP - KC CREATE NEW CASE
// @namespace http://github.com/Tiny-Giant
// @description Makes a link to create new case on knowledge center VIN lookup page
// @include https://brp.secure.force.com/apex/cs_main*
// @include https://brp.secure.force.com/500/e?RecordType=012a0000001C8JP&VIN=*
// @version 1
// @grant none
// ==/UserScript==
if (/cs_main/.test(window.location.href))
{
var funcs = {};
funcs.addXHRListener = function(callback)
{
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function()
{
this.addEventListener('load', callback.bind(null, this), false);
open.apply(this, arguments);
};
};
funcs.addXHRListener(function(XHR)
{
if (document.querySelector('.newcaselink') !== null)
{
return false;
}
var VIN = document.querySelector("#vinString").value.trim();
if (!VIN)
{
return false;
}
if (XHR.responseURL !== "https://brp.secure.force.com/cs_main")
{
return false;
}
var headers = [].slice.call(document.querySelectorAll('.headingPanel'));
if (headers.length === 0)
{
return false;
}
var linksHeader = (headers.filter(function(el){
return /Links/.test(el.textContent);
}) || [false])[0];
if (linksHeader === false)
{
return false;
}
var links = linksHeader.parentNode;
var newcase = links.children[2].cloneNode(true);
newcase.id = '';
var newcaselink = newcase.querySelector('a');
newcaselink.removeAttribute("onclick");
newcaselink.textContent = "Create New Case";
newcaselink.className = "newcaselink";
newcaselink.href = "https://brp.secure.force.com/500/e?RecordType=012a0000001C8JP&VIN=" + VIN;
newcaselink.target = "_blank";
links.insertBefore(newcase, links.children[2]);
});
}
else
{
document.querySelector('#Asset').value = window.location.search.split('&')[1].split('=')[1];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment