// ==UserScript==
// @name Base64 Decoder Tool (Minimized)
// @namespace http://tampermonkey.net/
// @version 1.5
// @description Adds a minimized, clickable Base64 decoding icon. On click, it pastes clipboard content if visible. Decoded URLs are clickable.
// @author ChatGPT Expert
// @match https://kone.gg/*
// @exclude https://kone.gg/
// @include https://kone.gg/s/ainovel*
// @grant none
// @run-at document-idle
// ==/UserScript==
(function() {
'use strict';
// 해당 스크립트가 'ainovel' 서브 페이지에서만 실행되도록 재차 확인
if (!window.location.href.includes('kone.gg/s/ainovel')) {
return;
}
// --- 1. Base64 디코딩 함수 ---
function base64Decode(encodedString) {
try {
const binaryString = atob(encodedString.trim());
const utf8String = decodeURIComponent(
Array.prototype.map.call(binaryString, (c) => {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join('')
);
return utf8String;
} catch (e) {
return 'ERROR: Invalid Base64 string.';
}
}
// --- 2. URL 유효성 검사 함수 ---
function isValidUrl(string) {
try {
const url = new URL(string);
return url.protocol === "http:" || url.protocol === "https:";
} catch (e) {
return false;
}
}
// --- 3. 디코딩 결과를 UI에 반영하는 함수 ---
function updateDecodedOutput(decodedString) {
resultField.value = decodedString;
linkOutput.innerHTML = '';
// 디코딩 결과가 유효한 URL인지 확인
if (decodedString && decodedString.length < 2048 && isValidUrl(decodedString)) {
const link = document.createElement('a');
link.href = decodedString;
link.target = '_blank';
link.textContent = '결과 링크 새 탭에서 열기 ➔';
link.style.cssText = `
color: #e5c07b;
text-decoration: underline;
cursor: pointer;
font-weight: bold;
display: block;
margin: 5px 0;
`;
linkOutput.appendChild(link);
resultField.value = "디코딩 성공! 위에 생성된 링크를 클릭하세요.";
resultField.style.color = '#98c379';
} else {
resultField.style.color = '#d19a66';
}
if (decodedString.startsWith('ERROR')) {
resultField.style.color = '#e06c75';
}
}
function performDecoding() {
const encoded = inputField.value.trim();
if (encoded) {
const decoded = base64Decode(encoded);
updateDecodedOutput(decoded);
} else {
resultField.value = '디코딩 결과';
linkOutput.innerHTML = '';
resultField.style.color = '#d19a66';
}
}
// --- 4. UI 요소 생성 및 스타일링 (이전과 동일) ---
const container = document.createElement('div');
container.id = 'b64-decoder-popup';
container.style.cssText = `
position: fixed;
top: 50px;
left: 50%;
transform: translateX(-50%);
z-index: 99998;
padding: 10px;
background: rgba(40, 44, 52, 0.98);
border: 2px solid #61afef;
border-radius: 8px;
box-shadow: 0 5px 15px rgba(0, 0, 0, 0.5);
width: 90%;
max-width: 300px;
color: #abb2bf;
display: none;
flex-direction: column;
gap: 8px;
`;
const title = document.createElement('h4');
title.textContent = 'Base64 Decoder';
title.style.cssText = `
margin: 0;
color: #98c379;
text-align: center;
font-size: 1.1em;
padding-bottom: 5px;
border-bottom: 1px dashed #5c6370;
`;
const inputField = document.createElement('textarea');
inputField.placeholder = 'Base64 입력...';
inputField.style.cssText = `
width: 100%;
min-height: 40px;
padding: 5px;
border: 1px solid #5c6370;
border-radius: 4px;
background: #20232a;
color: #abb2bf;
box-sizing: border-box;
resize: vertical;
font-family: monospace;
font-size: 0.85em;
`;
const linkOutput = document.createElement('div');
linkOutput.id = 'b64-link-output';
linkOutput.style.cssText = `
min-height: 1.5em;
text-align: center;
margin-top: -5px;
font-size: 0.9em;
`;
const resultField = document.createElement('textarea');
resultField.readOnly = true;
resultField.placeholder = '디코딩 결과';
resultField.style.cssText = `
width: 100%;
min-height: 60px;
padding: 5px;
border: 1px solid #5c6370;
border-radius: 4px;
background: #20232a;
color: #d19a66;
box-sizing: border-box;
resize: vertical;
font-family: monospace;
font-size: 0.85em;
`;
const toggleIcon = document.createElement('button');
toggleIcon.id = 'b64-toggle-icon';
toggleIcon.innerHTML = '⎂';
toggleIcon.title = 'Base64 디코더 열기/닫기 (클립보드 붙여넣기)';
toggleIcon.style.cssText = `
position: fixed;
top: 5px;
left: 50%;
transform: translateX(-50%);
z-index: 99999;
width: 40px;
height: 40px;
border-radius: 50%;
background: #61afef;
color: white;
border: 2px solid #569cd6;
cursor: pointer;
font-size: 1.2em;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
transition: background 0.2s, transform 0.2s;
`;
toggleIcon.onmouseover = () => toggleIcon.style.background = '#569cd6';
toggleIcon.onmouseout = () => toggleIcon.style.background = '#61afef';
// --- 5. 요소 배치 및 이벤트 리스너 ---
container.appendChild(title);
container.appendChild(inputField);
container.appendChild(linkOutput);
container.appendChild(resultField);
document.body.appendChild(toggleIcon);
document.body.appendChild(container);
inputField.addEventListener('input', performDecoding);
inputField.addEventListener('change', performDecoding);
// --- 6. 토글 및 클립보드 기능 ---
let isVisible = localStorage.getItem('b64-decoder-visible') === 'true';
if (isVisible) {
container.style.display = 'flex';
toggleIcon.style.background = '#e06c75';
}
toggleIcon.addEventListener('click', async () => {
// 1. 상태 토글
isVisible = !isVisible;
if (isVisible) {
// 2. 패널 열기
container.style.display = 'flex';
toggleIcon.style.background = '#e06c75';
localStorage.setItem('b64-decoder-visible', 'true');
// 3. 클립보드에서 내용 가져오기 및 붙여넣기 (비동기)
if (navigator.clipboard && navigator.clipboard.readText) {
try {
const clipboardText = await navigator.clipboard.readText();
// 클립보드 내용이 Base64 문자열로 보이는 경우에만 자동 붙여넣기
// 너무 짧거나 길지 않고, 특수 문자가 적절히 포함되어야 함.
if (clipboardText && clipboardText.length > 5 && clipboardText.length < 5000) {
inputField.value = clipboardText.trim();
performDecoding();
inputField.focus();
inputField.select(); // 전체 선택하여 바로 덮어쓰기 쉽게 함
} else {
inputField.focus();
}
} catch (err) {
console.error('클립보드 접근 거부 또는 오류:', err);
inputField.placeholder = '클립보드 접근 권한이 필요합니다.';
inputField.focus();
}
} else {
console.warn("브라우저가 navigator.clipboard를 지원하지 않거나 보안 문제로 접근이 거부되었습니다.");
inputField.focus();
}
} else {
// 4. 패널 닫기
container.style.display = 'none';
toggleIcon.style.background = '#61afef';
localStorage.setItem('b64-decoder-visible', 'false');
}
});
})();
