G00DB0Y / Fast Comment Box(Adult Private Tracker)

// ==UserScript==
// @name         Fast Comment Box(Adult Private Tracker)
// @namespace    http://tampermonkey.net/
// @version      2.6
// @description  Adds a comment box with fixed phrases, a custom input box, and draggable/resizable functionality with persistent size and position on HappyFappy. Clicking a comment or the Add Comment button adds it to the post comment field on the webpage. The custom input remains even after page reload or browser restart with logging for debugging. Added functionality to modify custom comment input, fixed drag issue, persistence on reloads, a notification feature when a comment is added, dark ash color scheme with fixed resize handle position, and a one-time hashed license check for added security.
// @author       Faisal Ahmed
// @license      MIT
// @match        https://www.happyfappy.org/torrents.php?id=*
// @match        https://pornbay.org/torrents.php?id=*
// @match        https://femdomcult.org/torrents.php?id=*
// @match        https://kufirc.com/torrents.php?id=*
// @match        https://www.homeporntorrents.club/torrents.php?id=*
// @match        https://www.empornium.is/torrents.php?id=*
// @match        https://www.empornium.sx/torrents.php?id=*
// @match        https://lusthive.org/torrents.php?id=*
// @grant        none
// ==/UserScript==

(async function() {
    'use strict';

    // Stored Hash of the Secret Code (SHA-256 of "mySecret1234")
    const STORED_HASH = 'e077e74c96c4de1fc7b8be2f0d3cb396ecc9c13e030d8b93ec0df84483a0de79'; // Replace with your hashed secret code

    // Check if the license is already verified
    const isLicensed = localStorage.getItem('isLicensed');

    // Function to hash the input code using SHA-256
    async function hashCode(input) {
        const encoder = new TextEncoder();
        const data = encoder.encode(input);
        const hash = await crypto.subtle.digest('SHA-256', data);
        const hashArray = Array.from(new Uint8Array(hash));
        const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
        return hashHex;
    }

    // Function to verify the license
    async function verifyLicense() {
        // Prompt the user to enter the secret code
        const enteredCode = prompt('Please enter the secret code to use this script:');
        if (enteredCode) {
            // Hash the entered code and compare with the stored hash
            const enteredHash = await hashCode(enteredCode);
            if (enteredHash === STORED_HASH) {
                // If the code is correct, store the license status in localStorage
                localStorage.setItem('isLicensed', 'true');
                alert('License verified successfully! You can now use the script.');
            } else {
                // If the code is incorrect, alert the user and exit the script
                alert('Incorrect code. You cannot use this script.');
                return false;
            }
        } else {
            // If the prompt was cancelled or empty, exit the script
            alert('License verification cancelled. You cannot use this script.');
            return false;
        }
        return true;
    }

    // If the script is not licensed, ask for the license code
    if (!isLicensed) {
        const licenseVerified = await verifyLicense();
        if (!licenseVerified) {
            // Exit the script if the license is not verified
            return;
        }
    }

    console.log('Tampermonkey script loaded: Fast Comment Box');

    // CSS for the comment box with dark ash color scheme, draggable cursor, and resizable handle
    const styles = `
        #comment-box {
            position: fixed; /* Keep the comment box fixed */
            top: 20px;
            right: 20px;
            width: 200px;
            height: 150px;
            min-width: 150px;
            min-height: 150px;
            background-color: #333333; /* Dark ash color */
            border: 1px solid #555555; /* Slightly lighter ash border */
            border-radius: 8px;
            padding: 10px;
            box-shadow: 0 6px 12px rgba(0,0,0,0.1);
            z-index: 9999;
            transition: box-shadow 0.3s ease-in-out;
            font-family: Arial, sans-serif;
            cursor: default;
            overflow: hidden; /* Hide overflow to prevent scrollbars */
            color: #e0e0e0; /* Light text color for visibility */
        }
        #comment-box:hover {
            box-shadow: 0 8px 16px rgba(0,0,0,0.15);
        }
        #comment-box h3 {
            margin: 0 0 10px;
            font-size: 14px;
            text-align: center;
            color: #ffffff; /* White text for the title */
            font-weight: bold;
            cursor: move;
        }
        .comment {
            cursor: pointer;
            padding: 8px;
            margin: 5px 0;
            background-color: #444444; /* Dark ash background */
            border: 1px solid #555555; /* Border color */
            border-radius: 5px;
            text-align: center;
            font-size: 12px;
            color: #e0e0e0; /* Light text color */
            transition: background-color 0.3s ease;
        }
        .comment:hover {
            background-color: #555555; /* Lighter ash on hover */
        }
        #custom-comment-input {
            width: 100%;
            padding: 7px;
            margin: 5px 0;
            border: 1px solid #555555; /* Border color */
            border-radius: 5px;
            font-size: 12px;
            box-sizing: border-box;
            outline: none;
            background-color: #444444; /* Dark ash background */
            color: #e0e0e0; /* Light text color */
            transition: border-color 0.3s ease;
        }
        #custom-comment-input:focus {
            border-color: #ffffff; /* White border on focus */
        }
        #add-comment-btn {
            width: 100%;
            padding: 7px;
            background-color: #4CAF50;
            color: #fff;
            border: none;
            border-radius: 5px;
            cursor: pointer;
            font-size: 12px;
            margin-bottom: 5px;
            transition: background-color 0.3s ease;
        }
        #add-comment-btn:hover {
            background-color: #45a049;
        }
        #resize-handle {
            position: absolute;
            bottom: 0; /* Keep the resize handle at the bottom */
            right: 0; /* Keep the resize handle at the right */
            width: 15px;
            height: 15px;
            background-color: #555555; /* Ash color for resize handle */
            cursor: se-resize;
            border-top: 1px solid #666666; /* Slightly lighter ash */
            border-left: 1px solid #666666;
            border-bottom-right-radius: 4px;
        }
        #notification {
            position: fixed;
            top: 20px;
            right: 20px;
            background-color: #4CAF50;
            color: #fff;
            padding: 10px 15px;
            border-radius: 5px;
            font-size: 14px;
            font-family: Arial, sans-serif;
            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
            z-index: 10000;
            display: none;
        }
    `;

    // Insert the styles into the page
    const styleSheet = document.createElement('style');
    styleSheet.type = 'text/css';
    styleSheet.innerText = styles;
    document.head.appendChild(styleSheet);

    // Create the comment box container
    const commentBox = document.createElement('div');
    commentBox.id = 'comment-box';

    // Add a title to the comment box
    const title = document.createElement('h3');
    title.innerText = 'Quick Comments';
    commentBox.appendChild(title);
    console.log('Comment box created.');

    // Add custom comment input box
    const customInput = document.createElement('input');
    customInput.id = 'custom-comment-input';
    customInput.placeholder = 'Enter your custom comment';
    commentBox.appendChild(customInput);

    // Add "Add Comment" button
    const addCommentButton = document.createElement('button');
    addCommentButton.id = 'add-comment-btn';
    addCommentButton.innerText = 'Add Comment';
    commentBox.appendChild(addCommentButton);
    console.log('Custom comment input and button added.');

    // Create a container for the comments
    const commentsContainer = document.createElement('div');
    commentsContainer.style.overflowY = 'auto'; // Allow comments to scroll inside the container vertically
    commentsContainer.style.maxHeight = 'calc(100% - 100px)'; // Adjust height dynamically
    commentBox.appendChild(commentsContainer);
    console.log('Comments container added.');

    // Add resize handle
    const resizeHandle = document.createElement('div');
    resizeHandle.id = 'resize-handle';
    commentBox.appendChild(resizeHandle);
    console.log('Resize handle added.');

    // Notification element
    const notification = document.createElement('div');
    notification.id = 'notification';
    notification.innerText = 'Comment added';
    document.body.appendChild(notification);
    console.log('Notification element added.');

    // List of fixed phrases
    const comments = [
        'Great Upload',
        'Great Share',
        'Jav is real deal',
        'Good Quality'
    ];

    // Function to show notification
    function showNotification(message) {
        notification.innerText = message;
        notification.style.display = 'block';
        setTimeout(() => {
            notification.style.display = 'none';
        }, 1000); // Hide notification after 1 second
    }

    // Function to add a comment to the post comment field
    function addCommentToPostField(comment) {
        console.log(`Attempting to add comment: "${comment}" to post comment field.`);
        // Use the correct selector for the comment input field
        const commentField = document.querySelector('textarea#quickpost[name="body"]');
        if (commentField) {
            console.log('Comment field found.');
            commentField.value += (commentField.value ? '\n' : '') + comment;
            commentField.focus(); // Focus on the comment field after adding the comment
            console.log(`Comment added to post field: "${comment}".`);
            showNotification('Comment added'); // Show notification
        } else {
            console.log('Comment field not found. Retrying in 500ms...');
            setTimeout(() => addCommentToPostField(comment), 500); // Retry after 500ms
        }
    }

    // Function to add a comment to the container
    function addComment(comment) {
        console.log(`Adding comment to comment box: "${comment}".`);
        const commentElement = document.createElement('div');
        commentElement.className = 'comment';
        commentElement.innerText = comment;
        commentElement.onclick = () => {
            console.log(`Comment clicked: "${comment}".`);
            addCommentToPostField(comment);
        };
        commentsContainer.appendChild(commentElement);
    }

    // Add the predefined comments to the box
    comments.forEach(comment => addComment(comment));

    // Load custom comment from localStorage if it exists
    const savedCustomComment = localStorage.getItem('customComment');
    if (savedCustomComment) {
        customInput.value = savedCustomComment;
        console.log(`Loaded custom comment from localStorage: "${savedCustomComment}".`);
    }

    // Load box size and position from localStorage if they exist
    const savedBoxWidth = localStorage.getItem('boxWidth');
    const savedBoxHeight = localStorage.getItem('boxHeight');
    const savedBoxTop = localStorage.getItem('boxTop');
    const savedBoxLeft = localStorage.getItem('boxLeft');
    if (savedBoxWidth && savedBoxHeight) {
        commentBox.style.width = savedBoxWidth + 'px';
        commentBox.style.height = savedBoxHeight + 'px';
        console.log(`Loaded box size from localStorage: Width=${savedBoxWidth}px, Height=${savedBoxHeight}px.`);
    }
    if (savedBoxTop && savedBoxLeft) {
        commentBox.style.top = savedBoxTop + 'px';
        commentBox.style.left = savedBoxLeft + 'px';
        console.log(`Loaded box position from localStorage: Top=${savedBoxTop}px, Left=${savedBoxLeft}px.`);
    }

    // Save custom comment to localStorage on change
    customInput.addEventListener('input', () => {
        localStorage.setItem('customComment', customInput.value);
        console.log(`Custom comment saved to localStorage on input change: "${customInput.value}".`);
    });

    // Add event listener for the "Add Comment" button
    addCommentButton.addEventListener('click', () => {
        const customComment = customInput.value.trim();
        if (customComment !== '') {
            // Add the custom comment to the post comment field
            addCommentToPostField(customComment);
            console.log(`Custom comment added to post field: "${customComment}".`);
        } else {
            console.log('Custom comment input is empty.');
        }
    });

    // Draggable functionality for the comment box
    function makeDraggable(element) {
        let posX = 0, posY = 0, mouseX = 0, mouseY = 0;

        function onMouseDown(e) {
            // Prevent dragging when clicking on input fields or buttons
            if (e.target === customInput || e.target === addCommentButton || e.target === resizeHandle) {
                return;
            }
            e.preventDefault();
            mouseX = e.clientX;
            mouseY = e.clientY;
            document.addEventListener('mousemove', onMouseMove);
            document.addEventListener('mouseup', onMouseUp);
            console.log('Started dragging comment box.');
        }

        function onMouseMove(e) {
            e.preventDefault();
            posX = mouseX - e.clientX;
            posY = mouseY - e.clientY;
            mouseX = e.clientX;
            mouseY = e.clientY;
            element.style.top = (element.offsetTop - posY) + 'px';
            element.style.left = (element.offsetLeft - posX) + 'px';
        }

        function onMouseUp() {
            document.removeEventListener('mousemove', onMouseMove);
            document.removeEventListener('mouseup', onMouseUp);
            console.log(`Stopped dragging comment box. New position: Top=${element.offsetTop}px, Left=${element.offsetLeft}px.`);
            // Save the new position to localStorage
            localStorage.setItem('boxTop', element.offsetTop);
            localStorage.setItem('boxLeft', element.offsetLeft);
        }

        element.addEventListener('mousedown', onMouseDown);
    }

    // Resizable functionality for the comment box
    function makeResizable(element, handle) {
        handle.addEventListener('mousedown', function (e) {
            e.preventDefault();
            document.addEventListener('mousemove', resize);
            document.addEventListener('mouseup', stopResize);
            console.log('Started resizing comment box.');
        });

        function resize(e) {
            element.style.width = (e.clientX - element.offsetLeft) + 'px';
            element.style.height = (e.clientY - element.offsetTop) + 'px';
        }

        function stopResize() {
            document.removeEventListener('mousemove', resize);
            document.removeEventListener('mouseup', stopResize);
            console.log(`Stopped resizing comment box. New size: Width=${element.offsetWidth}px, Height=${element.offsetHeight}px.`);
            // Save the new size to localStorage
            localStorage.setItem('boxWidth', element.offsetWidth);
            localStorage.setItem('boxHeight', element.offsetHeight);
        }
    }

    // Make the comment box draggable and resizable
    makeDraggable(commentBox);
    makeResizable(commentBox, resizeHandle);
    console.log('Comment box made draggable and resizable.');

    // Append the comment box to the body
    document.body.appendChild(commentBox);
    console.log('Comment box appended to the body.');
})();