greasemonkey script for different preview functions

Here is a greasemonkey script that links to different versions of the page preview. I find this invaluable when debugging problems (so i don’t have to hunt through the url to change a parameter…). Right now it only allows for debug/preview, change in item filter (preview/public), and sys_context (301) but should be easy enough to change as needed. These three options show up on the bottom of the page as a series of links and clicking on them links to the preview page with a particular parameter changed…

NOTE:
You must change the [site] and [port] values on the top of the script in order for this to work on your particular rx instance.


// ==UserScript==
// @name           vtCMSURLUtils
// @namespace      https://[site]
// @description    Rewrites URL for previewing
// @include        https://[site]:[port]/Rhythmyx/assembler/*
// ==/UserScript==

function addGlobalStyle(css) {
    var head, style;
    head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

var current_url = window.location.href;
var debugTxt, previewTxt, contTxt;
// debug/render
var url_base = (current_url.indexOf("Rhythmyx/assembler/")+19);
var compareStr = current_url.substring(url_base, url_base+6);
var debug_render_url, part1, part2;
if (compareStr == "render"){
	part1 = current_url.substring(0, url_base);
	part2 = current_url.substring(url_base+6, current_url.length);
	debug_render_url = part1+'debug'+part2;
	debugTxt = "Debug";
}else{
	part1 = current_url.substring(0, url_base);
	part2 = current_url.substring(url_base+5, current_url.length);
	debug_render_url = part1+'render'+part2;
	debugTxt="Render";
}

// public/preview
var pub_prev_url;
var loc_itemFilt = current_url.indexOf("sys_itemfilter=") +15;
var itemFilt = current_url.substring(loc_itemFilt, loc_itemFilt +6);
if (itemFilt == "public"){
	part1 = current_url.substring(0, loc_itemFilt);
	part2 = current_url.substring(loc_itemFilt+6, current_url.length);
	pub_prev_url = part1+"preview"+part2;
	previewTxt = "Preview";
}else if (itemFilt == "previe"){
	part1 = current_url.substring(0, loc_itemFilt);
	part2 = current_url.substring(loc_itemFilt+7, current_url.length);
	pub_prev_url = part1+"public"+part2;
	previewTxt="Public"
}else{
	pub_prev_url ="#";
	previewTxt = "N/A";
}	

// sys_context
var sys_context_url;
var loc_sysCont = current_url.indexOf("sys_context=") +12;
var sysCont = current_url.substring(loc_sysCont, loc_sysCont +1);
if (sysCont == "0"){
	part1 = current_url.substring(0, loc_sysCont);
	part2 = current_url.substring(loc_sysCont+1, current_url.length);
	sys_context_url = part1+"301"+part2;
	contTxt = "301 (Published)";
}else if (sysCont == "3"){
	part1 = current_url.substring(0, loc_sysCont);
	part2 = current_url.substring(loc_sysCont+3, current_url.length);
	sys_context_url = part1+"0"+part2;
	contTxt = "0 (Preview)";
}else{
	sys_context_url ="#";
}	


var desc, div;

div = document.createElement('div');
div.id = 'vtCMSUrlBar';
desc = '<div><ul><li class="first"><a href="'+debug_render_url+'">'+debugTxt+'</a></li>';
desc = desc + '<li><a href="'+pub_prev_url+'">'+previewTxt+'</a></li>';
desc = desc + '<li><a href="'+sys_context_url+'">'+contTxt+'</a></li>';
desc = desc + '</ul></div>';


div.innerHTML = desc;
document.body.style.paddingBottom = "4em";


window.addEventListener(
    "load",
    function() {
        document.body.appendChild(div);
    },
    true);
addGlobalStyle(
'#vtCMSUrlBar {'+
'  position: fixed;' +
'  left: 0;' +
'  right: 0;' +
'  bottom: 0;' +
'  top: auto;' +
'  border-top: 1px solid silver;' +
'  background: black;' +
'  color: white;' +
'  margin: 1em 0 0 0;' +
'  padding: 5px 0 0.4em 0;' +
'  width: 100%;' +
'  font-family: Verdana, sans-serif;' +
'  font-size: small;' +
'  z-index: 10000;' +
'  line-height: 160%;' +
'}' +
'#vtCMSUrlBar a,' +
'#vtCMSUrlBar li,' +
'#vtCMSUrlBar span,' +
'#vtCMSUrlBar strong {' +
'  background-color: transparent;' +
'  color: white;' +
'}' +
'#vtCMSUrlBar div {' +
'  margin: 0 1em 0 1em;' +
'}' +
'#vtCMSUrlBar div ul {' +
'  margin-left: 0;' +
'  margin-bottom: 5px;' +
'  padding-left: 0;' +
'  display: inline;' +
'}' +
'#vtCMSUrlBar div ul li {' +
'  margin-left: 0;' +
'  padding: 3px 15px;' +
'  border-left: 1px solid silver;' +
'  list-style: none;' +
'  display: inline;' +
'}' +
'#vtCMSUrlBar div ul li.first {' +
'  border-left: none;' +
'  padding-left: 0;' +
'}');

That’s really handy, thanks for sharing :slight_smile:

I second javier’s comment. Really handy. Thanks.