Created
January 29, 2019 23:55
-
-
Save natecavanaugh/d5d59383ffda13169774e67f6d70da28 to your computer and use it in GitHub Desktop.
Am I Running Liferay (TamperMonkey)
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
// ==UserScript== | |
// @name Am I Running Liferay? | |
// @namespace http://userscripts.org/users/23423423 | |
// @include * | |
// @connect * | |
// @grant unsafeWindow | |
// @grant GM_xmlhttpRequest | |
// ==/UserScript== | |
var createBanner = function () { | |
var body = document.body; | |
var banner = document.body.innerHTML += '<div style="position: fixed; top: 0; width: 100%; background: #ffc; opacity: 0.9;border-bottom: 1px solid #FFCC00; padding: 10px; font-weight: bold; z-index: 1000000">This website is running Liferay! <a href="javascript: ;" id="amILiferayHide">Hide</a> - <a href="javascript: ;" id="amILiferayDiscard">Stop showing for this domain</a></div>'; | |
bindBanner(); | |
}; | |
function bindBanner() { | |
var hideMessage = function(el) { | |
unsafeWindow.console.log(el); | |
el.parentNode.removeChild(el); | |
}; | |
// var console = unsafeWindow.console; | |
document.getElementById('amILiferayHide').addEventListener('click', function(event) { | |
hideMessage(this.parentNode); | |
}, false); | |
document.getElementById('amILiferayDiscard').addEventListener('click', function() { | |
var container = this.parentNode; | |
container.innerHTML = 'This website will no longer notify you (at least until you clear your cookies!)'; | |
container.style.backgroundColor = '#F4FDEF'; | |
container.style.borderColor = '#ACDFA7'; | |
container.style.color = '#384F34'; | |
container.style.opacity = 1; | |
var name = 'amiliferay_greasemonkey'; | |
var value = 'dontshow'; | |
var expires = (365 * 24 * 60 * 60 * 1000); | |
var date = new Date(); | |
date.setTime(date.getTime() + expires); | |
expires = '; expires=' + date.toGMTString(); | |
var path = ''; | |
var domain = ''; | |
var secure = ''; | |
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join(''); | |
setTimeout( | |
function() { | |
hideMessage(container); | |
}, 5000); | |
}, false); | |
} | |
var cookie = document.cookie; | |
var console = unsafeWindow.console; | |
if (cookie.indexOf('amiliferay_greasemonkey=dontshow') == -1) { | |
// console.log(location.hostname, unsafeWindow.Liferay); | |
if (unsafeWindow.Liferay) { | |
createBanner(); | |
} | |
else { | |
GM_xmlhttpRequest({ | |
method:"GET", | |
url: unsafeWindow.location.href, | |
onload:function(details) { | |
console.log(details); | |
var headers = details.responseHeaders; | |
var isLiferay = (headers.toLowerCase().indexOf('liferay-portal:') > -1); | |
// console.log(headers); | |
if (isLiferay) { | |
createBanner(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment