Upload 2 files
Browse files- colab-timer.js +122 -0
- colabTimer.txt +1 -0
colab-timer.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
let startTime;
|
| 2 |
+
let timeout;
|
| 3 |
+
let myHeaders = new Headers();
|
| 4 |
+
myHeaders.append("Bypass-Tunnel-Reminder", "Thanks for checking my code lol")
|
| 5 |
+
myHeaders.append("ngrok-skip-browser-warning", "Seriously tho, thank you so much!")
|
| 6 |
+
|
| 7 |
+
function updateTimer(el) {
|
| 8 |
+
const a = (i) => (i < 10 ? "0" + i : i);
|
| 9 |
+
const b = (x) => Math.floor(x);
|
| 10 |
+
let c = b(Date.now() / 1000) - startTime;
|
| 11 |
+
h = a(b(c / 3600));
|
| 12 |
+
m = a(b((c / 60) % 60));
|
| 13 |
+
s = a(b(c % 60));
|
| 14 |
+
// console.log(h,m,s)
|
| 15 |
+
|
| 16 |
+
// show different text betwen 4:58 and 5:15
|
| 17 |
+
if (c > 298 && c < 315) {
|
| 18 |
+
el.innerText =
|
| 19 |
+
"Usually there's captcha at this time, please check your colab (" +
|
| 20 |
+
h +
|
| 21 |
+
":" +
|
| 22 |
+
m +
|
| 23 |
+
":" +
|
| 24 |
+
s +
|
| 25 |
+
")";
|
| 26 |
+
} else {
|
| 27 |
+
el.innerText = h + ":" + m + ":" + s;
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
//refresh timer every 30 seconds
|
| 31 |
+
if (c % 30 == 0) {
|
| 32 |
+
refreshTimer(el, true);
|
| 33 |
+
return;
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
timeout = setTimeout(() => updateTimer(el), 1000);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
refreshTimer = (timerEl, notext = false) => {
|
| 40 |
+
if (timeout) {
|
| 41 |
+
clearTimeout(timeout);
|
| 42 |
+
timeout = null;
|
| 43 |
+
}
|
| 44 |
+
if (!notext) timerEl.innerText = "Connecting...";
|
| 45 |
+
fetch("file=static/colabTimer.txt", { cache: "no-store", headers: myHeaders })
|
| 46 |
+
.then((response) => {
|
| 47 |
+
if (response.status == 404) {
|
| 48 |
+
timerEl.innerText = "Error. Colab disconnected!";
|
| 49 |
+
return;
|
| 50 |
+
}
|
| 51 |
+
response.text().then((text) => {
|
| 52 |
+
startTime = parseInt(text);
|
| 53 |
+
if (isNaN(startTime))
|
| 54 |
+
timerEl.innerText = "Error. NaN stuff... Maybe network error";
|
| 55 |
+
else updateTimer(timerEl);
|
| 56 |
+
});
|
| 57 |
+
})
|
| 58 |
+
.catch((err) => {
|
| 59 |
+
console.log(err);
|
| 60 |
+
timerEl.innerText = "Error. "+err;
|
| 61 |
+
});
|
| 62 |
+
};
|
| 63 |
+
|
| 64 |
+
toggleNotification = (imgEl, audioEl, divEl) => {
|
| 65 |
+
audioEl.muted = !audioEl.muted
|
| 66 |
+
audioEl.currentTime = 0;
|
| 67 |
+
audioEl.play();
|
| 68 |
+
divEl.title = !audioEl.muted ? "Currently not-muted. Click to mute" : "Currently muted. Click to unmute";
|
| 69 |
+
divEl.style.borderColor =
|
| 70 |
+
!audioEl.muted
|
| 71 |
+
? "#00ff00"
|
| 72 |
+
: "#ff0000";
|
| 73 |
+
imgEl.src = audioEl.muted ? "https://api.iconify.design/ion:md-notifications-off.svg?color=%23ff0000" : "https://api.iconify.design/ion:md-notifications.svg?color=%2300ff00";
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
onUiLoaded(function () {
|
| 77 |
+
const quickSettings = gradioApp().querySelector("#quicksettings");
|
| 78 |
+
const audioEl = gradioApp().querySelector("#audio_notification > audio")
|
| 79 |
+
|
| 80 |
+
if (gradioApp().querySelector("#nocrypt-timer") != null) return;
|
| 81 |
+
|
| 82 |
+
let mainDiv = document.createElement("div");
|
| 83 |
+
mainDiv.id = "nocrypt-timer";
|
| 84 |
+
mainDiv.className = "justify-start";
|
| 85 |
+
mainDiv.style = "gap: 10px; user-select: none; margin-block: -10px; transform-origin: left center; scale: 0.8; display:flex;";
|
| 86 |
+
|
| 87 |
+
let div2 = document.createElement("div");
|
| 88 |
+
div2.className = "gr-box";
|
| 89 |
+
div2.style =
|
| 90 |
+
"gap: 0.5rem; border-radius:10px; display:flex;align-items:center;border-width:1px; display:flex; cursor: pointer; padding-block: 3px; width: fit-content; padding-inline: 5px; border-color: orange; z-index: 999; background-color: transparent !important;";
|
| 91 |
+
div2.title = "Colab Timer Integration by NoCrypt. Click to refresh.";
|
| 92 |
+
|
| 93 |
+
let img = document.createElement("img");
|
| 94 |
+
img.src =
|
| 95 |
+
"https://ssl.gstatic.com/colaboratory-static/common/de56aa663d279b80074b6c21f69dc872/img/favicon.ico";
|
| 96 |
+
img.width = 24;
|
| 97 |
+
|
| 98 |
+
let timerEl = document.createElement("div");
|
| 99 |
+
timerEl.style = "font-family: monospace;color: orange;";
|
| 100 |
+
timerEl.innerText = "Connecting...";
|
| 101 |
+
div2.appendChild(img);
|
| 102 |
+
div2.appendChild(timerEl);
|
| 103 |
+
mainDiv.appendChild(div2);
|
| 104 |
+
div2.onclick = () => refreshTimer(timerEl);
|
| 105 |
+
|
| 106 |
+
let div3 = document.createElement("div");
|
| 107 |
+
div3.className = "gr-box";
|
| 108 |
+
div3.style =
|
| 109 |
+
"gap: 0.5rem; border-radius:10px; display:flex;align-items:center;border-width:1px; display:flex; cursor: pointer; padding-block: 3px; width: fit-content; padding-inline: 5px; border-color: lime; z-index: 999; background-color: transparent !important;";
|
| 110 |
+
div3.title = "Currently not-muted. Click to mute";
|
| 111 |
+
|
| 112 |
+
let img2 = document.createElement("img");
|
| 113 |
+
img2.src =
|
| 114 |
+
"https://api.iconify.design/ion:md-notifications.svg?color=%2300ff00";
|
| 115 |
+
img2.width = 20;
|
| 116 |
+
div3.appendChild(img2);
|
| 117 |
+
div3.onclick = () => toggleNotification(img2, audioEl, div3);
|
| 118 |
+
mainDiv.appendChild(div3);
|
| 119 |
+
|
| 120 |
+
quickSettings.parentNode.insertBefore(mainDiv, quickSettings.nextSibling);
|
| 121 |
+
refreshTimer(timerEl);
|
| 122 |
+
});
|
colabTimer.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
1690279131
|