Skip to content

Instantly share code, notes, and snippets.

@hmps
Last active August 29, 2015 14:05
Show Gist options
  • Save hmps/74d8a338e4fa92d81dd7 to your computer and use it in GitHub Desktop.
Save hmps/74d8a338e4fa92d81dd7 to your computer and use it in GitHub Desktop.
ProspectEye Support Bookmarklet
// THE RIDDLE
(function() {
if ( !!document.getElementById('ProspectEyeDebugger') ) {
document.getElementById('ProspectEyeDebugger').remove();
}
function styleEl(el, styles) {
for( var style in styles) {
if ( styles[style].length === 2 ) {
el.style.setProperty(style, styles[style][0], "important");
}
el.style[style] = styles[style];
}
}
var tests = 3;
var debugEl = document.createElement('div');
debugEl.id = 'ProspectEyeDebugger';
var styles = {
'background': 'rgba(0,0,0,0.9)',
'position': 'fixed',
'top': '20px',
'left': '20px',
'width': '400px',
'padding': '15px',
'color': ['#eee', '!important'],
'letterSpacing': '1px',
'z-index': '100000',
'fontFamily': 'Verdana, Arialsans-serif'
};
styleEl(debugEl, styles);
debugEl.addEventListener('click', function() {
debugEl.remove();
});
var table = debugEl.appendChild(document.createElement('table'));
var tableStyles = {
'width': '100%',
'border': 'none',
'color': ['#eee', '!important'],
};
styleEl(table, tableStyles);
table.innerHTML = [
'<tr><td style="color:#eee">ID:</td><td style="color:#eee" id="js-id">-</td></tr>',
'<tr><td style="color:#eee">SCRIPT TAG:</td><td style="color:#eee" id="js-script">n/a</td></tr>',
'<tr><td style="color:#eee">NAMESPACE:</td><td style="color:#eee" id="js-ns">n/a</td></tr>',
'<tr><td style="color:#eee">DYNAMIC SITE:</td><td style="color:#eee" id="js-dynamic">No</td></tr>',
'<tr><td style="color:#eee">EMAIL ONLY LOADED:</td><td style="color:#eee" id="js-email">No</td></tr>',
'<tr><td style="color:#eee">EMAIL ONLY INPUT TYPE:</td><td style="color:#eee" id="js-input">-</td></tr>',
'<tr><td style="color:#eee">EMAIL ONLY NAME:</td><td style="color:#eee" id="js-name">-</td></tr>'].join('');
document.body.appendChild(debugEl);
function checkNS() {
if (!!window.ProspectEye) {
document.getElementById('js-ns').innerText = 'OK';
tests--;
if (!!ProspectEye.getSiteId) {
document.getElementById('js-id').innerText = ProspectEye.getSiteId();
tests--;
}
}
}
checkNS();
function checkTag() {
var tag = false,
scripts = document.getElementsByTagName("script");
for(var i=0;i<scripts.length;i++) {
if ( "" === scripts[i].src && !!scripts[i].innerText.match(/tr.prospecteye.com/) ) {
document.getElementById('js-script').innerText = 'OK';
tests--;
break;
}
}
}
checkTag();
function checkEmailOnly() {
if ( !!window._pe_formmodule_type ) {
document.getElementById('js-email').innerText = 'OK';
}
}
checkEmailOnly();
function checkDynamicSite() {
if ( !!window.psDynamicSite ) {
document.getElementById('js-dynamic').innerText = 'Yes';
}
}
checkEmailOnly();
function checkInput() {
var inputs = document.getElementsByTagName('input');
Array.prototype.forEach.call(inputs, function(input) {
if ( input.type === 'email' ) {
document.getElementById('js-input').innerText = 'OK';
}
if ( !!input.getAttribute('data-formname')) {
document.getElementById('js-name').innerText = input.getAttribute('data-formname');
}
});
}
checkInput();
if ( tests > 0 ) {
var callMe = document.createElement('div');
callMe.innerHTML = '<h3>Ok, something is wrong!</h3>' +
'<p>You may call this guy...</p>' +
'<a href="skype:andreas.helgegren?call/"><img src="https://media.licdn.com/mpr/mpr/shrink_200_200/p/2/000/0e8/2f6/2422025.jpg" style="border-radius:50%; width: 100px; height: auto;"></a>';
callMe.style.textAlign = 'center';
debugEl.appendChild(callMe);
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment