Skip to content

Instantly share code, notes, and snippets.

@ZiTAL
Last active June 6, 2025 11:07
Show Gist options
  • Save ZiTAL/66ff1b5d0f6b3db162300011cf1f35a4 to your computer and use it in GitHub Desktop.
Save ZiTAL/66ff1b5d0f6b3db162300011cf1f35a4 to your computer and use it in GitHub Desktop.
Tortolika: Gaurko egunean daramazun denbora kopura erakusten dizun tooltip-a
// ==UserScript==
// @name Tortolika Checker
// @namespace tortolika
// @version 1.0
// @description Tortolikako orduak
// @author ibantxi
// @match *://*tortolika.eitb.eus/*
// ==/UserScript==
(function () {
'use strict'
async function getHtml()
{
const url = 'https://tortolika.eitb.eus/kalitatea/Mod_SSE/euskera/fichajes2.asp'
const response = await fetch(url,
{
credentials: 'include'
})
const html = await response.text()
const parser = new DOMParser()
const doc = parser.parseFromString(html, 'text/html')
return doc
}
function isIframe()
{
return !(window.top === window.self)
}
function showToast(message)
{
const toast = document.createElement('div')
toast.textContent = message
Object.assign(toast.style,
{
position: 'fixed',
bottom: '20px',
right: '20px',
background: '#1971c2',
color: '#fff',
padding: '10px 16px',
borderRadius: '8px',
boxShadow: '0 4px 8px rgba(0,0,0,0.2)',
zIndex: 9999,
fontSize: '14px',
fontFamily: 'sans-serif',
cursor: 'pointer',
opacity: '0',
transition: 'opacity 0.3s ease'
})
toast.addEventListener('click', () =>
{
toast.style.opacity = '0'
setTimeout(() => toast.remove(), 300)
})
document.body.appendChild(toast)
requestAnimationFrame(() =>
{
toast.style.opacity = '1'
})
}
function parseTimeText(text)
{
const match = text.match(/^\s*([0-9]{2}):([0-9]{2})/)
if (!match)
return null
return {
hours: parseInt(match[1], 10),
minutes: parseInt(match[2], 10)
}
}
function showNotification(title, message)
{
showToast(`${title}: ${message}`)
}
async function updateInfo()
{
const doc = await getHtml()
const date = new Date()
const date_str = date.toISOString().split('T')[0].replace(/-/g, '/')
// Busca el elemento con la fecha actual
const bold_date_span = [...doc.querySelectorAll("span.NegritaNegro12")]
.find(el => el.textContent.trim() === date_str)
if (!bold_date_span)
{
showNotification("Errorea", "Logeatu behar zara")
return
}
const total_span = bold_date_span.parentElement.querySelector("span.NormalNegro12.totals > b")
const last_fichaje_spans = bold_date_span.parentNode.querySelectorAll('span.NormalAzul12')
if (!total_span || last_fichaje_spans.length === 0)
{
showNotification("Errorea", "E_UNKNOW");
return
}
const total_time = parseTimeText(total_span.textContent)
const last_fichaje = parseTimeText(last_fichaje_spans[last_fichaje_spans.length - 1].textContent)
if (!total_time || !last_fichaje)
{
showNotification("Errorea", "E_UNKNOW")
return
}
const now = new Date()
const last_date = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate(),
last_fichaje.hours,
last_fichaje.minutes
)
const seconds_since_last = Math.floor((now - last_date) / 1000)
const total_seconds = total_time.hours * 3600 + total_time.minutes * 60 + seconds_since_last
const h = String(Math.floor(total_seconds / 3600)).padStart(2, '0')
const m = String(Math.floor((total_seconds % 3600) / 60)).padStart(2, '0')
const n = `${h}:${m}`
showNotification("Gaurko denbora", n)
}
if(isIframe()===false)
updateInfo()
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment