Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function () {
- const PREFIX = "cp-";
- if (document.getElementById(PREFIX + "color-picker-hud")) return;
- const TARGET_ELEMENTS = {
- 'Chatbox Background': { selector: '#chatbox', type: 'rgba', alpha: 0.8 },
- 'Chatbox Text': { selector: '#chatbox', type: 'color' },
- 'Chat Input Background': { selector: '#chatmsg', type: 'hex' },
- 'Chat Input Text': { selector: '#chatmsg', type: 'color' },
- 'Send Button Background': { selector: '#sendmsg', type: 'hex' },
- 'Send Button Text': { selector: '#sendmsg', type: 'color' },
- 'Info Text Background': { selector: '.infotext', type: 'rgba', alpha: 0.8 },
- 'Info Text Color': { selector: '.infotext span', type: 'color' },
- 'HUD Buttons Background': { selector: '.buttons .infobtn', type: 'hex' },
- 'HUD Buttons Text': { selector: '.buttons .infobtn', type: 'color' },
- 'Usermenu Background': { selector: '#usermenu', type: 'rgba', alpha: 0.95 },
- 'Options Menu Background': { selector: '#optionsmenu', type: 'rgba', alpha: 0.95 },
- 'Options Text': { selector: '#optionsmenu, #optionsmenu label, #optionsmenu h1, #optionsmenu span', type: 'color' },
- 'Sidebar Background': { selector: '.sidething', type: 'rgba', alpha: 0.95 },
- 'Swatches Background': { selector: '#colourlist .colour', type: 'hex' }
- };
- const chatbox = document.getElementById('chatbox');
- const checkbox = document.getElementById('darkChat');
- const rainbowTagsCheckbox = document.getElementById("rainbowTag");
- let darkMode = localStorage.getItem('darkMode') === 'true';
- let rainbowTags = localStorage.getItem('rainbowTags') === 'true';
- checkbox.checked = darkMode;
- rainbowTagsCheckbox.checked = rainbowTags;
- function storeOriginalColor(el) {
- if (!el.dataset.originalColor) {
- const style = window.getComputedStyle(el);
- el.dataset.originalColor = style.backgroundColor || style.color || '';
- }
- }
- function applyMode(el) {
- storeOriginalColor(el);
- if (!el.dataset.originalColor) return;
- const original = el.dataset.originalColor.replace(/\s+/g, '').toLowerCase();
- if (original === 'rgb(0,0,0)') el.style.color = darkMode ? '#fff' : '#000';
- else if (original === 'rgb(255,255,255)') el.style.color = darkMode ? '#000' : '#fff';
- }
- function updateChatboxColors() {
- chatbox.style.backgroundColor = darkMode ? '#000' : '#fff';
- chatbox.style.color = darkMode ? '#fff' : '#000';
- chatbox.querySelectorAll('*').forEach(applyMode);
- chatbox.classList[rainbowTagsCheckbox.checked ? "add" : "remove"]("animatedTags");
- }
- checkbox.addEventListener('change', () => {
- darkMode = checkbox.checked;
- localStorage.setItem('darkMode', darkMode);
- updateChatboxColors();
- });
- rainbowTagsCheckbox.addEventListener('change', () => {
- rainbowTags = rainbowTagsCheckbox.checked;
- localStorage.setItem('rainbowTags', rainbowTags);
- updateChatboxColors();
- });
- const observer = new MutationObserver(mutations => {
- mutations.forEach(m => {
- m.addedNodes.forEach(node => {
- if (node.nodeType === 1) {
- node.classList.add('fade-in');
- applyMode(node);
- node.querySelectorAll('*').forEach(applyMode);
- requestAnimationFrame(() => node.classList.add('show'));
- }
- });
- });
- });
- observer.observe(chatbox, { childList: true, subtree: true });
- updateChatboxColors();
- if (!window.iro) {
- const script = document.createElement("script");
- script.src = "https://cdn.jsdelivr.net/npm/@jaames/iro@5";
- script.onload = initHUD;
- document.head.appendChild(script);
- } else {
- initHUD();
- }
- function initHUD() {
- const hudHTML = `
- <div id="${PREFIX}color-picker-hud">
- <div id="${PREFIX}hud-header">
- 🌈 Color Customizer
- <button id="${PREFIX}hud-close">✖</button>
- </div>
- <div id="${PREFIX}picker"></div>
- <input id="${PREFIX}hex-input" type="text" value="#00FF00" placeholder="#RRGGBB" style="margin:0 10px 10px; width:calc(100%-20px); padding:5px; background:black; color:#0f0; border:1px solid #0f0; font-family:monospace;">
- <button id="${PREFIX}eyedropperBtn">🎯 Eyedropper</button>
- <select id="${PREFIX}target">
- ${Object.keys(TARGET_ELEMENTS).map(t => `<option value="${t}">${t}</option>`).join('')}
- </select>
- <div id="${PREFIX}preview">#00FF00</div>
- <button id="${PREFIX}apply-color-btn">Apply Color</button>
- <button id="${PREFIX}apply-all-btn">Apply to All Targets</button>
- <button id="${PREFIX}reset-btn">Reset All Colors</button>
- </div>
- `;
- document.body.insertAdjacentHTML("beforeend", hudHTML);
- const style = document.createElement("style");
- style.textContent = `
- #${PREFIX}color-picker-hud { position: fixed; top:60px; right:20px; width:280px; background:#111; border:2px solid #0f0; border-radius:12px; box-shadow:0 0 20px lime; font-family:monospace; z-index:999999; resize:both; overflow:auto; padding-bottom:10px; }
- #${PREFIX}hud-header { background:#030; padding:10px; cursor:move; font-weight:bold; display:flex; justify-content:space-between; color:#0f0; user-select:none; }
- #${PREFIX}hud-close { background:none; border:none; color:red; cursor:pointer; }
- #${PREFIX}picker { padding:10px; display:flex; justify-content:center; }
- #${PREFIX}eyedropperBtn { margin:0 10px 10px; width:calc(100%-20px); padding:6px; background:#222; color:#0f0; border:1px solid #0f0; cursor:pointer; font-weight:bold; }
- #${PREFIX}target { margin:0 10px 10px; width:calc(100%-20px); background:black; color:#0f0; border:1px solid #0f0; padding:5px; }
- #${PREFIX}preview { margin:0 10px 10px; height:24px; border:1px solid #0f0; text-align:center; line-height:24px; font-weight:bold; }
- #${PREFIX}apply-color-btn, #${PREFIX}apply-all-btn { margin:0 10px 10px; width:calc(100%-20px); padding:5px; background:#0f0; color:#000; border:none; font-weight:bold; cursor:pointer; }
- #${PREFIX}apply-color-btn:hover, #${PREFIX}apply-all-btn:hover { background:#0c0; }
- #${PREFIX}reset-btn { margin:0 10px 10px; width:calc(100%-20px); padding:5px; background:#f00; color:#fff; border:none; font-weight:bold; cursor:pointer; }
- #${PREFIX}reset-btn:hover { background:#c00; }
- `;
- document.head.appendChild(style);
- const hud = document.getElementById(PREFIX + "color-picker-hud");
- const picker = new iro.ColorPicker("#" + PREFIX + "picker", {
- width: 200,
- color: "#00FF00",
- layout: [{ component: iro.ui.Wheel }, { component: iro.ui.Slider, options: { sliderType: "value" }}]
- });
- const targetSelect = document.getElementById(PREFIX + "target");
- const preview = document.getElementById(PREFIX + "preview");
- const applyBtn = document.getElementById(PREFIX + "apply-color-btn");
- const applyAllBtn = document.getElementById(PREFIX + "apply-all-btn");
- const eyedropperBtn = document.getElementById(PREFIX + "eyedropperBtn");
- const hexInput = document.getElementById(PREFIX + "hex-input");
- const resetBtn = document.getElementById(PREFIX + "reset-btn");
- const activeColors = {};
- Object.keys(TARGET_ELEMENTS).forEach(t => activeColors[t] = "#00FF00");
- let pickedColor = picker.color.hexString;
- // ------------------------
- // Picker → Preview & Input
- // ------------------------
- picker.on('color:change', color => {
- pickedColor = color.hexString;
- preview.textContent = pickedColor;
- preview.style.backgroundColor = pickedColor;
- hexInput.value = pickedColor;
- });
- // ------------------------
- // Hex Input → Picker
- // ------------------------
- hexInput.addEventListener('input', () => {
- const val = hexInput.value.trim();
- if (/^#([0-9A-Fa-f]{6})$/.test(val)) {
- picker.color.set(val);
- }
- });
- function applyColorToTarget(targetName) {
- const { selector, type, alpha } = TARGET_ELEMENTS[targetName];
- document.querySelectorAll(selector).forEach(el => {
- storeOriginalColor(el);
- if (type === 'hex') el.style.backgroundColor = pickedColor;
- else if (type === 'color') el.style.color = pickedColor;
- else if (type === 'rgba') {
- const rgb = new iro.Color(pickedColor).rgb;
- el.style.backgroundColor = `rgba(${rgb.r},${rgb.g},${rgb.b},${alpha})`;
- }
- });
- activeColors[targetName] = pickedColor;
- }
- applyBtn.addEventListener('click', () => applyColorToTarget(targetSelect.value));
- applyAllBtn.addEventListener('click', () => Object.keys(TARGET_ELEMENTS).forEach(applyColorToTarget));
- targetSelect.addEventListener('change', () => picker.color.set(activeColors[targetSelect.value]));
- // ------------------------
- // Reset All Colors
- // ------------------------
- function resetAllColors() {
- Object.keys(TARGET_ELEMENTS).forEach(targetName => {
- const { selector } = TARGET_ELEMENTS[targetName];
- document.querySelectorAll(selector).forEach(el => {
- if (el.dataset.originalColor) {
- if (TARGET_ELEMENTS[targetName].type === 'color') el.style.color = el.dataset.originalColor;
- else el.style.backgroundColor = el.dataset.originalColor;
- }
- });
- activeColors[targetName] = "#00FF00";
- });
- picker.color.set("#00FF00");
- hexInput.value = "#00FF00";
- preview.textContent = "#00FF00";
- preview.style.backgroundColor = "#00FF00";
- }
- resetBtn.addEventListener('click', resetAllColors);
- // ------------------------
- // Native EyeDropper API
- // ------------------------
- eyedropperBtn.addEventListener("click", async () => {
- if (!window.EyeDropper) {
- alert("Your browser does not support the EyeDropper API.");
- return;
- }
- try {
- const eyeDropper = new EyeDropper();
- const result = await eyeDropper.open();
- picker.color.set(result.sRGBHex);
- } catch (err) {
- console.log("Eyedropper canceled or failed:", err);
- }
- });
- // ------------------------
- // Close HUD
- // ------------------------
- document.getElementById(PREFIX + "hud-close").onclick = () => {
- hud.remove();
- style.remove();
- };
- makeDraggable(hud, document.getElementById(PREFIX + "hud-header"));
- }
- function makeDraggable(elmnt, handle) {
- let x = 0, y = 0, dx = 0, dy = 0;
- handle.onmousedown = e => {
- e.preventDefault();
- dx = e.clientX; dy = e.clientY;
- document.onmousemove = drag;
- document.onmouseup = () => document.onmousemove = null;
- };
- function drag(e) {
- e.preventDefault();
- x = dx - e.clientX; y = dy - e.clientY;
- dx = e.clientX; dy = e.clientY;
- elmnt.style.top = (elmnt.offsetTop - y) + "px";
- elmnt.style.left = (elmnt.offsetLeft - x) + "px";
- }
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment