<!doctype html>
<html>
<head>
<title>Dynamic Javascript and/or CSS Head Tag - RJM Programming - June, 2015</title>
<script src="http://code.jquery.com/jquery-2.0.3.min.js" type="text/javascript"></script>
<link href='//www.rjmprogramming.com.au/PHP/emboss_h1.css' rel='stylesheet' type='text/css'>
<script type='text/javascript'>

var shuh="";
var preshuh="";
var cstyle="";
var cscript="";

function parse(ins) {
var outs=ins;
if (ins != "") {
outs=outs.replace(/ type="text\/css"/g, "").replace(/ type="text\/javascript"/g, "").replace(/ type='text\/css'/g, "").replace(/ type='text\/javascript'/g, "");
outs=outs.replace(/style>"/g, 'style>"').replace(/STYLE>"/g, 'style>"').replace(/style>'/g, "style>'").replace(/STYLE>'/g, "style>'").replace(/"<style/g, '"<style').replace(/"<STYLE/g, '"<style').replace(/'<style/g, "'<style").replace(/'<STYLE/g, "'<style").replace(/STYLE>/g, "style>").replace(/SCRIPT>/g, "script>").replace(/"<\/style/g, '"</style').replace(/"<\/STYLE/g, '"</style').replace(/'<\/style/g, "'</style").replace(/'<\/STYLE/g, "'</style");
//alert(outs);
var stylebits=outs.replace("<" + "style" + ">", "style>").replace("<" + "style" + ">", "style>").replace("</" + "style" + ">", "style>").replace("</" + "style" + ">", "style>").split("style>");
if (stylebits.length > 1) {
//alert("here at style");
for (var istyle=1; istyle<stylebits.length; istyle+=2) {
cstyle += stylebits[istyle];
outs=outs.replace("<" + "style>", "").replace("<" + "style>", "").replace("</" + "style>", "").replace("</" + "style>", "");
}
}
var scriptbits=outs.replace("<" + "script" + ">", "script>").replace("<" + "script" + ">", "script>").replace("</" + "script" + ">", "script>").replace("</" + "script" + ">", "script>").split("script>");
if (scriptbits.length > 1) {
//alert("here at script");
for (var iscript=1; iscript<scriptbits.length; iscript+=2) {
cscript += scriptbits[iscript];
outs=outs.replace("<" + "script>", "").replace("<" + "script>", "").replace("</" + "script>", "").replace("</" + "script>", "");
}
}
}
if (outs != "") {
if (outs.indexOf("{") != -1 && outs.indexOf(":") != -1 && outs.indexOf("=") == -1 && outs.indexOf("(") == -1) {
cstyle=outs;
outs="";
}
}
return outs;
}

function askforjavascript() {
if (document.URL.indexOf("?iframe=iframe") == -1) {
var mystuff=prompt("What do you want to add to Javascript and/or CSS of this webpage? For Javascript, start with 'function ' or use <" + "script> ... </" + "script> and we will retain what you put, else we will 'eval()' it. For CSS use <" + "style> ... </" + "style> Enter nothing to finish up.", "");
if (mystuff != null) {
mystuff=parse(mystuff);
if (mystuff != '' || cstyle != "" || cscript != "") {
if (("~" + mystuff).indexOf("~function ") != -1 || cscript != ""|| cstyle != "") {
if (cstyle != "") cstyle="<" + "style>" + cstyle + "</" + "style>";
if (cscript != "") {
if (mystuff == cscript) mystuff="";
cscript="<" + "script>" + cscript + mystuff + "</" + "script>";
mystuff="";
}
location.href='dynamic_javascript_iframe.html?scr=' + encodeURIComponent(shuh + mystuff + cscript + cstyle);
} else {
eval(mystuff + cscript);
setTimeout(askforjavascript, 2000);
}
}
}
} else if (document.URL.indexOf("?iframe=iframe") != -1) {
//document.getElementById('myh1').style.display='none';
//document.body.innerHTML = "";
if (document.URL.indexOf("&scr=") == -1 && top.document.URL.indexOf("scr=") == -1) {
document.write("");
}
}
}

function onl() {
preshuh=(location.search.split('scr=')[1] ? location.search.split('scr=')[1].split('&')[0] : "");
while (preshuh.indexOf("+") != -1) {
preshuh = preshuh.replace("+", " ");
}
var shuh=parse(decodeURIComponent(preshuh));
if (("~" + shuh).indexOf("~function ") != -1 || cscript != "") {
var scriptTag = document.createElement('script');
if (shuh.indexOf(cscript) != -1 && cscript != "") shuh="";
//alert("shuh=" + shuh.length + " AnD cscript=" + cscript.length);
if (shuh == cscript) shuh="";
scriptTag.innerHTML = shuh + cscript;
var head = document.getElementsByTagName('head')[0];
head.appendChild(scriptTag);
if (cscript != "") {
//alert("shuh=" + shuh + " AND cscript=" + cscript);
if (shuh == cscript) shuh="";
cscript = "<script>\n" + cscript + shuh + "</" + "script>\n";
shuh="";
}
//alert(shuh + cscript);
document.getElementById('scr').innerHTML = shuh + cscript;
} else if (shuh != "" || cscript != "") {
if (document.URL.indexOf("?iframe=iframe") == -1) {
if (shuh.indexOf(cscript) != -1 && cscript != "") shuh="";
if (shuh == cscript) shuh="";
eval(shuh + cscript);
shuh="";
cscript="";
}
}

if (cstyle != "") {
//alert("shuh=" + shuh + " and cstyle=" + cstyle);
var styleTag = document.createElement('style');
styleTag.innerHTML = cstyle;
var headcss = document.getElementsByTagName('head')[0];
headcss.appendChild(styleTag);
//alert("++ cstyle=" + cstyle + " and shuh=" + shuh + " and cscript=" + cscript);
if (document.URL.indexOf("?iframe=iframe") == -1) {
document.getElementById('scr').innerHTML = "<style>\n" + cstyle + "</" + "style>\n" + shuh + cscript;
}
}

if (document.URL.indexOf("?iframe=iframe") == -1) {
var table_of_iframes = "<div align='center'><table>";
var docu = document.URL.split("?");
for (var icols=0; icols<3; icols++) {
table_of_iframes += "<tr>";
for (var irows=0; irows<3; irows++) {
table_of_iframes += "<td>";
table_of_iframes += "<iframe src='" + docu[0] + "?iframe=iframe' title='i" + icols + irows + "' id='i" + icols + irows + "'></iframe>";
table_of_iframes += "</td>";
}
table_of_iframes += "</tr>";
}
table_of_iframes += "</table></div>";
document.body.innerHTML += table_of_iframes;
} else if (document.URL.indexOf("?iframe=iframe") != -1) {
//document.getElementById('myh1').style.display='none';
//document.body.innerHTML = "";
if (shuh != "") alert(shuh);
if (document.URL.indexOf("&scr=") == -1 && top.document.URL.indexOf("scr=") == -1) {
document.write("");
}
}
}
</script>
</head>
<body onload='onl(); setTimeout(askforjavascript,2000);' style='background-color: cyan;'>
<h1 id='myh1' align='center'>Dynamic Javascript and/or CSS Head Tag - RJM Programming - June, 2015</h1>
<div id='mydiv' align='center'>
<form method='GET' id='myform' action='dynamic_javascript_iframe.html'>
<input type='submit' value='Javascript and/or CSS'></input> <textarea id='scr' name='scr' cols=80 rows=20 value=''></textarea>
<form>
</div>
</body>
</html>