hookPropertyName

hook property name

สคริปต์นี้ไม่ควรถูกติดตั้งโดยตรง มันเป็นคลังสำหรับสคริปต์อื่น ๆ เพื่อบรรจุด้วยคำสั่งเมทา // @require https://update.greasyfork.org/scripts/485962/1319216/hookPropertyName.js

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

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.

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

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

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

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

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

// ==UserScript==
// @name         hookPropertyName
// @namespace    http://tampermonkey.net/
// @version      0.1.0
// @description  hook property name
// @author       Gnosis
// ==/UserScript==

function hookPropertyName(prop, getter, setter) {
    const raw_prop = prop + '$raw'
    const has_getter = typeof getter === 'function'
    const has_setter = typeof setter === 'function'
    Object.defineProperty(Object.prototype, prop, {
        get() {
            return has_getter ? (getter.call(this, this[raw_prop]) ?? this[raw_prop]) : this[raw_prop]
        },
        set(val) {
            this[raw_prop] = has_setter ? ((setter.call(this, this[raw_prop], val)) ?? val) : val
        }
    })
}