Greasy Fork is available in English.

Cookie Manager

For Developers Only. Control Cookies everywhere via DevTools

Autor
𝖢𝖸 𝖥𝗎𝗇𝗀
Instalações hoje
0
Total de instalações
157
Avaliações
0 0 0
Versão
0.5
Criado
21/12/2022
Atualizado
10/01/2023
Licença
MIT
Aplicável a
Todos os sites

This script, named "Cookie Manager", is a UserScript that is intended to be used by developers for managing cookies on a website via the developer console. It allows developers to get, set, and remove cookies using simple commands, as well as create new cookie "chefs" with specific parameters. It does so by injecting a proxy object, cook, into the unsafeWindow scope, which is an alias for the standard JavaScript global object window in Tampermonkey and other UserScript environments.

Here is a more detailed breakdown of the key components:

  1. @require: The script includes the library js-cookie, a powerful and easy-to-use JavaScript library that simplifies working with cookies. This library provides a simple, straightforward API for managing cookies, such as setting, getting, and deleting them.

  2. Initialization: The script immediately calls an anonymous function with the Cookies object from js-cookie as an argument. Inside this function, the get, set, and remove methods from Cookies are deconstructed and saved for later use.

  3. Chef Function: The script defines a function named chefFunc. This function is used to create new cookie "chefs", i.e., versions of the Cookies object with specific converters and attributes. This function is then bound to the Cookies object and added to the target object.

  4. Proxy Object: The script creates a Proxy object that is assigned to unsafeWindow.cook. The Proxy object intercepts and defines custom behavior for fundamental operations on the object it wraps. In this case, the Proxy is used to allow getting and setting cookies using dot notation. For example, cook.myvar = 'abc' sets a cookie named 'myvar' with a value of 'abc', and cook.myvar retrieves the value of the 'myvar' cookie.

The usage examples at the top of the script demonstrate how to use these capabilities. For example, cook.set('hello-world',100) sets a cookie named 'hello-world' with a value of 100, and cook.get('hello-world') retrieves the value of the 'hello-world' cookie.

This script is intended for use in the context of a browser's DevTools console, allowing developers to easily manage cookies on a website for development and testing purposes. It has a MIT license and is expected to be used on all HTTP and HTTPS websites.