Заспамить копипастеров, не защита от копирования, а именно отбить желание копировать описание товаров и статей
<script>
(function(){
// ===== НАСТРОЙКИ =====
const TARGET_SELECTOR = '.message-body .mb-3';
// ===== УТИЛИТЫ =====
function randomString(len = 8) {
return Math.random().toString(36).substring(2, 2 + len);
}
function randomNumbers(len = 6) {
let out = '';
for (let i = 0; i < len; i++) {
out += Math.floor(Math.random() * 10);
}
return out;
}
function encodeZeroWidth(str) {
let binary = '';
for (let i = 0; i < str.length; i++) {
binary += str.charCodeAt(i).toString(2).padStart(8, '0');
}
return binary
.replace(/0/g, '\u200B')
.replace(/1/g, '\u200C');
}
function injectHidden(text, mark) {
let mid = Math.floor(text.length / 2);
return text.slice(0, mid) + mark + text.slice(mid);
}
function insertRandomNumbersInside(text) {
// вставляем рандомные числа в скобках между словами
return text.split(' ').map(word => {
const rnd = `[${randomNumbers(3)}]`; // всегда новые числа
return word + rnd;
}).join(' ');
}
function wrapWithRandomNumbers(text) {
const left = `[${randomNumbers(4)}]`; // всегда новые числа слева
const right = `{${randomNumbers(5)}}`; // всегда новые числа справа
const inside = insertRandomNumbersInside(text); // новые числа внутри текста
return left + inside + right;
}
// ===== COPY ПЕРЕХВАТ =====
document.addEventListener("copy", function (e) {
const selection = window.getSelection();
if (!selection || selection.rangeCount === 0) return;
const url = window.location.href;
const domain = window.location.hostname;
const title = document.querySelector('h1')?.innerText || '';
const hiddenMark = encodeZeroWidth("SRC:" + domain + "|" + url);
const container = document.createElement("div");
for (let i = 0; i < selection.rangeCount; i++) {
container.appendChild(selection.getRangeAt(i).cloneContents());
}
let html = container.innerHTML;
// --- уникальный ID для каждого копирования ---
const uid = randomString(10) + "-" + randomNumbers(10);
// --- каждый раз новый noisy текст с числами ---
const noisyText = wrapWithRandomNumbers('Источник копирования описания электросамокатов:');
const block = `
<span data-copy="true" style="font-size:12px;opacity:0.6;">
${noisyText} <a href="${url}">${title}</a>
<span style="display:none;">ID:${uid}</span>
</span>
`;
// --- вставка блока после каждого подходящего тега ---
html = html.replace(/<\/(p|li|h1|h2|h3)>/gi, function(match) {
return match + wrapWithRandomNumbers(block); // оборачиваем каждый блок новыми числами
});
// --- TEXT версия ---
let textContent = selection.toString();
textContent = injectHidden(textContent, hiddenMark);
const plainText =
textContent +
"\n\nИсточник: " + title +
"\n" + url +
"\nID:" + uid +
"\n[" + domain + "]";
e.clipboardData.setData("text/html", html);
e.clipboardData.setData("text/plain", plainText);
e.preventDefault();
});
// ===== АНТИ-ПАРСЕР (мусор в DOM) =====
document.addEventListener("DOMContentLoaded", function () {
const container = document.querySelector(TARGET_SELECTOR);
if (!container) return;
const blocks = container.querySelectorAll('p, li');
blocks.forEach(el => {
const junk = document.createElement("span");
junk.style.display = "none";
junk.textContent = "J" + randomNumbers(12);
el.appendChild(junk);
});
});
})();
</script>