Created
December 13, 2019 18:03
-
-
Save joelverhagen/1e2b1d9a641735abebb08ee5b5d3a431 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
nuget.enableUsabilla = function (obfuscatedPath) { | |
// If there is an obfuscated path, hook into the outgoing AJAX request containing the feedback and obfuscate | |
// the URL data. This approach was provided by the Usabilla technical support. | |
if (obfuscatedPath) { | |
var obfuscatedUrl = document.createElement('a'); | |
obfuscatedUrl.href = window.location.href; | |
if (obfuscatedPath.substring(0, 1) != "/") { | |
obfuscatedUrl.pathname = "/" + obfuscatedPath; | |
} else { | |
obfuscatedUrl.pathname = obfuscatedPath; | |
} | |
window.usabilla_live("setEventCallback", function (category, action, label, value, eventdata) { | |
if (action != "Feedback:Open") { | |
return; | |
} | |
function sendWithObfuscation(vData) { | |
var data = JSON.parse(vData); | |
data.url = obfuscatedUrl.href; | |
vData = JSON.stringify(data); | |
arguments[0] = vData; | |
realSend.apply(this, arguments); | |
} | |
var realSend = XMLHttpRequest.prototype.send; | |
var ub_window = document.getElementById("lightningjs-frame-usabilla_live_feedback").contentWindow; | |
ub_window.XMLHttpRequest.prototype.send = sendWithObfuscation; | |
if (window.XDomainRequest) { | |
realSend = XDomainRequest.prototype.send; | |
ub_window.XDomainRequest.prototype.send = sendWithObfuscation; | |
} | |
}); | |
} | |
// Hide the default feedback button. | |
window.usabilla_live("hide"); | |
// Wire-up and show the custom feedback button. | |
document.getElementById("usbl-integrated-button").addEventListener("click", function (event) { | |
event.preventDefault(); | |
window.usabilla_live("click"); | |
}); | |
document.getElementById("usabilla-button").style.display = "block"; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment