javDB Selection Tools

Double-click + right-click hyphenated word select on javDB.com/*

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         javDB Selection Tools
// @namespace    -
// @icon         https://avatars.githubusercontent.com/u/81081327?v=4
// @version      2.0
// @description  Double-click + right-click hyphenated word select on javDB.com/*
// @author       colemeg
// @match        https://javdb.com/*
// @grant        none
// @license      Do What The Fuck You Want To Public License (WTFPL)
// ==/UserScript==
//
//
//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
//                    Version 2, December 2004
//
// Copyright (C) 2004 Sam Hocevar <[email protected]>
//
// Everyone is permitted to copy and distribute verbatim or modified
// copies of this license document, and changing it is allowed as long
// as the name is changed.
//
//            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
//   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
//
//  0. You just DO WHAT THE FUCK YOU WANT TO.
//
//
(function () {
    // Reusable caret range from point
    function getTextNodeRangeFromPoint(x, y) {
        if (document.caretRangeFromPoint) return document.caretRangeFromPoint(x, y);
        if (document.caretPositionFromPoint) {
            const pos = document.caretPositionFromPoint(x, y);
            const r = document.createRange();
            r.setStart(pos.offsetNode, pos.offset);
            return r;
        }
        return null;
    }

    // 1. Double-click hyphenated word selector
    document.addEventListener('dblclick', function (e) {
        const range = getTextNodeRangeFromPoint(e.clientX, e.clientY);
        if (!range) return;

        const node = range.startContainer;
        if (node.nodeType !== Node.TEXT_NODE) return;

        const text = node.textContent;
        const offset = range.startOffset;
        const regex = /\b[\w]+-[\w]+\b/g;
        let match;
        while ((match = regex.exec(text)) !== null) {
            if (offset >= match.index && offset <= match.index + match[0].length) {
                const sel = window.getSelection();
                const wordRange = document.createRange();
                wordRange.setStart(node, match.index);
                wordRange.setEnd(node, match.index + match[0].length);
                sel.removeAllRanges();
                sel.addRange(wordRange);
                break;
            }
        }
    });

    // 2. Right-click to select hyphenated word (if it's the only one in text)
    document.addEventListener('contextmenu', function (e) {
        const range = getTextNodeRangeFromPoint(e.clientX, e.clientY);
        if (!range) return;

        const node = range.startContainer;
        if (node.nodeType !== Node.TEXT_NODE) return;

        const text = node.textContent;
        const offset = range.startOffset;
        const matches = [...text.matchAll(/\b[\w]+-[\w]+\b/g)];

        // Only act if there's exactly one hyphenated word
        if (matches.length !== 1) return;

        const match = matches[0];
        if (offset < match.index || offset > match.index + match[0].length) return;

        // Select and prevent native menu
        e.preventDefault();

        const sel = window.getSelection();
        const wordRange = document.createRange();
        wordRange.setStart(node, match.index);
        wordRange.setEnd(node, match.index + match[0].length);
        sel.removeAllRanges();
        sel.addRange(wordRange);
    });
})();