DF Quick marks

Simple bookmark for market search

スクリプトをインストールするには、Tampermonkey, GreasemonkeyViolentmonkey のような拡張機能のインストールが必要です。

You will need to install an extension such as Tampermonkey to install this script.

スクリプトをインストールするには、TampermonkeyViolentmonkey のような拡張機能のインストールが必要です。

スクリプトをインストールするには、TampermonkeyUserscripts のような拡張機能のインストールが必要です。

このスクリプトをインストールするには、Tampermonkeyなどの拡張機能をインストールする必要があります。

このスクリプトをインストールするには、ユーザースクリプト管理ツールの拡張機能をインストールする必要があります。

(ユーザースクリプト管理ツールは設定済みなのでインストール!)

このスタイルをインストールするには、Stylusなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus などの拡張機能をインストールする必要があります。

このスタイルをインストールするには、Stylus tなどの拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

このスタイルをインストールするには、ユーザースタイル管理用の拡張機能をインストールする必要があります。

(ユーザースタイル管理ツールは設定済みなのでインストール!)

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください
// ==UserScript==
// @name         DF Quick marks 
// @namespace    http://tampermonkey.net/
// @version      1.6.4
// @description  Simple bookmark for market search
// @author       SHUN
// @license      SHUN
// @match        *://fairview.deadfrontier.com/onlinezombiemmo/index.php?page=35
// @match        *://*.deadfrontier.com/onlinezombiemmo/index.php?page=35
// @grant        none
// @icon         https://i.imgur.com/wDmstST.png
// @run-at       document-end

// ==/UserScript==

(function() {
    'use strict';

    // 延长等待时间,确保页面完全加载
    setTimeout(init, 3000);

    function init() {
        if (!window.location.href.includes('page=35')) return;

        console.log('Simple Bookmarks started');

        // 防止重复创建
        if (document.getElementById('simple-bookmarks')) return;

        // 创建主框架
        const frame = document.createElement('div');
        frame.id = 'simple-bookmarks';
        frame.style.cssText = `
            position: fixed;
            top: 580px;
            right: 250px;
            width: 180px;
            background: rgba(40, 40, 40, 0.9);
            border: 1px solid #666;
            border-radius: 5px;
            z-index: 9999;
            padding: 10px;
            font-family: Arial, sans-serif;
        `;

        // 标题
        const title = document.createElement('div');
        title.textContent = 'Bookmarks';
        title.style.cssText = `
            color: white;
            font-weight: bold;
            font-size: 14px;
            margin-bottom: 10px;
            text-align: center;
        `;
        frame.appendChild(title);

        // 输入框
        const input = document.createElement('input');
        input.type = 'text';
        input.placeholder = 'Item Name';
        input.style.cssText = `
            width: 100%;
            padding: 6px;
            margin-bottom: 8px;
            border: 1px solid #555;
            border-radius: 3px;
            background: #333;
            color: white;
            font-size: 12px;
            box-sizing: border-box;
        `;
        frame.appendChild(input);

        // 按钮容器
        const buttonContainer = document.createElement('div');
        buttonContainer.style.cssText = `
            display: flex;
            justify-content: space-between;
            margin-bottom: 10px;
        `;

        // 保存按钮
        const saveBtn = document.createElement('button');
        saveBtn.textContent = 'Save';
        saveBtn.style.cssText = `
            padding: 6px 12px;
            background: #28a745;
            color: white;
            border: none;
            border-radius: 3px;
            font-size: 12px;
            cursor: pointer;
            flex: 1;
            margin-right: 5px;
        `;

        // 移动按钮
        const moveBtn = document.createElement('button');
        moveBtn.textContent = 'Move';
        moveBtn.style.cssText = `
            padding: 6px 12px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 3px;
            font-size: 12px;
            cursor: pointer;
            flex: 1;
            margin-left: 5px;
        `;

        buttonContainer.appendChild(saveBtn);
        buttonContainer.appendChild(moveBtn);
        frame.appendChild(buttonContainer);

        // 物品列表
        const list = document.createElement('div');
        list.id = 'bookmarks-list';
        list.style.cssText = `
            max-height: 200px;
            overflow-y: auto;
            font-size: 12px;
        `;
        frame.appendChild(list);

        // 添加到页面
        document.body.appendChild(frame);

        // 加载保存的物品
        const savedItems = loadItems();
        renderList();

        // 保存功能
        saveBtn.onclick = () => {
            const item = input.value.trim();
            if (item && !savedItems.includes(item)) {
                savedItems.push(item);
                saveItems(savedItems);
                renderList();
                input.value = '';
            }
        };

        // 移动功能
        let isDragging = false;
        let dragOffsetX = 0;
        let dragOffsetY = 0;

        moveBtn.onclick = () => {
            isDragging = !isDragging;
            moveBtn.textContent = isDragging ? 'Stop' : 'Move';
            moveBtn.style.background = isDragging ? '#dc3545' : '#007bff';
        };

        frame.addEventListener('mousedown', (e) => {
            if (!isDragging) return;

            e.preventDefault();
            dragOffsetX = e.clientX - frame.getBoundingClientRect().left;
            dragOffsetY = e.clientY - frame.getBoundingClientRect().top;

            function mouseMoveHandler(e) {
                frame.style.left = (e.clientX - dragOffsetX) + 'px';
                frame.style.top = (e.clientY - dragOffsetY) + 'px';
                frame.style.right = 'auto'; // 移动时取消right定位
            }

            function mouseUpHandler() {
                document.removeEventListener('mousemove', mouseMoveHandler);
                document.removeEventListener('mouseup', mouseUpHandler);
            }

            document.addEventListener('mousemove', mouseMoveHandler);
            document.addEventListener('mouseup', mouseUpHandler);
        });

        // 渲染列表
        function renderList() {
            list.innerHTML = '';

            if (savedItems.length === 0) {
                const emptyMsg = document.createElement('div');
                emptyMsg.textContent = 'No saved items';
                emptyMsg.style.cssText = `
                    color: #999;
                    text-align: center;
                    padding: 10px;
                    font-style: italic;
                `;
                list.appendChild(emptyMsg);
                return;
            }

            savedItems.forEach((item, index) => {
                const itemDiv = document.createElement('div');
                itemDiv.style.cssText = `
                    display: flex;
                    justify-content: space-between;
                    align-items: center;
                    padding: 5px;
                    margin: 3px 0;
                    background: rgba(255, 255, 255, 0.1);
                    border-radius: 3px;
                `;

                const nameSpan = document.createElement('span');
                nameSpan.textContent = item;
                nameSpan.style.cssText = `
                    color: white;
                    cursor: pointer;
                    flex: 1;
                    padding: 3px;
                `;

                // 双击搜索功能
                nameSpan.ondblclick = () => searchItem(item);

                // 按钮容器
                const btnContainer = document.createElement('div');
                btnContainer.style.cssText = `
                    display: flex;
                    gap: 5px;
                `;

                // 搜索按钮
                const searchBtn = document.createElement('button');
                searchBtn.textContent = '🔍';
                searchBtn.style.cssText = `
                    background: #17a2b8;
                    color: white;
                    border: none;
                    border-radius: 3px;
                    width: 22px;
                    height: 22px;
                    font-size: 10px;
                    cursor: pointer;
                `;
                searchBtn.onclick = (e) => {
                    e.stopPropagation();
                    searchItem(item);
                };

                // 删除按钮
                const deleteBtn = document.createElement('button');
                deleteBtn.textContent = '×';
                deleteBtn.style.cssText = `
                    background: #dc3545;
                    color: white;
                    border: none;
                    border-radius: 50%;
                    width: 22px;
                    height: 22px;
                    font-size: 12px;
                    cursor: pointer;
                `;
                deleteBtn.onclick = (e) => {
                    e.stopPropagation();
                    if (confirm(`Delete "${item}"?`)) {
                        savedItems.splice(index, 1);
                        saveItems(savedItems);
                        renderList();
                    }
                };

                btnContainer.appendChild(searchBtn);
                btnContainer.appendChild(deleteBtn);

                itemDiv.appendChild(nameSpan);
                itemDiv.appendChild(btnContainer);
                list.appendChild(itemDiv);
            });
        }

        // ====== 关键修复:简化的搜索功能 ======
        function searchItem(item) {
            console.log('搜索物品:', item);

            // 简单直接的查找搜索框
            let searchField = null;

            // 尝试所有可能的搜索框选择器
            const selectors = [
                'input[name="searchField"]',
                'input[name="search"]',
                'input[placeholder*="Search"]',
                'input[placeholder*="search"]',
                '#searchField',
                '.searchField',
                'input[type="text"]'
            ];

            for (const selector of selectors) {
                searchField = document.querySelector(selector);
                if (searchField && searchField.offsetWidth > 0) {
                    break;
                }
            }

            if (!searchField) {
                console.error('找不到搜索框!');
                alert('找不到搜索框,请刷新页面重试。');
                return;
            }

            console.log('找到搜索框:', searchField);

            // 清空并填充搜索框
            searchField.value = '';
            searchField.focus();
            searchField.value = item;

            // 触发输入事件
            searchField.dispatchEvent(new Event('input', { bubbles: true }));
            searchField.dispatchEvent(new Event('change', { bubbles: true }));

            // 等待一下让输入生效
            setTimeout(() => {
                // 查找搜索按钮
                let searchButton = null;
                const buttons = document.querySelectorAll('input[type="submit"], button, input[type="button"]');

                for (const btn of buttons) {
                    const btnText = (btn.value || btn.textContent || '').toLowerCase();
                    const btnName = (btn.name || '').toLowerCase();

                    if (btnText.includes('search') ||
                        btnText.includes('find') ||
                        btnName.includes('search')) {
                        searchButton = btn;
                        break;
                    }
                }

                if (searchButton) {
                    console.log('找到搜索按钮,点击它');
                    searchButton.click();
                } else {
                    // 如果找不到按钮,尝试提交表单
                    const form = searchField.closest('form');
                    if (form) {
                        console.log('找不到按钮,直接提交表单');
                        form.submit();
                    } else {
                        // 最后尝试:按Enter键
                        console.log('尝试按Enter键');
                        const enterEvent = new KeyboardEvent('keydown', {
                            key: 'Enter',
                            code: 'Enter',
                            keyCode: 13,
                            bubbles: true
                        });
                        searchField.dispatchEvent(enterEvent);
                    }
                }
            }, 100);
        }

        // 本地存储功能
        function loadItems() {
            try {
                return JSON.parse(localStorage.getItem('simpleBookmarks')) || [];
            } catch {
                return [];
            }
        }

        function saveItems(items) {
            localStorage.setItem('simpleBookmarks', JSON.stringify(items));
        }
    }

})();