Skip to content

Instantly share code, notes, and snippets.

@walditamaniko
Last active February 17, 2026 10:18
Show Gist options
  • Select an option

  • Save walditamaniko/6ec0340486bf25d81de975df5552dbba to your computer and use it in GitHub Desktop.

Select an option

Save walditamaniko/6ec0340486bf25d81de975df5552dbba to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name TM-Auto Copy Email (Fixed Race Condition)
// @namespace http://tampermonkey.net/
// @version 7.0
// @description Menggunakan Dual-Hashing (Normal & Reverse) untuk menjamin slot unik meskipun terjadi tabrakan awal.
// @author Nicholas
// @match *://*/*
// @grant GM_setClipboard
// ==/UserScript==
(function() {
'use strict';
// CONFIG
const BASE_DELAY = 1500; // Waktu start awal (1.5 detik)
const SLOT_TIME = 300; // Kita percepat jadi 0.3 detik per slot (biar total ngga lama)
const TOTAL_SLOTS = 60; // Perbanyak slot jadi 60 agar makin jarang tabrakan
// Fungsi Hashing Sederhana
function getHash(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
hash = str.charCodeAt(i) + ((hash << 5) - hash);
}
return Math.abs(hash);
}
// Fungsi Copy Inti
function performCopy(text, source) {
GM_setClipboard(text, { type: 'text', mimetype: 'text/plain' });
console.log(`✅ EKSEKUSI (${source}): ${text}`);
// Kita update title dengan tanda centang ganda jika sudah 2x
if(document.title.includes("✅")) {
document.title = `✅✅ ${text}`;
} else {
document.title = `✅ ${text}`;
}
}
function findAndCopyEmail() {
// Stop jika sudah sukses 2x (Double check)
if (document.title.includes("✅✅")) return true;
const emailRegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}/g;
const pageText = document.body.innerText;
const emails = pageText.match(emailRegex);
if (emails && emails.length > 0) {
const filteredEmails = emails.filter(email => !email.toLowerCase().includes('tidal'));
if (filteredEmails.length > 0) {
const emailToCopy = filteredEmails[0];
// --- STRATEGI DOUBLE TAP ---
// 1. Hitung Slot UTAMA (Berdasarkan Email Normal)
const hash1 = getHash(emailToCopy);
const slot1 = hash1 % TOTAL_SLOTS;
const time1 = BASE_DELAY + (slot1 * SLOT_TIME);
// 2. Hitung Slot CADANGAN (Berdasarkan Email Dibalik + Garam)
// Ini menjamin jika Slot 1 tabrakan, Slot 2 pasti beda jauh.
const reversedEmail = emailToCopy.split("").reverse().join("") + "backup";
const hash2 = getHash(reversedEmail);
const slot2 = hash2 % TOTAL_SLOTS;
const time2 = BASE_DELAY + (slot2 * SLOT_TIME);
// Pastikan Slot 2 tidak sama dengan Slot 1 (geser kalau sama)
if (slot1 === slot2) {
time2 += 1000;
}
console.log(`Email: ${emailToCopy}`);
console.log(`Jadwal 1: Slot ${slot1} (${time1}ms)`);
console.log(`Jadwal 2: Slot ${slot2} (${time2}ms)`);
document.title = `⏳ Siap di Slot [${slot1}] & [${slot2}]`;
// JADWALKAN EKSEKUSI 1
setTimeout(() => {
performCopy(emailToCopy, "Slot Utama");
}, time1);
// JADWALKAN EKSEKUSI 2 (Backup)
setTimeout(() => {
performCopy(emailToCopy, "Slot Backup");
}, time2);
return true;
}
}
return false;
}
let attempts = 0;
const intervalId = setInterval(() => {
attempts++;
if (findAndCopyEmail() || attempts > 20) {
clearInterval(intervalId);
}
}, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment