Skip to content

Instantly share code, notes, and snippets.

@tonymarklove
Last active June 19, 2017 12:07
Show Gist options
  • Select an option

  • Save tonymarklove/15dfc33ce22543afb69fd96024d2b9c4 to your computer and use it in GitHub Desktop.

Select an option

Save tonymarklove/15dfc33ce22543afb69fd96024d2b9c4 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Zoho Estimate Plugin
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add button for converting Zoho estimates to purchase and sales orders.
// @author You
// @include https://books.zoho.eu/app
// @grant GM_log
// ==/UserScript==
(function() {
'use strict';
function createLinkElement(text, href) {
var a = document.createElement('a');
var linkText = document.createTextNode(text);
a.appendChild(linkText);
a.href = href;
a.className = "btn btn-default";
a.target = "_blank";
return a;
}
function perform(waitTime) {
waitTime = waitTime || 100;
setTimeout(function() {
var match = location.hash.match(/#\/quotes\/(\d+)\?/);
if (!match) {
return;
}
var estimateId = match[1];
var replacedElement = document.querySelector(".content-column .btn-toolbar > button");
if (!replacedElement) {
perform(waitTime * 2);
return;
}
var linkHref = "https://portal.steelscout.com/zoho?enquiryId=" + estimateId;
var newLinkElement = createLinkElement("Convert to Purchase Orders", linkHref);
replacedElement.parentNode.replaceChild(newLinkElement, replacedElement);
}, waitTime);
}
window.addEventListener("popstate", perform);
perform();
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment