AJR log ttu

Crea un botón para guardar logs para AJR

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         AJR log ttu
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  Crea un botón para guardar logs para AJR
// @author       Pedrubik🦙
// @license      GPL-3.0-or-later
// @match        https://reader.ttsu.app/b?id=*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ttsu.app
// @grant        none
// ==/UserScript==

function copyLog(textLog,divObjective) {
    navigator.clipboard.writeText(textLog);
    createPopup(divObjective, textLog)
};
function createPopup(divObjective, textLog) {
    const popup = document.createElement('div');
    popup.textContent = `${textLog} ✅`;
    popup.style.position = 'absolute';
    popup.style.top = '50%';
    popup.style.left = '50%';
    popup.style.transform = 'translate(-50%, -50%)';
    popup.style.backgroundColor = 'rgba(0, 0, 0, 0.7)';
    popup.style.color = 'white';
    popup.style.padding = '10px';
    popup.style.borderRadius = '5px';
    popup.style.fontFamily = 'Arial, sans-serif';
    popup.style.fontSize = '16px';
    popup.style.zIndex = '9999';
    popup.style.pointerEvents = 'none';
    popup.style.opacity = '0'; // Start with 0 opacity
    popup.style.transition = 'opacity 0.25s ease, top 0.3s ease'; // Add transition for opacity


    // Adjust for the parent's positioning
    const rect = divObjective.getBoundingClientRect();
    const parentStyles = window.getComputedStyle(divObjective);
    const paddingTop = parseFloat(parentStyles.paddingTop);
    const paddingLeft = parseFloat(parentStyles.paddingLeft);

    const popupTop = rect.top + window.scrollY + paddingTop;
    const popupLeft = rect.left + window.scrollX + paddingLeft;

    popup.style.top = `${popupTop + rect.height / 2}px`;
    popup.style.left = `${popupLeft + rect.width / 2}px`;

    divObjective.appendChild(popup);

    // Triggering a reflow so that the initial opacity change is animated
    popup.offsetWidth;
    popup.style.top = `${popupTop - rect.height}px`; // Move the popup up
    popup.style.opacity = '1'; // Fade in
    setTimeout(() => {
        popup.style.opacity = '0'; // Fade out
        setTimeout(() => {
            divObjective.removeChild(popup);
        }, 500); // Remove the popup after the fade out animation (0.5 seconds)
    }, 1000); // Remove the popup after 2 seconds
}
function runScript() {
    const flexChild = this.querySelector(".flex-1");
    const regex = /\|.*|【電子版特典付】 \(PASH! ブックス\) /gm;
    const subst = ``;

    if (!runScript.executed && flexChild) {
        console.log("Executed")
        runScript.executed = true;
        let divChildren = flexChild.childNodes;
        for (var i = 0; i < divChildren.length - 1; i++) {
            let logText = `.log lectura ${divChildren[i+1].childNodes[2].innerText - divChildren[i].childNodes[2].innerText} ${document.title.replace(regex, subst)} ${divChildren[i].childNodes[0].innerText}`;
            divChildren[i].addEventListener("click", function(){
                copyLog(logText, this);
            }, false);
        }
    } else if (!flexChild) {
        console.log("No child with class 'flex-1' and the flag is reseted");
        runScript.executed = false; // Reset the flag
        // Your additional code here
    }else{
        console.log("Not Executed")
    }
};

const container = document.querySelector('.writing-horizontal-tb');
container.addEventListener('click', runScript);