同步完整源码 - 2026-05-24
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<style>
|
||||
body, html { margin: 0; padding: 0; }
|
||||
@keyframes move {
|
||||
from { marign-left: 0; }
|
||||
to { margin-left: 100px; }
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
function addButton() {
|
||||
const button = document.createElement('button');
|
||||
button.textContent = 'Click me';
|
||||
button.style.animation = '3s linear move';
|
||||
button.style.animationIterationCount = 'infinite';
|
||||
button.addEventListener('click', () => window.clicked = true);
|
||||
document.body.appendChild(button);
|
||||
}
|
||||
|
||||
function stopButton(remove) {
|
||||
const button = document.querySelector('button');
|
||||
button.style.marginLeft = button.getBoundingClientRect().left + 'px';
|
||||
button.style.animation = '';
|
||||
if (remove)
|
||||
button.remove();
|
||||
}
|
||||
|
||||
let x = 0;
|
||||
function jump() {
|
||||
x += 300;
|
||||
const button = document.querySelector('button');
|
||||
button.style.marginLeft = x + 'px';
|
||||
}
|
||||
|
||||
function startJumping() {
|
||||
x = 0;
|
||||
const moveIt = () => {
|
||||
jump();
|
||||
requestAnimationFrame(moveIt);
|
||||
};
|
||||
setInterval(jump, 0);
|
||||
moveIt();
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Button test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="mouse-helper.js"></script>
|
||||
<button>Click target</button>
|
||||
<script>
|
||||
window.result = 'Was not clicked';
|
||||
window.offsetX = undefined;
|
||||
window.offsetY = undefined;
|
||||
window.pageX = undefined;
|
||||
window.pageY = undefined;
|
||||
window.shiftKey = undefined;
|
||||
window.pageX = undefined;
|
||||
window.pageY = undefined;
|
||||
window.bubbles = undefined;
|
||||
document.querySelector('button').addEventListener('click', e => {
|
||||
result = 'Clicked';
|
||||
offsetX = e.offsetX;
|
||||
offsetY = e.offsetY;
|
||||
pageX = e.pageX;
|
||||
pageY = e.pageY;
|
||||
shiftKey = e.shiftKey;
|
||||
bubbles = e.bubbles;
|
||||
cancelable = e.cancelable;
|
||||
composed = e.composed;
|
||||
}, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Selection Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<label for="agree">Remember Me</label>
|
||||
<input id="agree" type="checkbox">
|
||||
<script>
|
||||
window.result = {
|
||||
check: null,
|
||||
events: [],
|
||||
};
|
||||
|
||||
let checkbox = document.querySelector('input');
|
||||
|
||||
const events = [
|
||||
'change',
|
||||
'click',
|
||||
'dblclick',
|
||||
'input',
|
||||
'mousedown',
|
||||
'mouseenter',
|
||||
'mouseleave',
|
||||
'mousemove',
|
||||
'mouseout',
|
||||
'mouseover',
|
||||
'mouseup',
|
||||
];
|
||||
|
||||
for (let event of events) {
|
||||
checkbox.addEventListener(event, () => {
|
||||
if (['change', 'click', 'dblclick', 'input'].includes(event) === true) {
|
||||
result.check = checkbox.checked;
|
||||
}
|
||||
|
||||
result.events.push(event);
|
||||
}, false);
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>File upload test</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" multiple name="file1">
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>File upload test</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="file1">
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,12 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Folder upload test</title>
|
||||
</head>
|
||||
<body>
|
||||
<form action="/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="file1" webkitdirectory>
|
||||
<input type="submit">
|
||||
</form>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,91 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Interstitial test</title>
|
||||
</head>
|
||||
<body>
|
||||
<style>
|
||||
body {
|
||||
position: relative;
|
||||
}
|
||||
#target.removed {
|
||||
display: none;
|
||||
}
|
||||
#target.hidden {
|
||||
visibility: hidden;
|
||||
}
|
||||
#target:hover {
|
||||
background: yellow;
|
||||
}
|
||||
#interstitial {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 300px;
|
||||
height: 300px;
|
||||
border: 1px solid black;
|
||||
background: rgba(255, 180, 180);
|
||||
display: none;
|
||||
}
|
||||
#interstitial.visible {
|
||||
display: block;
|
||||
}
|
||||
#close {
|
||||
margin: 50px;
|
||||
}
|
||||
</style>
|
||||
<div><button id="target">Click me</button></div>
|
||||
<div id="aside">A place on the side to hover</div>
|
||||
<div id="interstitial">
|
||||
<div>This interstitial covers the button</div>
|
||||
<button id="close">Close the interstitial</button>
|
||||
</div>
|
||||
<script>
|
||||
const target = document.querySelector('#target');
|
||||
const interstitial = document.querySelector('#interstitial');
|
||||
const close = document.querySelector('#close');
|
||||
|
||||
target.addEventListener('click', () => {
|
||||
window.clicked = (window.clicked ?? 0) + 1;
|
||||
}, false);
|
||||
|
||||
close.addEventListener('click', () => {
|
||||
const closeInterstitial = () => {
|
||||
interstitial.classList.remove('visible');
|
||||
target.classList.remove('hidden');
|
||||
target.classList.remove('removed');
|
||||
};
|
||||
|
||||
if (interstitial.classList.contains('timeout'))
|
||||
setTimeout(closeInterstitial, 3000);
|
||||
else
|
||||
closeInterstitial();
|
||||
});
|
||||
|
||||
let timesToShow = 0;
|
||||
function setupAnnoyingInterstitial(event, times, capture) {
|
||||
timesToShow = times;
|
||||
const listener = () => {
|
||||
timesToShow--;
|
||||
interstitial.classList.add('visible');
|
||||
interstitial.getBoundingClientRect();
|
||||
if (!timesToShow && event !== 'none')
|
||||
target.removeEventListener(event, listener, capture === 'capture');
|
||||
};
|
||||
if (event === 'hide' || event === 'timeout') {
|
||||
target.classList.add('hidden');
|
||||
listener();
|
||||
if (event === 'timeout')
|
||||
interstitial.classList.add('timeout');
|
||||
} else if (event === 'remove') {
|
||||
target.classList.add('removed');
|
||||
listener();
|
||||
} else if (event === 'none') {
|
||||
listener();
|
||||
} else {
|
||||
target.addEventListener(event, listener, capture === 'capture');
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,42 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Keyboard test</title>
|
||||
</head>
|
||||
<body>
|
||||
<textarea></textarea>
|
||||
<script>
|
||||
window.result = "";
|
||||
let textarea = document.querySelector('textarea');
|
||||
textarea.focus();
|
||||
textarea.addEventListener('keydown', event => {
|
||||
log('Keydown:', event.key, event.code, event.which, modifiers(event));
|
||||
});
|
||||
textarea.addEventListener('keypress', event => {
|
||||
log('Keypress:', event.key, event.code, event.which, event.charCode, modifiers(event));
|
||||
});
|
||||
textarea.addEventListener('keyup', event => {
|
||||
log('Keyup:', event.key, event.code, event.which, modifiers(event));
|
||||
});
|
||||
function modifiers(event) {
|
||||
let m = [];
|
||||
if (event.altKey)
|
||||
m.push('Alt')
|
||||
if (event.ctrlKey)
|
||||
m.push('Control');
|
||||
if (event.shiftKey)
|
||||
m.push('Shift')
|
||||
return '[' + m.join(' ') + ']';
|
||||
}
|
||||
function log(...args) {
|
||||
console.log.apply(console, args);
|
||||
result += args.join(' ') + '\n';
|
||||
}
|
||||
function getResult() {
|
||||
let temp = result.trim();
|
||||
result = "";
|
||||
return temp;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,62 @@
|
||||
// This injects a box into the page that moves with the mouse;
|
||||
// Useful for debugging
|
||||
(function(){
|
||||
const box = document.createElement('div');
|
||||
box.classList.add('mouse-helper');
|
||||
const styleElement = document.createElement('style');
|
||||
styleElement.innerHTML = `
|
||||
.mouse-helper {
|
||||
pointer-events: none;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
background: rgba(0,0,0,.4);
|
||||
border: 1px solid white;
|
||||
border-radius: 10px;
|
||||
margin-left: -10px;
|
||||
margin-top: -10px;
|
||||
transition: background .2s, border-radius .2s, border-color .2s;
|
||||
}
|
||||
.mouse-helper.button-1 {
|
||||
transition: none;
|
||||
background: rgba(0,0,0,0.9);
|
||||
}
|
||||
.mouse-helper.button-2 {
|
||||
transition: none;
|
||||
border-color: rgba(0,0,255,0.9);
|
||||
}
|
||||
.mouse-helper.button-3 {
|
||||
transition: none;
|
||||
border-radius: 4px;
|
||||
}
|
||||
.mouse-helper.button-4 {
|
||||
transition: none;
|
||||
border-color: rgba(255,0,0,0.9);
|
||||
}
|
||||
.mouse-helper.button-5 {
|
||||
transition: none;
|
||||
border-color: rgba(0,255,0,0.9);
|
||||
}
|
||||
`;
|
||||
document.head.appendChild(styleElement);
|
||||
document.body.appendChild(box);
|
||||
document.addEventListener('mousemove', event => {
|
||||
box.style.left = event.pageX + 'px';
|
||||
box.style.top = event.pageY + 'px';
|
||||
updateButtons(event.buttons);
|
||||
}, true);
|
||||
document.addEventListener('mousedown', event => {
|
||||
updateButtons(event.buttons);
|
||||
box.classList.add('button-' + event.which);
|
||||
}, true);
|
||||
document.addEventListener('mouseup', event => {
|
||||
updateButtons(event.buttons);
|
||||
box.classList.remove('button-' + event.which);
|
||||
}, true);
|
||||
function updateButtons(buttons) {
|
||||
for (let i = 0; i < 5; i++)
|
||||
box.classList.toggle('button-' + i, buttons & (1 << i));
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,21 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Rotated button test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="mouse-helper.js"></script>
|
||||
<button onclick="clicked();">Click target</button>
|
||||
<style>
|
||||
button {
|
||||
transform: rotateY(180deg);
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
window.result = 'Was not clicked';
|
||||
function clicked() {
|
||||
result = 'Clicked';
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Scrollable test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src='mouse-helper.js'></script>
|
||||
<script>
|
||||
for (let i = 0; i < 100; i++) {
|
||||
let button = document.createElement('button');
|
||||
button.textContent = i + ': not clicked';
|
||||
button.id = 'button-' + i;
|
||||
button.onclick = () => button.textContent = 'clicked';
|
||||
button.oncontextmenu = event => {
|
||||
event.preventDefault();
|
||||
button.textContent = 'context menu';
|
||||
}
|
||||
document.body.appendChild(button);
|
||||
document.body.appendChild(document.createElement('br'));
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,69 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Selection Test</title>
|
||||
</head>
|
||||
<body>
|
||||
<select>
|
||||
<option value="black">Black</option>
|
||||
<option value="blue">Blue</option>
|
||||
<option value="brown">Brown</option>
|
||||
<option value="cyan">Cyan</option>
|
||||
<option value="gray">Gray</option>
|
||||
<option value="green">Green</option>
|
||||
<option value="indigo">Indigo</option>
|
||||
<option value="magenta">Magenta</option>
|
||||
<option value="orange">Orange</option>
|
||||
<option value="pink">Pink</option>
|
||||
<option value="purple">Purple</option>
|
||||
<option value="red">Red</option>
|
||||
<option value="violet">Violet</option>
|
||||
<option value="white" id="whiteOption">White</option>
|
||||
<option value="yellow">Yellow</option>
|
||||
</select>
|
||||
<script>
|
||||
window.result = {
|
||||
onInput: null,
|
||||
onChange: null,
|
||||
onBubblingChange: null,
|
||||
onBubblingInput: null,
|
||||
};
|
||||
|
||||
let select = document.querySelector('select');
|
||||
|
||||
function makeEmpty() {
|
||||
for (let i = select.options.length - 1; i >= 0; --i) {
|
||||
select.remove(i);
|
||||
}
|
||||
}
|
||||
|
||||
function makeMultiple() {
|
||||
select.setAttribute('multiple', true);
|
||||
}
|
||||
|
||||
select.addEventListener('input', () => {
|
||||
result.onInput = Array.from(select.querySelectorAll('option:checked')).map((option) => {
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
|
||||
select.addEventListener('change', () => {
|
||||
result.onChange = Array.from(select.querySelectorAll('option:checked')).map((option) => {
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
|
||||
document.body.addEventListener('input', () => {
|
||||
result.onBubblingInput = Array.from(select.querySelectorAll('option:checked')).map((option) => {
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
|
||||
document.body.addEventListener('change', () => {
|
||||
result.onBubblingChange = Array.from(select.querySelectorAll('option:checked')).map((option) => {
|
||||
return option.value;
|
||||
});
|
||||
}, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,20 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Textarea test</title>
|
||||
</head>
|
||||
<body>
|
||||
<textarea spellcheck="false"></textarea>
|
||||
<input></input>
|
||||
<div contenteditable="true"></div>
|
||||
<div class="plain">Plain div</div>
|
||||
<script src='mouse-helper.js'></script>
|
||||
<script>
|
||||
window.result = '';
|
||||
let textarea = document.querySelector('textarea');
|
||||
textarea.addEventListener('input', () => result = textarea.value, false);
|
||||
let input = document.querySelector('input');
|
||||
input.addEventListener('input', () => result = input.value, false);
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Touch test</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="mouse-helper.js"></script>
|
||||
<button onclick="clicked();">Click target</button>
|
||||
<script>
|
||||
window.result = [];
|
||||
const button = document.querySelector('button');
|
||||
button.style.height = '200px';
|
||||
button.style.width = '200px';
|
||||
button.focus();
|
||||
button.addEventListener('touchstart', event => {
|
||||
log('Touchstart:', ...Array.from(event.changedTouches).map(touch => touch.identifier));
|
||||
});
|
||||
button.addEventListener('touchend', event => {
|
||||
log('Touchend:', ...Array.from(event.changedTouches).map(touch => touch.identifier));
|
||||
});
|
||||
button.addEventListener('touchmove', event => {
|
||||
log('Touchmove:', ...Array.from(event.changedTouches).map(touch => touch.identifier));
|
||||
});
|
||||
function log(...args) {
|
||||
console.log.apply(console, args);
|
||||
result.push(args.join(' '));
|
||||
}
|
||||
function getResult() {
|
||||
let temp = result;
|
||||
result = [];
|
||||
return temp;
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user