- 将所有字替换成“听不懂思密达”:
function replaceTextWithTingbudongsimida(){const allElements=document.querySelectorAll('*');for(let element of allElements){if(element.tagName==='SCRIPT'||element.tagName==='STYLE'){continue;}for(let node of element.childNodes){if(node.nodeType===Node.TEXT_NODE){node.nodeValue='听不懂思密达';}}}}replaceTextWithTingbudongsimida();- 删除所有字:
function deleteAllText(){const allElements=document.querySelectorAll('*');for(let element of allElements){if(element.tagName==='SCRIPT'||element.tagName==='STYLE'){continue;}for(let node of element.childNodes){if(node.nodeType===Node.TEXT_NODE){node.nodeValue='';}}}}deleteAllText();- 摇晃动画“鼠标放上去试试”:
const element=document.createElement('div');element.textContent='鼠标放上去试试';element.style.position='fixed';element.style.top='50%';element.style.left='50%';element.style.transform='translate(-50%, -50%)';element.style.width='200px';element.style.height='200px';element.style.lineHeight='200px';element.style.textAlign='center';document.body.appendChild(element);element.style.transition='transform 0.5s';element.onmouseover=()=>{element.style.transform='scale(1.2) rotate(5deg)';};element.onmouseout=()=>{element.style.transform='scale(1) rotate(-5deg)';};加强版:
const element=document.createElement('div');element.textContent='鼠标放上去试试';element.style.position='fixed';element.style.top='50%';element.style.left='50%';element.style.transform='translate(-50%, -50%)';element.style.width='200px';element.style.height='200px';element.style.lineHeight='200px';element.style.textAlign='center';document.body.appendChild(element);let isMouseOver=false;element.style.transition='transform 0.5s, color 0.5s';element.onmouseover=()=>{isMouseOver=true;animate();};element.onmouseout=()=>{isMouseOver=false;};function animate(){if(isMouseOver){element.style.transform='scale(1.2) rotate(5deg)';element.style.color=getRandomColor();setTimeout(animate,500);}else{element.style.transform='scale(1) rotate(-5deg)';element.style.color='';}}function getRandomColor(){const letters='0123456789ABCDEF';let color='#';for(let i=0;i<6;i++){color+=letters[Math.floor(Math.random()*16)];}return color;}- 随机网页背景:
document.body.style.backgroundColor='#'+Math.floor(Math.random()*16777215).toString(16);- 粒子动画(输入完往下翻):
const canvas=document.createElement('canvas');document.body.appendChild(canvas);const ctx=canvas.getContext('2d');canvas.width=window.innerWidth;canvas.height=window.innerHeight;let particles=[];function createParticle(x,y,color){return{x:x,y:y,color:color,radius:3,speedX:Math.random()*2-1,speedY:Math.random()*2-1};}function draw(){ctx.clearRect(0,0,canvas.width,canvas.height);particles.forEach(particle=>{ctx.beginPath();ctx.arc(particle.x,particle.y,particle.radius,0,Math.PI*2);ctx.fillStyle=particle.color;ctx.fill();particle.x+=particle.speedX;particle.y+=particle.speedY;if(particle.x>canvas.width||particle.x<0){particle.speedX=-particle.speedX;}if(particle.y>canvas.height||particle.y<0){particle.speedY=-particle.speedY;}});requestAnimationFrame(draw);}canvas.addEventListener('mousemove',function(e){const color=`rgb(${Math.random()*255},${Math.random()*255},${Math.random()*255})`;const particle=createParticle(e.clientX,e.clientY,color);particles.push(particle);});draw();- 将页面中所有段落的文字内容反转:
Array.from(document.querySelectorAll('p')).forEach(p=>{p.textContent=p.textContent.split('').reverse().join('');});加强版:
var textNodes=[];function getTextNodes(node){if(node.nodeType===Node.TEXT_NODE){textNodes.push(node);}else{var children=node.childNodes;for(var i=0;i<children.length;i++){getTextNodes(children[i]);}}}getTextNodes(document.body);for(var i=0;i<textNodes.length;i++){var textNode=textNodes[i];var text=textNode.textContent;var reversedText=text.split('').reverse().join('');textNode.textContent=reversedText;}- 手写签名板:
const canvas=document.createElement('canvas');canvas.width=1000;canvas.height=1500;canvas.style.border='2px solid #000';document.body.appendChild(canvas);const ctx=canvas.getContext('2d');let isDrawing=false;let lastX=0;let lastY=0;canvas.addEventListener('mousedown',(e)=>{isDrawing=true;[lastX,lastY]=[e.offsetX,e.offsetY];});canvas.addEventListener('mousemove',(e)=>{if(isDrawing){ctx.beginPath();ctx.moveTo(lastX,lastY);ctx.lineTo(e.offsetX,e.offsetY);ctx.strokeStyle='#000';ctx.lineWidth=2;ctx.stroke();[lastX,lastY]=[e.offsetX,e.offsetY];}});canvas.addEventListener('mouseup',()=>{isDrawing=false;});canvas.addEventListener('mouseout',()=>{isDrawing=false;});8.冈易特效(全部替换成*):
function replaceSingleCharacters(node){if(node.nodeType===Node.TEXT_NODE){node.nodeValue=node.nodeValue.replace(/./g,"*");}else if(node.nodeType===Node.ELEMENT_NODE){for(let i=0;i<node.childNodes.length;i++){replaceSingleCharacters(node.childNodes[i]);}}}replaceSingleCharacters(document.body);任意编辑:
document.body.contentEditable = 'true';