Adds an ultra-smooth zoom slider with draggable functionality, ensuring no auto-zoom and slider visibility remains constant.
当前为
// ==UserScript==
// @name Ultra Smooth Zoom Slider (Fixed & Improved)
// @namespace http://tampermonkey.net/
// @version 1.8
// @description Adds an ultra-smooth zoom slider with draggable functionality, ensuring no auto-zoom and slider visibility remains constant.
// @author tae
// @match *://*/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
function createZoomSlider() {
console.log("✅ Ultra Smooth Zoom Slider Initialized...");
// Create the slider
const slider = document.createElement('input');
slider.type = 'range';
slider.min = '0.5';
slider.max = '2';
slider.step = '0.01';
slider.value = '1'; // Ensure it starts at normal zoom (no auto-zoom)
slider.style.width = '200px';
// Create a container for the slider (fixed position)
const sliderContainer = document.createElement('div');
Object.assign(sliderContainer.style, {
position: 'fixed',
bottom: '10px',
left: '10px',
zIndex: '10000',
padding: '8px',
backgroundColor: 'rgba(255, 255, 255, 0.9)',
border: '1px solid #ccc',
borderRadius: '5px',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
boxShadow: '0px 2px 10px rgba(0, 0, 0, 0.2)',
cursor: 'grab',
userSelect: 'none'
});
sliderContainer.appendChild(slider);
document.body.appendChild(sliderContainer);
console.log("🎯 Zoom slider added successfully.");
// Ensure smooth zooming without unexpected resets
document.documentElement.style.transformOrigin = 'top left';
document.documentElement.style.transition = 'transform 0.2s ease-out';
// Apply zoom on slider input
slider.addEventListener('input', function () {
document.documentElement.style.transform = `scale(${slider.value})`;
});
// Dragging functionality
let isDragging = false;
let startX, startY, initialLeft, initialBottom;
sliderContainer.addEventListener('mousedown', function (e) {
isDragging = true;
sliderContainer.style.cursor = 'grabbing';
startX = e.clientX;
startY = e.clientY;
initialLeft = sliderContainer.offsetLeft;
initialBottom = window.innerHeight - sliderContainer.offsetTop - sliderContainer.offsetHeight;
document.addEventListener('mousemove', onMouseMove);
document.addEventListener('mouseup', onMouseUp);
});
function onMouseMove(e) {
if (isDragging) {
const dx = e.clientX - startX;
const dy = e.clientY - startY;
sliderContainer.style.left = `${Math.max(0, initialLeft + dx)}px`;
sliderContainer.style.bottom = `${Math.max(0, initialBottom - dy)}px`;
}
}
function onMouseUp() {
isDragging = false;
sliderContainer.style.cursor = 'grab';
document.removeEventListener('mousemove', onMouseMove);
document.removeEventListener('mouseup', onMouseUp);
}
}
// Run script only when DOM is fully loaded
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', createZoomSlider);
} else {
createZoomSlider();
}
})();