A basic outline on seive configuration in Imagus—based on previous posts by developer, with additions based on own usage.
Before it's sent to matching, every URL has its protocol and subdomain removed using the following regex:
/** | |
* 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 |
// 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>>; |
/** | |
* 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}); |
'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); |
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(); | |
} |
(() => { | |
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) |
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(); |
/** | |
* NOTE: Use browser console | |
* | |
* @playground <https://tsplay.dev/KwXl8w> | |
*/ | |
//#region Declarations | |
export type NaturalNumber = Number & Partial<{__brand?: null}> |
changes:
\n
, \t
, and a new escape for singleSpace \
(exact recipe open for discussion)(
so that the easiest-to-type grouping construct does not capture, and pollute the capture result array(?:
just to be able to |
a few options looks nasty(>=
= positive lookahead