Torn Utils Library

Shared utility functions for Torn userscripts

이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/569328/1772270/Torn%20Utils%20Library.js을(를) 사용하여 포함하는 라이브러리입니다.

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

작성자
Paulo Pascoal
버전
1.0
생성일
2026-03-11
갱신일
2026-03-11
크기
2.67KB
라이선스
MIT

Torn Utils Library - Additional Info

Torn Utils Library – Additional Information

Overview

Torn Utils Library is a lightweight collection of helper functions designed for userscripts running on modern single-page applications (SPA), such as Torn.

Many pages dynamically load and update their interface without performing a full page refresh. Scripts that rely on traditional page load events can fail when elements have not yet been rendered.

This library provides utilities that make it easier to:

  • Wait for dynamically created elements
  • Observe DOM changes
  • Run code safely after the document is ready
  • Build more reliable userscripts for dynamic interfaces

All utilities are exposed under a single namespace: TornUtils. This prevents conflicts with other scripts and avoids polluting the global scope.

Installation

Include this library in your userscript using @require in the script header:

// @require https://update.greasyfork.org/scripts/569328/1772269/Torn%20Utils%20Library.js

Once included, access the utilities through TornUtils.

Available Functions

waitForElement(selector, timeout)

Waits until a DOM element matching the selector appears.

ParameterTypeDescription
selectorstringCSS selector of the element to wait for
timeoutnumberMaximum wait time in milliseconds (default: 10000)

Returns a Promise resolving with the element.

await TornUtils.waitForElement('#profile-container');
const element = document.querySelector('#profile-container');
console.log(element);

waitForElements(selector, timeout)

Waits until one or more elements matching the selector exist.

ParameterTypeDescription
selectorstringCSS selector of the elements
timeoutnumberMaximum wait time in milliseconds (default: 10000)

Returns a Promise resolving with a NodeList.

const items = await TornUtils.waitForElements('.item-row');
items.forEach(el => console.log(el.textContent));

observe(target, callback, options)

Creates a MutationObserver for a DOM element.

ParameterTypeDescription
targetElementDOM node to observe
callbackfunctionFunction executed on DOM mutations
optionsobjectMutationObserver config (default: { childList: true, subtree: true })

Returns the created MutationObserver instance.

const container = document.querySelector('#content');
const observer = TornUtils.observe(container, mutations => console.log('DOM changed'));

// Stop observing
observer.disconnect();

domReady()

Returns a promise that resolves when the DOM is fully loaded and ready for interaction.

await TornUtils.domReady();
console.log("DOM is ready");

Why Use This Library

Dynamic websites often render content asynchronously. Using these helpers makes scripts:

  • More reliable
  • Easier to maintain
  • Compatible with dynamic page updates

It avoids repeated setTimeout loops or fragile DOM checks, providing a structured approach to detecting elements.

Namespace

All functions are attached to window.TornUtils.

TornUtils.waitForElement(...);
TornUtils.observe(...);
TornUtils.domReady(...);

Compatibility

This library is designed for modern browsers that support:

  • ES6
  • Promises
  • MutationObserver