Skip to content

Instantly share code, notes, and snippets.

@MarkoSh
MarkoSh / queue.js
Last active September 6, 2025 09:48
class RequestQueue {
queue: Promise<void> = Promise.resolve();
constructor() {
const $this = this;
}
async add(fn: any) {
const $this = this;
class WorkerTimeout {
worker = null;
constructor(callback, timeout) {
const $this = this;
const blob = new Blob([`setTimeout(() => postMessage(0), ${timeout});`]);
const workerScript = URL.createObjectURL(blob);
$this.worker = new Worker(workerScript);
$this.worker.onmessage = () => {
callback();
$this.worker.terminate();
class WorkerInterval {
worker = null;
constructor(callback, interval) {
const $this = this;
const blob = new Blob([`setInterval(() => postMessage(0), ${interval});`]);
const workerScript = URL.createObjectURL(blob);
$this.worker = new Worker(workerScript);
$this.worker.onmessage = callback;
}
@MarkoSh
MarkoSh / doNotThrottleMyTimers.js
Created December 30, 2024 22:01
Disable throttling functions like setTimeout, setInterval in inactive tabs in Chrome
function doNotThrottleMyTimers() {
const audioContext = new AudioContext();
const constantSource = audioContext.createConstantSource();
constantSource.connect(audioContext.destination);
constantSource.start();
}
@MarkoSh
MarkoSh / URL.js
Last active September 15, 2025 15:04
URL = new Proxy(URL, {
construct(target, args: [string]) {
const url: any = new target(...args);
if (url.hash) {
const hashString = url.hash.startsWith('#') ? url.hash.slice(1) : url.hash;
url.hashParams = new URLSearchParams(hashString);
}
// Добавляем свойство pathSegments, разбивая pathname на массив
@MarkoSh
MarkoSh / XMLHttpRequest.js
Last active September 15, 2025 15:04
Replace XMLHttpRequest
XMLHttpRequest = new Proxy( XMLHttpRequest, {
construct( target ) {
const xhr: any = new target();
( (
open,
setRequestHeader,
send,
onreadystatechange
) => {
@MarkoSh
MarkoSh / js
Last active May 23, 2024 22:40
Remove WebSocket from browser
WebSocket = new Proxy( WebSocket, {
construct( target, args ) {
return {}; // Safety remove WS from browser =)
}
} );
@MarkoSh
MarkoSh / functions.php
Last active February 11, 2018 09:46
Woocommerce count items in cookie
add_action( 'wp', 'woocommerce_set_custom_cookie', 100 );
add_action( 'woocommerce_add_to_cart_handler', 'woocommerce_set_custom_cookie' );
function woocommerce_set_custom_cookie() {
setcookie( 'woocommerce_cart_contents_count', WC()->cart->cart_contents_count, 0, '/' );
}
@MarkoSh
MarkoSh / functions.php
Created February 11, 2018 09:42
Woocommerce all js params
add_action( 'wp_head', 'woo_js_params', 99 );
function woo_js_params() {
?>
<script>
<?php
$vars = array(
'woocommerce' => array(
'ajax_url' => WC()->ajax_url() ,
'wc_ajax_url' => WC_AJAX::get_endpoint("%%endpoint%%") ,
) ,
@MarkoSh
MarkoSh / functions.php
Last active February 11, 2018 09:43
WooCommerce total disable
add_filter( 'woocommerce_enqueue_styles', '__return_empty_array' );
add_action( 'wp_head', 'disable_woo', 99 );
function disable_woo() {
global $wp_scripts, $wp_styles;
$scripts = array(
'accounting',
'wc-jquery-ui-touchpunch',
'wc-price-slider',
'flexslider',