您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Framework with proper script communication
Torn Framework — GreasyFork Description
A lightweight, opinionated userscript framework for Torn modules — centralised logging, UI menu, module registration and cross-module communication.
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.
GM_setValue
/GM_getValue
GM_setValue
— store framework settings (console visible, menu visible, etc.)GM_getValue
— read settings on startunsafeWindow
— expose TornFramework
globally for other moduleshttps://www.torn.com/*
.Modules register themselves using TornFramework.registerModule(moduleConfig)
. The framework exposes helper functions and properties on window.unsafeWindow.TornFramework
.
// 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;
}
});
TornFramework.log(message, type = 'info', moduleName = 'FRAMEWORK')
— central logging into the framework console (types: error, success, warning, info, debug)TornFramework.modules
— Map
of registered modulesTornFramework.startTime
— epoch ms when the framework startedTornFramework.registerModule()
— register & optionally initialize a 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; }
});
});
})();
GM_setValue
.TornFramework
. Always check for existence before creating or re-registering objects — the framework already prevents multiple instances.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.