Skip to content

Instantly share code, notes, and snippets.

@colelawrence
Last active August 9, 2016 17:28
Show Gist options
  • Select an option

  • Save colelawrence/a2cfc199a8e5ec51f59f4e9e0f98becb to your computer and use it in GitHub Desktop.

Select an option

Save colelawrence/a2cfc199a8e5ec51f59f4e9e0f98becb to your computer and use it in GitHub Desktop.
.styler-aem {
position: fixed;
z-index: 999999;
bottom: 1vw;
right: 1vw;
background: rgba(255,255,255,0.5);
font-size: 2vw;
padding: .5vw;
}
.styler-aem a + a {
margin-left: 1vw;
}
var n1 = document.createElement("DIV");
n1.className = 'styler-aem';
var packmgr = "/crx/de/index.jsp";
var aemwcm = "/siteadmin#/content";
var prj = "/projects.html";
var edit = function () {
var here = window.location.href;
here = here.replace(/\/content\//, "/editor.html/content/");
here = here.replace(/\?(.*&)?wcmmode=disabled/, "?$1");
window.location.href = here;
}
var preview = function () {
var here = window.location.pathname;
var hash = window.location.hash;
here = here.replace(/\/editor.html\/content\//, "/content/");
here += '?wcmmode=disabled' + hash;
window.location.href = here;
}
n1.appendChild(CreateButton(packmgr, 'CRX'));
n1.appendChild(CreateButton(prj, 'Projects'));
n1.appendChild(CreateButton(aemwcm, 'WCM'));
if (isPreview()) n1.appendChild(CreateButton(edit, 'Edit'));
if (isEditor()) n1.appendChild(CreateButton(preview, 'Preview'));
function isEditor(){
return /^\/editor\.html/.test(window.location.pathname);
}
function isPreview(){
return /^\/content/.test(window.location.pathname);
}
function CreateButton (href, title, cls) {
const jsHref = 'javascript: void(0);'
var btn = document.createElement("A");
if (cls) btn.className = cls;
if (typeof href === 'function') {
btn.href = jsHref;
btn.onclick = href;
} else {
btn.href = href;
}
btn.textContent = title;
return btn;
}
setTimeout(function () {
document.body.appendChild(n1);
console.log(n1);
}, 1000)
@colelawrence
Copy link
Copy Markdown
Author

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment