add_action("admin_footer", function (){
if( get_post_type()=="wbcr-snippets" && ($GLOBALS['pagenow']=='post-new.php' || $GLOBALS['pagenow']=='post.php') ){
echo '
<script>
var CurrentCodeMirrorCode="first_time";
var FirstCodeMirrorCode="first_time";
var document_title="";
var document_title_edited="";
function decodeHtmlCharCodes(str) {
return str.replace(/(&#(\d+);)/g, function(match, capture, charCode) {
return String.fromCharCode(charCode);
});
}
function CodeMirrorCodeWithoutSpaces(){
var string="";
var children_divs=document.getElementsByClassName("CodeMirror-code").item(0).children; //itterate
var all_spans="";
for(var j=0; j<children_divs.length; j++){
all_spans=children_divs.item(j).getElementsByTagName("PRE").item(0).getElementsByTagName("SPAN").item(0).getElementsByTagName("SPAN");
var flag=false;
for(var i=0; i<all_spans.length; i++){
var text = all_spans.item(i).innerHTML;
text=text.replace(/\s/g, "");
//the above if-loop is to not identify new empty line as new content
if(all_spans.item(i).innerHTML!=decodeHtmlCharCodes("& #8203;")){ //SOS Delete the space between & and #
string=string + text;
flag=true;
}
}
if(flag===true){
string= string + "end_of_codemirror_line";
}
}
//console.log(string);
//string=string.replace("", "");
return string;
}
var interval_CodeMirrorCode = setInterval(function()
{
if(FirstCodeMirrorCode=="first_time")
{
FirstCodeMirrorCode=CodeMirrorCodeWithoutSpaces(); //first content converted as string
CurrentCodeMirrorCode=FirstCodeMirrorCode;
document_title=document.title;
document_title_edited=document_title.replace(" ", " *"); //in my code I change the first occurrence of space with *
}else
{
CurrentCodeMirrorCode=CodeMirrorCodeWithoutSpaces(); //current content converted as string
}
if(CurrentCodeMirrorCode!=FirstCodeMirrorCode){
document.title=document_title_edited; //change the title if content is different
}else{
document.title=document_title; //if not remove the asterisc (first title)
}
},1000); //checks every seconds for changes
</script>
';
}
},20);