Torn Framework

Framework with proper script communication

作者
Duo Gaming
日安装量
1
总安装量
5
评分
0 0 0
版本
2.1
创建于
2025-09-24
更新于
2025-09-27
大小
12.0 KB
许可证
暂无
适用于

Torn Framework — GreasyFork Description


Torn Framework v2.1

A lightweight, opinionated userscript framework for Torn modules — centralised logging, UI menu, module registration and cross-module communication.

Framework for modules
Works with Tampermonkey / Greasemonkey / Violentmonkey


Short summary

Torn Framework provides a global TornFramework object that other userscripts (modules) can use to register themselves, log messages to a consistent console UI, and inject module-specific UI sections in a central framework menu. It does not change gameplay — it only offers shared infrastructure for your Torn userscripts.



Why use it?

  • Standardised, colour-coded debug console shared between modules
  • Central module menu with status, uptime, and per-module UI sections
  • Simple API for registering/initializing/cleaning up modules
  • Persistent settings storage via GM_setValue/GM_getValue
  • Prevents duplicate framework instances and exposes a stable global object


Permissions / Grants

  • GM_setValue — store framework settings (console visible, menu visible, etc.)
  • GM_getValue — read settings on start
  • unsafeWindow — expose TornFramework globally for other modules


Quick install

  1. Install a user script manager (Tampermonkey / Violentmonkey / Greasemonkey).
  2. Create a new userscript and paste the framework code (the script header should include the three grants above).
  3. Save and enable the script. The framework automatically injects its console and menu on https://www.torn.com/*.


API — how modules should integrate

Modules register themselves using TornFramework.registerModule(moduleConfig). The framework exposes helper functions and properties on window.unsafeWindow.TornFramework.

Primary API

// register a module
TornFramework.registerModule({
  name: 'MyModule',
  version: '1.0',
  description: 'Does clever stuff',
  menuSection: '
My module UI here
', initialize: function(){ // called immediately after register (if provided) }, cleanup: function(){ // optional: called if module wants to cleanup }, isActive: function(){ // return true/false for active state in framework status return true; } });

Utilities

  • TornFramework.log(message, type = 'info', moduleName = 'FRAMEWORK') — central logging into the framework console (types: error, success, warning, info, debug)
  • TornFramework.modulesMap of registered modules
  • TornFramework.startTime — epoch ms when the framework started
  • TornFramework.registerModule() — register & optionally initialize a module


Example: a tiny "hello" module

// Example userscript (module) - register with the framework
(function(){
  'use strict';
  // wait for framework to exist
  function whenReady(cb){
    if (window.TornFramework && TornFramework.registerModule) return cb();
    setTimeout(() => whenReady(cb), 150);
  }

  whenReady(function(){
    TornFramework.registerModule({
      name: 'HelloModule',
      version: '0.1',
      description: 'Simple demo module',
      menuSection: `
        <div>
          <h4>HelloModule</h4>
          <button id="helloBtn">Say hello</button>
        </div>`,
      initialize: function(){
        TornFramework.log('HelloModule init', 'info', 'HelloModule');
        document.getElementById('helloBtn')?.addEventListener('click', () => {
          TornFramework.log('Hello from HelloModule', 'success', 'HelloModule');
          alert('Hello from HelloModule!');
        });
      },
      isActive: function(){ return true; }
    });
  });
})();


UI & behaviour

  • Console: fixed, collapsible, colour-coded logs with timestamps. Can be enabled/disabled via framework settings.
  • Menu: top-right floating menu that lists modules, active count, uptime, and allows each module to inject its own UI section.
  • Settings persist across page reloads via GM_setValue.


Development notes


Important: Modules should avoid directly re-defining TornFramework. Always check for existence before creating or re-registering objects — the framework already prevents multiple instances.


Changelog (high level)

  • v2.1 — UI polishing, persistent settings, improved logging, safer module registration.
  • v2.0 — Initial public rewrite: module map, menu sections, uptime/status.
  • v1.x — Early prototypes and internal testing.


Support / Contribution

If you want to report bugs, suggest API changes, or contribute modules, include a short description and a minimal reproduction. When posting issues, include your userscript manager (Tampermonkey/GreaseMonkey) and browser/version.

Suggested channels: the GreasyFork comments for this script or your project's repo/PMs.



License: MIT (recommended)
Last updated: Sep 2025