// keep_parent_background.js // RJM Programming // May, 2017 // As an HTML iframe child and parent defines document.body background, and the child has not defined background, adopt that parent one as the background //var myStyle = "color: #090"; //document.getElementById("myElement").style.cssText += '; ' + myStyle; // to append //document.getElementById("myElement").style.cssText = myStyle; // to replace var kpbadd=false, ifm_data="", ifm_ph="", pdhsone=1, parent_style="", pruleprefixtocheck=[], prulenamevaluetocheck=[], pruleph=[], iprule=-1, lastph="&style="; function forcsscheck() { // Thanks to https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/insertRule and https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleDeclaration var styleObj = forcsscheck, j=0, k=0, tval='', cval='', nameString='', i, prule='',title=''; //alert(1); var efd, fg,found=false, laststyleObj=null, lastj=0, styleEl, pds=[document], styleSheet; //alert(11); if (iprule > -1 && iprule < pruleph.length) { lastph=pruleph[iprule]; if (pruleph[iprule].indexOf("&style=") != -1 || pruleph[iprule].indexOf("&STYLE=") != -1) { pds.push(parent.document); } else if (pruleph[iprule].indexOf("&sTYLE=") != -1) { pds[0]=parent.document; } } else { if (lastph.indexOf("&style=") != -1 || lastph.indexOf("&STYLE=") != -1) { pds.push(parent.document); } else if (lastph.indexOf("&sTYLE=") != -1) { pds[0]=parent.document; } } //alert(pds.length); for (fg=0; fg -1 && iprule < pruleprefixtocheck.length) { //alert(pruleprefixtocheck.length + ' ' + pruleprefixtocheck[1] + ' { ' + prulenamevaluetocheck[1] + '; }'); //alert(found + ' ' + pruleprefixtocheck[iprule].trim().toLowerCase() + ' { ' + prulenamevaluetocheck[iprule] + ' !important; }'); if (!found) { styleEl = pds[fg].createElement('style'); pds[fg].head.appendChild(styleEl); // Grab style sheet styleSheet = styleEl.sheet; // Insert CSS Rule styleSheet.insertRule(pruleprefixtocheck[iprule].trim().toLowerCase().replace(/>/g,'>').replace(/</g,'<') + '{' + prulenamevaluetocheck[iprule] + ' !important;}', 0); // styleSheet.cssRules.length); //alert(pruleprefixtocheck[iprule].trim().toLowerCase().replace(/>/g,'>').replace(/</g,'<') + '{' + prulenamevaluetocheck[iprule] + ' !important;}'); styleObj = null; } while (styleObj != null) { while (styleObj != null) { styleObj=null; if (k < pds[fg].styleSheets.length) { //alert("pds[fg].styleSheets[" + k + "].length=" + pds[fg].styleSheets[k].cssRules.length); //if (j < pds[fg].styleSheets[k].cssRules.length) { //try { //alert(pds[fg].styleSheets.length); try { styleObj = pds[fg].styleSheets[k].cssRules[j].style; } catch (efd) { styleObj = null; //alert(pds[fg].styleSheets.length); } //} catch(efd) { // alert("k=" + k + " and j=" + j); // styleObj = null; //} //} } if (styleObj != null) laststyleObj=styleObj; if (styleObj != null) { prule = styleObj.parentRule.cssText; title = styleObj.cssText; for (i = styleObj.length; i--;) { nameString = styleObj[i]; if (pruleprefixtocheck[iprule].trim().toLowerCase() == prule.split('{')[0].trim().toLowerCase() && nameString.toLowerCase() == prulenamevaluetocheck[iprule].split(':')[0].toLowerCase()) { found=true; //styleObj.removeProperty(nameString); tval = ('' + title).split(('' + nameString) + ':')[1].split(';')[0]; cval=prulenamevaluetocheck=[iprule].split(nameString + ':')[1].split(';')[0]; // prompt('Regarding current CSS Stylesheet definition ... ' + String.fromCharCode(10) + String.fromCharCode(10) + title.split(';')[i] + ';' + String.fromCharCode(10) + String.fromCharCode(10) + ' ... feel free to change the value suggested within the CSS Rule ... ' + String.fromCharCode(10) + String.fromCharCode(10) + prule + String.fromCharCode(10) + String.fromCharCode(10), tval); if (cval != null) { if (cval != tval) { styleObj.setProperty(nameString, cval); //alert('Within ' + prule + ' ... ' + nameString + ' changed to ' + cval + ' (from ' + tval + ')'); //document.getElementById('findings').innerHTML+='Within ' + prule + ' ... ' + nameString + ' changed to ' + cval + ' (from ' + tval + ')
'; } } } } j++; lastj=j; } } styleObj = forcsscheck; k++; j=0; } styleObj = forcsscheck; j=0; k=0; tval=''; cval=''; nameString=''; i=0; prule=''; title=''; found=false; laststyleObj=null; lastj=0; } iprule--; setTimeout(forcsscheck,100); } } function nocomment(ins) { var spareo, outs=ins, cos=["",""]; while (outs.indexOf(String.fromCharCode(10)) != -1) { outs=outs.replace(String.fromCharCode(10),' '); } while (cos.length > 1) { cos=outs.split('*/'); if (cos.length > 1) { if (cos[0].indexOf('/*') != -1) { spareo=cos[0].split('/*'); outs=outs.replace('/*' + spareo[1] + '*/',' '); } else { outs=outs.replace('*/',' '); } } } return filterit(outs); } function ifm_check(iois) { if (iois != null) { var aconto = (iois.contentWindow || iois.contentDocument); if (aconto != null) { if (aconto.document) { aconto = aconto.document; } if (aconto.body != null) { //alert(aconto.body.innerHTML); if (aconto.body.innerHTML.indexOf('')[0]; ifm_data=aconto.body.innerHTML.replace(/:not\(/g,'~not(').replace(/:NOT\(/g,'~not(').replace(/:Not\(/g,'~not(').replace(/:not \(/g,'~not(').replace(/:NOT \(/g,'~not(').replace(/:Not \(/g,'~not(').replace(prehuh + '>','').replace('',''); } else { ifm_data=aconto.body.innerHTML.replace(/:not\(/g,'~not(').replace(/:NOT\(/g,'~not(').replace(/:Not\(/g,'~not(').replace(/:not \(/g,'~not(').replace(/:NOT \(/g,'~not(').replace(/:Not \(/g,'~not(').replace('
','').replace('
',''); } //alert(ifm_data); var ifm_partsbits = nocomment(ifm_data).split(':'); css_text_processing(ifm_ph, ifm_partsbits); } } } } function css_text_processing(fromarg,betweenstyles) { var i, j, k, cname='',cvalue=' ', cdname='', oneele=null, oneeleset,cnames; var thisrule="body", therules=["body"]; for (i=0; i',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else if (therules[j].indexOf('.') != -1) { if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else { if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } else if (fromarg.indexOf("&Style=") != -1) { oneeleset=document.getElementsByTagName('*'); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else if (therules[j].indexOf('.') != -1) { if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else { if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } else { oneeleset=parent.document.getElementsByTagName('*'); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else if (therules[j].indexOf('.') != -1) { if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else { if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } oneeleset=document.getElementsByTagName('*'); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else if (therules[j].indexOf('.') != -1) { if (oneeleset[k].className.toLowerCase() != therules[j].split('.')[1].toLowerCase() || oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } else { if (oneeleset[k].outerHTML.toLowerCase().replace('>',' ').indexOf('<' + therules[j].toLowerCase() + ' ') == -1) eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } } else if (therules[j].substring(0,1) == '#') { // single ID oneele=null; if (fromarg.indexOf("&sTYLE=") != -1) { oneele=parent.document.getElementById(therules[j].split('#')[1]); if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";"); } else if (fromarg.indexOf("&Style=") != -1) { oneele=document.getElementById(therules[j].split('#')[1]); if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";"); } else { oneele=parent.document.getElementById(therules[j].split('#')[1]); if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";"); oneele=document.getElementById(therules[j].split('#')[1]); if (oneele) eval("oneele.style." + cdname + "=\"" + cvalue + "\";"); } } else if (therules[j].substring(0,1) == '.') { // single class oneeleset=[]; if (fromarg.indexOf("&sTYLE=") != -1) { oneeleset=parent.document.getElementsByTagName('*'); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) { eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } oneeleset=document.getElementsByTagName(therules[j].split('.')[0].split('#')[0].toLowerCase()); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].toLowerCase() + ' ') == 0) { eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } } } else { // an element type oneeleset=[]; if (fromarg.indexOf("&sTYLE=") != -1) { oneeleset=parent.document.getElementsByTagName(therules[j].split('.')[0].split('#')[0].toLowerCase()); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].split('#')[0].toLowerCase() + ' ') == 0) { eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } else if (fromarg.indexOf("&Style=") != -1) { oneeleset=document.getElementsByTagName(therules[j].split('.')[0].split('#')[0].toLowerCase()); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].split('#')[0].toLowerCase() + ' ') == 0) { eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } else { oneeleset=parent.document.getElementsByTagName(therules[j].split('.')[0].split('#')[0].toLowerCase()); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].split('#')[0].toLowerCase() + ' ') == 0) { eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } oneeleset=document.getElementsByTagName(therules[j].split('.')[0].split('#')[0].toLowerCase()); for (k=0; k',' ').indexOf('<' + therules[j].split('.')[0].split('#')[0].toLowerCase() + ' ') == 0) { eval("oneeleset[k].style." + cdname + "=\"" + cvalue + "\";"); } } } } } } } if (!kpbadd) { kpbadd=true; setTimeout(adopt_parent_background_maybe,3000); setTimeout(forcsscheck,3500); } } function filterit(sb) { var outsb=sb, sp; var pbits=sb.split('{'); if (pbits.length > 1) { outsb=pbits[0].replace(/:/g,'|'); for (var ij=1; ij 1) { outsb+='}' + sp[1].replace(/:/g,'|'); } } } else if (outsb.toLowerCase().replace('https:','').replace('http:','').replace('file:','').indexOf('//') == 0) { var urls=outsb.split(';'); for (var iurls=0; iurls 0) { divs[eval(-1 + divs.length)].innerHTML+=''; } else { document.body.innerHTML+=''; } } outsb=""; } return outsb; } function adopt_parent_background_maybe() { if (parent.document) { var fromthetop=false; // Start of more generic ideas regarding passing CSS styling ideas over via ?style=[HTMLstyleString] argument at address bar or at call to external Javascript (ie. this keep_parent_background.js) from parent var dbs = document.getElementsByTagName('body'); var pdbs = parent.document.getElementsByTagName('body'); var pdhs = parent.document.getElementsByTagName('head'); if (pdhs.length >= pdhsone) { var passingahih = pdhs[0].innerHTML.split('keep_parent_background.js?'); if (passingahih.length <= 1) { fromthetop = true; passingahih = parent.document.URL.split('?'); } if (passingahih.length > 1) { var ph = '&' + passingahih[eval(-1 + passingahih.length)].split("'")[0].split('"')[0] + '&'; ifm_ph=ph; if (ph.toLowerCase().indexOf('&style=') != -1) { var sbitsare = decodeURIComponent(ph.replace('&STYLE=','&style=').replace('&sTYLE=','&style=').replace('&Style=','&style=').split('&style=')[1].split('&')[0]); var aname='',avalue='',thenpartsbits; var partsbits = filterit(sbitsare.replace(/:not \(/g,'~not (').replace(/:NOT \(/g,'~not (').replace(/:Not \(/g,'~not (')).split(':'); if (sbitsare.indexOf('{') != -1) { css_text_processing(ph,partsbits); } else if (sbitsare != "") { for (var iparts=1; iparts')[0].split(' style="'); if (parent_style_bits.length > 1) { if (parent_style == "") parent_style=(";" + parent_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';'); if (parent_style.toLowerCase().indexOf(";background") != -1) { if (dbs[0].outerHTML) { var self_style_bits=dbs[0].outerHTML.split('>')[0].split(' style="'); if (self_style_bits.length > 1) { var self_style=(";" + self_style_bits[1].split('"')[0] + ";").replace(/ ; /g,';').replace(/; /g,';').replace(/ ;/g,';'); if (self_style.toLowerCase().indexOf(";background") == -1 || 1 == 1) { if (parent_style.toLowerCase().indexOf(";background-color:") != -1) { document.body.style.backgroundColor=parent_style.toLowerCase().split(";background-color:")[1].split(";")[0].trim(); } } if (self_style.toLowerCase().indexOf("url(") == -1) { if (parent_style.toLowerCase().indexOf("url(") != -1) { var pd=parent.document; var parifs=pd.getElementsByTagName('iframe'); for (var iparifs=0; iparifs