Camwhores.tv user preview inside messages

Extracts the URL from the first message on camwhores.tv/my/messages/*, retrieves the title from the linked page, gets the content from the video element, and adds the generated text to the visible page. If successful, adds the generated text to the visible page, otherwise adds "No videos".

目前為 2024-03-31 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Camwhores.tv user preview inside messages
// @namespace    https://sleazyfork.org/users/1281730-vipprograms
// @version      0.3
// @description  Extracts the URL from the first message on camwhores.tv/my/messages/*, retrieves the title from the linked page, gets the content from the video element, and adds the generated text to the visible page. If successful, adds the generated text to the visible page, otherwise adds "No videos".
// @author       vipprograms
// @match        https://www.camwhores.tv/my/messages/*
// @grant        GM_xmlhttpRequest
// @icon         data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAgMAAABinRfyAAAAIGNIUk0AAHomAACAhAAA+gAAAIDoAAB1MAAA6mAAADqYAAAXcJy6UTwAAAAMUExURQAAAP8ANwwA/////7gbQJkAAAABdFJOUwBA5thmAAAAAWJLR0QDEQxM8gAAAAd0SU1FB+gDHhIuCjXV/h8AAAA4SURBVAjXY2ANDQ1gEA0NDWEIYWBgZAhgAAIUghEiC1YHBhpMDRpIhBbXghUMXKtWLWBgWqHVAACjlwz/pN0YPwAAACV0RVh0ZGF0ZTpjcmVhdGUAMjAyNC0wMy0zMFQxODo0NjowOSswMDowME+iXNIAAAAldEVYdGRhdGU6bW9kaWZ5ADIwMjQtMDMtMzBUMTg6NDY6MDkrMDA6MDA+/+RuAAAAKHRFWHRkYXRlOnRpbWVzdGFtcAAyMDI0LTAzLTMwVDE4OjQ2OjEwKzAwOjAwMNiA/AAAAABJRU5ErkJggg==
// ==/UserScript==

(function() {
    'use strict';

    // Function to fetch the URL and extract title, content, and joined date
    function fetchAndExtract(url) {
        GM_xmlhttpRequest({
            method: "GET",
            url: url,
            onload: function(response) {
                // Parse the response text into a HTML document
                var parser = new DOMParser();
                var htmlDoc = parser.parseFromString(response.responseText, "text/html");

                // Get the text of the specified elements
                var titleElement = htmlDoc.evaluate('//*[@id="list_videos_uploaded_videos"]/div[1]/h2', htmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
                var contentElement = htmlDoc.evaluate('//*[@id="list_videos_uploaded_videos_items"]/div[1]/a/div[3]/div[1]/em', htmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
                var joinedDateElement = htmlDoc.evaluate('/html/body/div[2]/div[2]/div/div[2]/div[2]/div/div/div[1]/div[3]/em', htmlDoc, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
                var joinedDateText = joinedDateElement.singleNodeValue.textContent;

                // Check if the elements exist
                if (titleElement && titleElement.singleNodeValue && contentElement && contentElement.singleNodeValue && joinedDateElement && joinedDateElement.singleNodeValue) {
                    var titleText = titleElement.singleNodeValue.textContent;
                    // Extract text inside parentheses from title
                    var extractedTitle = titleText.match(/\(([^)]+)\)/);
                    if (extractedTitle && extractedTitle.length > 1) {
                        var contentText = contentElement.singleNodeValue.textContent;
                        var generatedText = "Joined " + joinedDateText + "<br>" + extractedTitle[1] + " videos, last " + contentText;
                        // Add generated text to the visible page
                        var messageDiv = document.evaluate('//*[@id="list_messages_my_conversation_messages_items"]/div/div[3]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
                        if (messageDiv && messageDiv.singleNodeValue) {
                            messageDiv.singleNodeValue.innerHTML += generatedText;
                        }
                    } else {
                        console.log('Text inside parentheses in title not found.');
                    }
                } else {
                    console.log('Title, content, or joined date element not found. Probably no videos uploaded yet.');
                    // Add "No videos" to the visible page
                    var messageDiv = document.evaluate('//*[@id="list_messages_my_conversation_messages_items"]/div/div[3]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
                    if (messageDiv && messageDiv.singleNodeValue) {
                        messageDiv.singleNodeValue.innerHTML += "Joined " + joinedDateText + "<br>" + "<b>No videos</b>";
                    }
                }
            }
        });
    }

    // Get the href attribute of the first message
    var messageLink = document.evaluate('//*[@id="list_messages_my_conversation_messages_items"]/div/div[1]/a', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);

    // Check if the element exists
    if (messageLink && messageLink.singleNodeValue) {
        // Get the URL from the message link
        var messageUrl = messageLink.singleNodeValue.href;
        // Fetch and extract title, content, and joined date from the URL
        fetchAndExtract(messageUrl);
    } else {
        console.log('Message link not found.');
    }

    // Remove class "bottom" from specified element
    var bottomElement = document.evaluate('//*[@id="list_messages_my_conversation_messages_items"]/div/div[3]/form/div', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
    if (bottomElement && bottomElement.singleNodeValue) {
        bottomElement.singleNodeValue.style.marginTop = "1em";
        bottomElement.singleNodeValue.style.marginBottom = "1em";
        bottomElement.singleNodeValue.classList.remove("bottom");
    } else {
        console.log('Bottom element not found.');
    }
})();