Skip to content

Instantly share code, notes, and snippets.

@makeros
Last active February 6, 2021 13:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makeros/b1bbc49e4a41a6d1074142d484c6d22f to your computer and use it in GitHub Desktop.
Save makeros/b1bbc49e4a41a6d1074142d484c6d22f to your computer and use it in GitHub Desktop.
IntercomCP2
function createNavMenuItem () {
var el = document.createElement("a");
el.className = "cp2-panel-menu";
el.appendChild(document.createTextNode("CP2"));
el.style.color = "red";
el.target = "cp";
return el;
}
function getUserEmail() {
var userDetails = document.querySelector(".test__user-details-area");
if (userDetails) {
var emailRow = userDetails.querySelector("span[data-attr-identifier='email']"),
emailNode = emailRow.parentNode.parentNode.querySelector("span[data-content]");
return emailNode.dataset.content;
}
return null;
}
function getProductsNavbar (startFunction) {
var productsNavbar = document.querySelector(".left-nav__product-links ");
console.log("Looing for navbar...");
if (productsNavbar) {
startFunction(productsNavbar);
} else {
setTimeout(function () {
getProductsNavbar(startFunction);
}, 5000);
}
}
// ==UserScript==
// @name Intercom to CP2 user redirect
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://app.intercom.io/*
// @grant none
// ==/UserScript==
(function(window) {
'use strict';
getProductsNavbar(function (navbar) {
var navItem = createNavMenuItem();
navItem.addEventListener("click", function () {
var email = getUserEmail();
if (!email) {
alert("No user email found ;(");
} else {
this.href = "http://localhost:8080/#/user/" + email;
}
});
navbar.appendChild(navItem);
});
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment