troilus
84 天前
修改为,可以选中解码结果:
```
javascript:(function(){
function decodeBase64(str) {
try {
return decodeURIComponent(atob(str).split('').map(function(c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
} catch (e) {
return "解码失败: " + e.message;
}
}
function getSelectedText() {
return window.getSelection().toString().trim();
}
function createSelectablePopup(content) {
var popup = document.createElement('div');
popup.style.cssText = `
position: fixed;
top: 20%;
left: 20%;
width: 60%;
max-height: 60%;
background: white;
border: 1px solid #ccc;
padding: 20px;
box-shadow: 0 0 10px rgba(0,0,0,0.5);
z-index: 1000;
overflow: auto;
white-space: pre-wrap;
word-wrap: break-word;
`;
var closeButton = document.createElement('button');
closeButton.textContent = '关闭';
closeButton.style.cssText = `
position: absolute;
top: 10px;
right: 10px;
`;
closeButton.onclick = function() {
document.body.removeChild(popup);
};
var contentDiv = document.createElement('div');
contentDiv.textContent = content;
contentDiv.style.cssText = `
margin-top: 30px;
user-select: text;
`;
popup.appendChild(closeButton);
popup.appendChild(contentDiv);
document.body.appendChild(popup);
}
var selectedText = getSelectedText();
if (selectedText) {
var decoded = decodeBase64(selectedText);
createSelectablePopup("解码结果:\n" + decoded);
} else {
alert("请先选择要解码的 Base64 文本");
}
})();
```