This code defines a **UserScript**, a type of script often...

September 3, 2025 at 12:16 PM

// ==UserScript== // @name Auto Loot // @namespace https://blog.chrxw.com // @version 1.2 // @description lootlink.me 自动领取日常奖励,自动抽奖 // @author Chr_ // @include https://www.lootlink.me/* // @license AGPL-3.0 // @icon https://blog.chrxw.com/favicon.ico // @grant none // @downloadURL https://update.greasyfork.org/scripts/420104/Auto%20Loot.user.js // @updateURL https://update.greasyfork.org/scripts/420104/Auto%20Loot.meta.js // ==/UserScript== (function () { 'use strict'; showLabel(); dailyClaim(); add10xBtn(); })(); // 显示标签 function showLabel() { let uname = document.querySelector('#profileMenuInvoker>span'); let tag1 = document.createElement('span'); tag1.textContent = ' (反馈 '; tag1.addEventListener('click', () => { window.open('https://keylol.com/t676764-1-1'); }); let tag2 = document.createElement('span'); tag2.textContent = '| By Chr_) '; tag2.addEventListener('click', () => { window.open('https://blog.chrxw.com'); }); uname.appendChild(tag1); uname.appendChild(tag2); } // 每日签到&自动开箱 function dailyClaim() { const MAX = 20; let tries = 0; clickDaily(); function clickDaily() { let coin = document.querySelector('#wallet2 a[data-modal-target="#crate-modal"]'); if (coin) { coin.click(); tries = 0; retry(claimCoin, 1000); } else { let coin = document.querySelector('#wallet2 div:not([style*="display:none"])>[src="/images/art/crate.png"]:not(.grayscale)'); if (coin) { coin.parentElement.click(); tries = 0; retry(claimCoin, 1000); } } } function claimCoin() { let claimbtn = document.querySelector("#cratetab > a"); if (claimbtn) { claimbtn.click(); tries = 0; retry(closePanel, 1000); } else { retry(claimCoin, 500); } } function closePanel() { let title = document.querySelector("#cratetab > h4"); if (title.textContent.search('Opened') != -1 || title.textContent.search('Received') != -1) { let closebtn = document.querySelector("#crate-modal > button"); closebtn.click(); window.location.reload(); } else { retry(closePanel, 500); } } function retry(foo, t) { console.log(foo.name); if (tries++ <= MAX) { setTimeout(() => { try { foo(); } catch (e) { console.log(e); throw e; } }, t); } else { console.log('操作超时'); } } } // 添加x连按钮 function add10xBtn() { function genBtn(txt, time, index) { let btn = document.createElement('button'); console.log('loot' + time.toString() + 'x' + (index).toString()) btn.id = 'loot' + time.toString() + 'x' + (index).toString(); btn.onclick = loot10x; btn.className = 'float-right btn btn-lg u-btn-cyan g-color-white u-btn-hover-v2-1'; btn.textContent = txt; return btn; } let lootBtns = document.querySelectorAll('button[data-modal-target="#loot-modal"]'); let i = 0; for (let lootBtn of lootBtns) { let bar = lootBtn.parentElement.parentElement.children[0]; let box = document.createElement('div'); let btn5x = genBtn('五连', 5, i); let btn10x = genBtn('十连', 10, i); let btn100x = genBtn('梭哈', 100, i); box.appendChild(btn5x); box.appendChild(btn10x); box.appendChild(btn100x); bar.insertBefore(box, bar.children[0]); i++; } } // x连 function loot10x(e) { const MAX = 50; let LOOT = 0; let tries = 0; let count = 0; clickLoot(); function clickLoot() { let id = e.target.getAttribute('id'); let t = id.match(/^loot(\d+)x(\d+)$/); t = t ? [t[1], t[2]] : [0, 0]; let lootBtns = document.querySelectorAll('button[data-modal-target="#loot-modal"]'); if (lootBtns == null) { alert('未找到Loot按钮'); return; } LOOT = Number(t[0]); lootBtns[Number(t[1])].click(); tries = 0; retry(claimLoot, 1000); } function claimLoot() { let lootbtn = document.querySelector('#rollit'); if (lootbtn) { document.getElementById('rollmessage').textContent = '第' + (count + 1).toString() + '/' + LOOT.toString() + '抽'; lootbtn.click(); tries = 0; retry(waitLoot, 1000); } else { retry(claimLoot, 1000); } } function waitLoot() { let lootbtn = document.querySelector("#rollit"); if (lootbtn.textContent.search('Try') != -1) { if (++count >= LOOT) { document.getElementById('rollmessage').textContent = '抽完啦'; console.log('done'); return; } tries = 0; retry(claimLoot, 1000); } else { retry(waitLoot, 1000); } } function retry(foo, t) { console.log(foo.name); if (tries++ <= MAX) { setTimeout(() => { try { if (document.getElementById('rolltab') == null) { console.log('cancel'); return; } foo(); } catch (e) { console.log(e); throw e; } }, t); } else { console.log('操作超时'); } } }

This code defines a UserScript, a type of script often used with userscript managers like Tampermonkey or Greasemonkey, designed to modify or enhance the functionality of a specific website—in this case, https://www.lootlink.me/. Here's what the script does in detail:

General Overview:

The script automates multiple actions on the lootlink.me website:

  1. Adds labels for user feedback.
  2. Automates daily actions (claiming daily rewards and opening loot crates).
  3. Adds buttons for multi-loot actions (e.g., "5 consecutive draws", "10 consecutive draws", "all draws").
  4. Handles retrying actions in case certain elements are not yet loaded.
  5. Provides notifications or updates on the progress of automated tasks.

Detailed Functionality:

  1. Metadata Block:
    • Specifies details about the script like its name, version, author, description, what sites it applies to (@include), and URLs for updates/downloads.
    • For example:
      • Name: "Auto Loot"
      • URL applies to: https://www.lootlink.me/*

  1. Immediately Invoked Function Expression (IIFE):
    • The script is encapsulated in an IIFE ((function () { ... })()) to avoid polluting the global namespace.
    • Calls three main functions when executed:
      • showLabel()
      • dailyClaim()
      • add10xBtn()

  1. Function Descriptions:

    a) showLabel()

    • Adds custom feedback labels/buttons (e.g., "反馈" and "By Chr_") next to the user's profile menu.
    • These labels:
      • Navigate users to feedback and developer-related web pages when clicked.

    b) dailyClaim()

    • Automates daily actions like claiming daily rewards and opening crates.
    • Key Actions:
      1. Check if daily reward crates are available:
        • Looks for clickable elements like coin icons or crate images.
        • Triggers their click events.
      2. Claim the rewards:
        • Finds and clicks the "claim" button inside the crate modal.
      3. Close the modal:
        • Waits for confirmation that the crate reward is opened or received, then closes the modal.
      4. Handles retries:
        • Utilizes a retry mechanism to handle cases where the elements might not have loaded instantly.

c) add10xBtn()

  • Dynamically adds custom buttons for multi-loot actions next to existing loot buttons.
  • Buttons include:
    • "五连" (5 consecutive draws)
    • "十连" (10 consecutive draws)
    • "梭哈" (100 consecutive draws)
  • Each button is configured to trigger the loot10x function upon clicking.

d) loot10x(e)

  • Automates a multi-loot process (triggered by the buttons added by add10xBtn()).
  • Key Operations:
    1. Determines the desired number of draws based on the clicked button's ID.
    2. Initiates the multi-loot process by clicking loot buttons.
    3. Keeps track of loot progress and displays updates (e.g., "抽完啦" which translates to "Done with draws").
    4. Uses a retry mechanism to wait for each loot action to complete before proceeding.
    5. Handles situations where the required elements are missing or actions timeout.

  1. Retry Mechanisms:
    • Several functions (retry(foo, t)) help handle asynchronous or lag-prone scenarios:
      • Retries a task (foo) up to a specified maximum number of times (MAX).
      • Waits for a specified timeout (t) between attempts, ensuring the DOM elements have time to load.

Summary:

This script automates daily interactions and multi-loot actions on the lootlink.me website. It enhances the UX by offering streamlined operations (e.g., "daily claim", "multi-loot"), adding custom feedback links, and handling user interaction in an optimized manner. The script relies heavily on DOM manipulation, event listeners, and retry mechanisms to manage asynchronous processes effectively.

Generate your own explanations
Download our vscode extension
Read other generated explanations

Built by @thebuilderjr
Sponsored by beam analytics
Read our terms and privacy policy
Forked from openai-quickstart-node