Serolapy / CBM - Addon

// ==UserScript==
// @name         CBM - Addon
// @namespace    https://catwar.su/cat982738
// @version      1.0
// @description  Данный аддон позволит вам получить окрас любого кота на вашей локации, музыку и фон поля!
// @copyright	 2020, Serolapy (https://openuserjs.org/users/Serolapy)
// @license		 MIT
// @author       Серолапый, 2020
// @include      https://catwar.su/cw3/
// ==/UserScript==
window.onload = function() {
var CBMscript = document.createElement("script");
CBMscript.innerHTML = `
var CBMCheck=false;
var CBMdiv = document.createElement("div");
CBMdiv.innerHTML='<div id="audio"></div><br> 	<div id="background"></div><br> 	<div id="color"></div><br>';
CBMdiv.style.cssText = 'position:fixed; 	top:30px; 	background:#FFFFFF; 	height:30%; 	width:30%; 	display:none; 	overflow:scroll';
document.body.appendChild(CBMdiv);
function onCBM(){
	if(!CBMCheck){
		CBMdiv.style.display = "block";
		CBMCheck=true;
	} else{
		CBMdiv.style.display = "none";
		CBMCheck=false;
	}
}
`
document.head.appendChild(CBMscript);


var musik='', musikArray = new Array(),
	backgroundArray = new Array(), background_ = '',
	colorsArray = new Array(), colorCatTable = '';
function CBMf(){
	var oldMusik = musikArray.length,
		oldBackground = backgroundArray.length,
		oldColor = colorsArray.length;
	//музыка
	var audioNb = document.getElementsByTagName("audio"), audio = '<table>';

for(var a=0;a<audioNb.length;a++){
	var musikCheck = true;
	for(var m=0;m<musikArray.length;m++){
		if(audioNb[a].src==musikArray[m]){
			musikCheck=false;
		}
	}
	if(musikCheck&&audioNb[a].src!="https://catwar.su/cw3/"){
		musik += '<tr><td><audio src="'+audioNb[a].src+'"></td><td>'+audioNb[a].src+'</td></tr>';
		musikArray[musikArray.length]=audioNb[a].src;
	}
}
if(musik==''&&musikArray.length==0){
	musik='<tr><td>Музыки нет!</td></tr>';
}
audio+=musik+'</table>';
	if(musikArray.length!=oldMusik||musik=='<tr><td>Музыки нет!</td></tr>'){
	document.getElementById("audio").innerHTML=audio;
	}

	var backgrounds = '<table>',
	background = document.getElementById("cages_div").style.backgroundImage,
	backgroundCheck = true;

	background = 'https://catwar.su/cw3/'+background.slice(5,background.length-2); //исправление ссылки

	for(var b=0;b<backgroundArray.length;b++){
		if(background==backgroundArray[b]){
			backgroundCheck=false;
		}
	}
	if(backgroundCheck){
		background_ += '<tr><td><img src="'+background+'" style="height:50px; width:50px"></td><td>'+background+'</td></tr>';
		backgroundArray[backgroundArray.length]=background;
	}
	backgrounds += background_ + '</table>';
	if(backgroundArray.length!=oldBackground){
	document.getElementById("background").innerHTML=backgrounds;
	}
	var color = document.getElementsByClassName("d"),
	colorTable = '<table>';
for(var c=0;c<color.length;c++){
	var colorCheck = true,
		colorBackgroundImage = 'https://catwar.su'+color[c].style.backgroundImage.slice(5,color[c].style.backgroundImage.length-2),									//окрас
		colorCatName = color[c].parentNode.parentNode.childNodes[6].childNodes[0].innerText;	//имя кота

	for(var cc=0;cc<colorsArray.length;cc++){
		if(colorBackgroundImage==colorsArray[cc]){
			colorCheck=false;
		}
	}
	if(colorCheck){
		colorsArray[colorsArray.length] = colorBackgroundImage;
		colorCatTable += '<tr><td><img src="'+colorBackgroundImage+'" style="height:75px;width:50px"></td><td><b>'+colorCatName+'</b></td><td>'+colorBackgroundImage+'</td></tr>';
	}
}
colorTable += colorCatTable+'</table>';
if(colorsArray.length!=oldColor){
document.getElementById("color").innerHTML = colorTable;
}
}
var CBM = document.createElement("li");
CBM.innerHTML = '<img src="https://serolapy.github.io/CBM/img/CBM.png" onclick = "onCBM()" style="height:70px; width:70px; cursor:pointer">';
CBM.class="itemInMouth";
document.getElementById("itemList").appendChild(CBM);


setInterval(CBMf, 10000);
CBMf();
}