Ivypoolflame / Мод на КО CatWar

// ==UserScript==
// @name         Мод на КО CatWar
// @version      1.1
// @description  -
// @author       Искропламя
// @include       https://alwiess.github.io/
// @license      MIT
// @include        https://catwar.su/cw3/kns
// ==/UserScript==

var styles = `
    #btn:hover {
        color: #0074c7;
    }
`
var styleSheet = document.createElement("style")
styleSheet.innerText = styles
document.head.appendChild(styleSheet)

const byt = document.createElement('div');
var sky = document.querySelector('body');
var ky = document.querySelector('#random');
var t = document.querySelector('#byt');
byt.id = 'btn'
byt.setAttribute('style', 'text-decoration: underline; padding: 3px; cursor: pointer; display: flex; justify-content: center; align-items: center; margin-bottom: 3px;');
byt.textContent = 'Записать код в список окрасов'
ky.before(byt);
const v_field = document.createElement('textarea');
v_field.setAttribute('placeholder', 'Можешь писать сюда коды окрасов и они сохранятся после обновления страницы. Но только в этом браузере и на этом компе. Осторожнее.');
v_field.style.height = '100px';
v_field.style.top = '600px';
v_field.id = 'comment'
sky.appendChild(v_field);
var elements = document.querySelectorAll('textarea');

function checkValidity() {};
for (var i = 0; i < elements.length; i++) {
  (function (element) {
    var id = element.getAttribute('id');
    element.value = localStorage.getItem(id);
    element.onchange = function () {
      localStorage.setItem(id, element.value);
      checkValidity();
    };
    element.onpaste = function () {
      localStorage.setItem(id, element.value);
      checkValidity();
    };
  })(elements[i]);
}

document.getElementById("btn").addEventListener("click", function () {
  var start_inp = document.getElementById("code");
  var finish_inp = document.getElementById("comment");
  finish_inp.value = finish_inp.value + '       ' + start_inp.value;
  var element = document.querySelector('#comment');
  var id = element.getAttribute('id');
  localStorage.setItem(id, element.value);
  checkValidity();

});

var styls = `
    body {
        background-color: #060606;
        color: #525252;
    }
    #blocks {
        background-color: #000000;
        color: #525252;
    }
    a {
        color: #525252;
    }
    input, select, .btn-cns {
        background-color: #6c6c6c !important;
    }
    ::-webkit-input-placeholder {
        color: #b7b7b7;
        opacity: 0.5;
    }
    ::-webkit-scrollbar-thumb {
    background-color: #b7b7b7;
}

    ::-webkit-scrollbar-track {
    background-color: #000000;
}

textarea {
    box-sizing: border-box;
    background-color: #000;
    color: #fff;
}
textarea:focus {
    background-color: #333;
    color: #fff;
    border: 1px solid #000;
}

`
var ssdtyleSheet = document.createElement("style")
ssdtyleSheet.innerText = styls
document.head.appendChild(ssdtyleSheet)

//1.1
var start_inp = document.getElementById("code");

var c = function lindk() {
  let c = 'https://catwar.su/compositeByCode?code=' + start_inp.value + '&amp;act=0';
  lindk()
  return c;
}
var link = document.createElement('textarea');
link.setAttribute('id', 'sdds');
link.setAttribute('style', 'display: none;');
sky.appendChild(link);
console.log(link.value)
const bu = document.createElement('button');
bu.id = 'by'
bu.setAttribute('style', 'text-decoration: underline; padding: 3px; cursor: pointer; display: flex; justify-content: center; align-items: center; margin-bottom: 3px;');
let f = document.querySelectorAll('btn-kns copy');
bu.textContent = 'Создать ссылку на окрас'
sky.append(bu);
var isMenuShow = false;
document.querySelector("#by").onclick = function copyCode() {
  const str = document.getElementById('sdds').innerHTML;
  let c = 'https://catwar.su/compositeByCode?code=' + start_inp.value + '&amp;act=0';
  let docc = c.replace('amp;', ' ')
  link.innerHTML = docc;
  const el = document.createElement('textarea');
  el.value = docc;
  el.setAttribute('readonly', '');
  el.style.position = 'absolute';
  el.style.eft = '-9999px';
  document.body.appendChild(el);
  link.setAttribute('style', 'display: none;');

  if (isMenuShow) {
    bu.textContent = 'Создать ссылку на окрас'
    isMenuShow = false;
    el.select();
    document.execCommand('copy');
    document.body.removeChild(el);
    alert(`Copied: ${str}`);
    link.setAttribute('style', 'display: none;');
  }
  else {
    bu.textContent = 'Скопировать ссылку на окрас'
    isMenuShow = true;
    link.setAttribute('style', 'display: none;');
  }
};