您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
See the birthdates of neopets and their petpets on their pet lookup.
当前为
// ==UserScript== // @name Grundos Cafe Pet Birthday Display // @namespace http://tampermonkey.net/ // @version 1.1 // @description See the birthdates of neopets and their petpets on their pet lookup. // @author Dij // @match https://www.grundos.cafe/petlookup/* // @match http://www.grundos.cafe/petlookup/* // @match https://grundos.cafe/petlookup/* // @match http://grundos.cafe/petlookup/* // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @grant none // @license GPL 3.0 // ==/UserScript== let style = document.createElement("style"); style.innerHTML = ` .tooltip { text-decoration:underline; text-decoration-style:dotted; } .tooltip>span { color:white; position:absolute; opacity:0; background-color:rgba(0,0,0,0.8); padding:5px; transition:opacity 0.2s; width:10em; transform:translate(-9em, 2em); text-align:center; } .tooltip:hover>span { opacity:1; transition:opacity 0.2s; } .tooltip>span::before { content:""; width:0px; height:0px; position:absolute; border-style:solid; border-color:rgba(0,0,0,0.8) transparent; border-width: 0 10px 10px 10px; top:-10px; left:calc(5em - 5px); }`; function subtractHours(date, hours, minutes) { date.setHours(date.getHours() - hours); date.setMinutes(date.getMinutes()- minutes) return date; } function format(a, b) { let adate = a.toDateString() let atime = `${a.getHours()}:${a.getMinutes().toString().padStart(2,0)}`; let bdate = b.toDateString(); let btime = `${b.getHours()}:${b.getMinutes().toString().padStart(2,0)}`; let bhours = b.getHours() if (adate == bdate) { return `${adate}, at about <span class="tooltip">${bhours}:00 NST<span>${adate}, ${atime}-${btime} NST</span></span>`; } return `${bdate}, at about <span class="tooltip">${bhours}:00 NST<span>${adate}, ${atime} - ${bdate}, ${btime} NST</span></span>`; } function calculateAge(age, element, prepend) { let basetime = new Date(); const clock = document.getElementById("sb_clock").querySelector(".nst").innerText; let hrs = Number(document.getElementById("NST_clock_hours").innerText); if (clock.charAt(clock.length-6 == "p")) { hrs = hrs + 12; } basetime.setHours(hrs); basetime.setMinutes(document.getElementById("NST_clock_minutes").innerText); const a = subtractHours(new Date(basetime), age, 59); const b = subtractHours(new Date(basetime), age, 0); let NSTstring = format(a, b); const bday = document.createElement("div"); bday.innerHTML = `${prepend}${NSTstring}`; element.parentNode.insertAdjacentElement("beforeend" ,bday); } function ageToNumber(text) { return Number(text.replace(",", "")); } function parsePPAge(element) { const re = /\((?:(\d+)\ days|).*?(\d+) hours/; let match = element.innerHTML.match(re); console.log(typeof match[2]); let age = ageToNumber(match[2]); if (match[1]) { age = age + (ageToNumber(match[1]) * 24); } return calculateAge(age, element, "Adopted: "); } (function() { 'use strict'; try { let petAgeHrs = document.querySelector("#petStats .pet--age strong:nth-child(3)"); let ageNum = ageToNumber(petAgeHrs.innerText); document.head.appendChild(style); calculateAge(ageNum, petAgeHrs, '<strong>Born</strong> : '); let petpetages = document.querySelectorAll(".pet--petpetage"); if(petpetages.length > 0){ Array.from(petpetages).forEach(parsePPAge); } } catch (error) { window.onload = function() { alert(`Birthday Display error, please notify Dij: ${error}`); } } })();