您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Tiny Modal
当前为
此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/491129/1350904/Tiny%20Modal.js
- // ==UserScript==
- // @name Tiny Modal
- // @namespace http://tampermonkey.net/
- // @version 2024-03-28
- // @description Tiny Modal
- // @author NoLongerPure
- // @match https://www.torn.com/*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=torn.com
- // @grant GM_addStyle
- // ==/UserScript==
- function createModal(content) {
- const modalWrapper = document.createElement('div');
- modalWrapper.id = 'tmModalWrapper';
- modalWrapper.innerHTML = `
- <div id="tmModal">
- <div id="tmModalHeader">
- <span id="tmModalCloseBtn">×</span>
- </div>
- <div id="tmModalContent">
- ${content}
- </div>
- </div>
- `;
- document.body.appendChild(modalWrapper);
- // Style for modal
- const modalStyle = `
- #tmModalWrapper {
- position: fixed;
- top: 50px;
- left: 50px;
- z-index: 9999;
- }
- #tmModal {
- border: 1px solid #ccc;
- background-color: #fff;
- border-radius: 5px;
- box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
- max-width: 200px;
- }
- #tmModalHeader {
- background-color: #f0f0f0;
- padding: 8px;
- border-bottom: 1px solid #ccc;
- cursor: move;
- }
- #tmModalContent {
- padding: 16px;
- }
- #tmModalCloseBtn {
- cursor: pointer;
- float: right;
- font-size: 20px;
- }
- `;
- GM_addStyle(modalStyle);
- // Make modal movable
- const modal = document.getElementById('tmModalWrapper');
- const modalHeader = document.getElementById('tmModalHeader');
- let isDragging = false;
- let offsetX, offsetY;
- let modalWidth = modal.offsetWidth;
- let modalHeight = modal.offsetHeight;
- let windowWidth = window.innerWidth;
- let windowHeight = window.innerHeight;
- modalHeader.addEventListener('mousedown', startDragging);
- modalHeader.addEventListener('mouseup', stopDragging);
- function startDragging(e) {
- isDragging = true;
- offsetX = e.clientX - modal.offsetLeft;
- offsetY = e.clientY - modal.offsetTop;
- document.addEventListener('mousemove', dragModal);
- }
- function stopDragging() {
- isDragging = false;
- document.removeEventListener('mousemove', dragModal);
- }
- function dragModal(e) {
- if (isDragging) {
- let newX = e.clientX - offsetX;
- let newY = e.clientY - offsetY;
- // Check if modal reaches the edges
- if (newX < 0) {
- newX = 0;
- } else if (newX + modalWidth > windowWidth) {
- newX = windowWidth - modalWidth;
- }
- if (newY < 0) {
- newY = 0;
- } else if (newY + modalHeight > windowHeight) {
- newY = windowHeight - modalHeight;
- }
- modal.style.left = `${newX}px`;
- modal.style.top = `${newY}px`;
- }
- }
- // Close modal when close button is clicked
- const closeBtn = document.getElementById('tmModalCloseBtn');
- closeBtn.addEventListener('click', () => {
- modal.style.display = 'none';
- });
- }