Common.Utils

Classes for your scripts

لا ينبغي أن لا يتم تثبيت هذا السكريت مباشرة. هو مكتبة لسكبتات لتشمل مع التوجيه الفوقية // @require https://update.greasyfork.org/scripts/389765/1785927/CommonUtils.js

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

المؤلف
Anton Shevchuk
الإصدار
0.1.0
تم إنشاؤه
04-09-2019
تم تحديثه
29-03-2026
الحجم
3.7 KB
الترخيص
MIT

Common Utils

Shared utility classes for WME (Waze Map Editor) userscripts.

Require Script

// @require https://greasyfork.org/scripts/389765-common-utils/code/CommonUtils.js?version=XXX

See last available version on the GreasyFork homepage

Development

npm install
npm run build       # one-off build → dist/Utils.user.js
npm run watch       # rebuild on changes

Source is written in TypeScript under src/, built with Rollup into dist/Utils.user.js.

src/
├── meta.ts          # userscript header
├── container.ts     # Container class
├── simple-cache.ts  # SimpleCache extends Container
├── settings.ts      # Settings extends Container
├── tools.ts         # Tools static class
└── index.ts         # exposes all classes to global scope

API

Container

A nested key-value store with path-based access:

let container = new Container()

// set nested values
container.set(['options', 'theme'], 'dark')
container.set(['options', 'lang'], 'uk')

// get nested values
container.get('options', 'theme')  // 'dark'
container.get('options')           // { theme: 'dark', lang: 'uk' }
container.get()                    // entire container

// check existence
container.has('options', 'theme')  // true
container.has('options', 'color')  // false

SimpleCache

Simplified Container with flat key-value interface:

let cache = new SimpleCache()

cache.set('key', result)
cache.has('key')          // true
cache.get('key')          // result

Settings

Container backed by localStorage. Loads on construction, merges stored values over defaults:

// load settings (merges localStorage data over defaults)
let settings = new Settings('my-script', {
  enabled: true,
  radius: 200
})

// read
settings.get('enabled')    // true
settings.get('radius')     // 200

// update
settings.set(['radius'], 500)

// save to localStorage (call before page unload)
settings.save()

With jQuery:

$(window).on('beforeunload', () => settings.save())

Tools

Static utility methods:

// deep merge objects (preserves nested structure)
let result = Tools.mergeDeep({}, defaults, overrides)

// check if value is a plain object
Tools.isObject({})     // true
Tools.isObject([])     // false
Tools.isObject(null)   // false

Links

Author homepage: https://anton.shevchuk.name/
Script homepage: https://github.com/AntonShevchuk/common.utils
GreasyFork: https://greasyfork.org/uk/scripts/389765-common-utils