Skip to content

Instantly share code, notes, and snippets.

@disco0
disco0 / index.md
Last active April 17, 2025 22:25
Imagus Sieve #doc

Imagus Seive Configuration

A basic outline on seive configuration in Imagus—based on previous posts by developer, with additions based on own usage.

Extension Implementation

Input Processing

Before it's sent to matching, every URL has its protocol and subdomain removed using the following regex:

@disco0
disco0 / webpack.configuration.devtool.d.ts
Last active September 30, 2020 23:05
TypeScript 4.1 Beta - Template Literal Type - Webpack Configuration `devtool` type
/**
* A basic example of TypeScript 4.1's new Template Literal types being used
* to enumerate a set of required possible literal types. Additional
* documentation comments at the bottom of each section with addtional info
* related to the actual content of the types.
*
* Playground link (make sure version is >= 4.1.0): https://tsplay.dev/PmL5aW
*/
//#region Utility types
@disco0
disco0 / index.d.ts
Last active January 31, 2022 02:51
TypeScript 4.1 - Template Literal Utility Types
// Copied with additions from querySelector template literal types example
type Split<S extends string, D extends string> = S extends `${infer T}${D}${infer U}` ? [T, ...Split<U, D>] : [S];
type SplitUnion<S extends string, D extends string> = Split<S, D>[number];
type TakeLast<V> = V extends [] ? never : V extends [string] ? V[0] : V extends [string, ...infer R] ? TakeLast<R> : never;
type TrimLeft<V extends string> = V extends ` ${infer R}` ? TrimLeft<R> : V;
type TrimRight<V extends string> = V extends `${infer R} ` ? TrimRight<R> : V;
type Trim<V extends string> = TrimLeft<TrimRight<V>>;
@disco0
disco0 / index.ts
Last active October 4, 2020 01:06
GM_addGlobalStyle
/**
* This function improves the GM_AddStyle function, enabling to add external CSS stylesheets, like the CodeMirror one.
* Modified version of [kaskus-code-mirror UserScript](http://userscripts.org/scripts/show/156308) (removed the gvar variable).
*/
function GM_addGlobalStyle(a, b, c)
{
var d, e;
if(a.match(/^http?:\/\/.+/))
{
d = createEl("link", {type: "text/css", rel: 'stylesheet', href: a});
@disco0
disco0 / parse-user-script.ts
Last active October 4, 2020 06:37
UserScript - Meta Parsing
'use strict';
const gAllMetaRegexp = new RegExp(
'^(\u00EF\u00BB\u00BF)?// ==UserScript==([\\s\\S]*?)^// ==/UserScript==',
'm');
/** Get just the stuff between ==UserScript== lines. */
function extractMeta(content)
{
const meta = content && content.match(gAllMetaRegexp);
@disco0
disco0 / asyncwhile.js
Created October 4, 2020 08:08 — forked from tyler-johnson/asyncwhile.js
Asynchronous while loop for ES6 Promises.
function asyncWhile(condition, action, ctx) {
var whilst = function(data) {
return condition.call(ctx, data) ?
Promise.resolve(action.call(ctx, data)).then(whilst) :
data;
}
return whilst();
}
@disco0
disco0 / window.onDOMscriptReady.js
Last active October 5, 2020 07:12
Browser Extension window.onload workaround
(() => {
let subscribers, observer;
// natively declared <script> elements in html can't have onload= attribute
// due to the default extension CSP that forbids inline code (and we don't want to relax it),
// so we're using MutationObserver to add onload event listener to the script element to be loaded
window.onDOMscriptReady = (srcSuffix, timeout = 1000) =>
{
if (!subscribers)
@disco0
disco0 / mixin.ts
Last active October 5, 2020 10:00
TypeScript - Mixin Class
type Constructor<T = {}> = new (...args: any[]) => T;
//#region Mixins
// A mixin that adds a property
function Timestampable<TBase extends Constructor>(Base: TBase)
{
return class extends Base
{
timestamp = Date.now();
@disco0
disco0 / indentDecorator.ts
Last active October 19, 2020 22:54
TypeScript - Indent control method decorator
/**
* NOTE: Use browser console
*
* @playground <https://tsplay.dev/KwXl8w>
*/
//#region Declarations
export type NaturalNumber = Number & Partial<{__brand?: null}>
@disco0
disco0 / readme.md
Created October 9, 2020 04:04 — forked from EthanRutherford/readme.md
Regex but better

RegexButBetter

changes:

  • whitespace is no longer meaningful, and can therefore be used for formatting
    • this means whitespace must be escaped, using existing constructs like \n, \t, and a new escape for singleSpace \ (exact recipe open for discussion)
  • (capture) group constructs are totally rearranged, to allow for easier non-capturing grouping and reduction of "symbol soup" of current regex patterns
    • non-capturing group is assigned the bare ( so that the easiest-to-type grouping construct does not capture, and pollute the capture result array
      Motivation: using (?: just to be able to | a few options looks nasty
    • lookahead and lookbehind are modified to remove inconsistencies that exist for legacy, backward-compatibility reasons
  • (&gt;= = positive lookahead