This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Stackoverflow dates | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Stackoverflow dates outdate marker | |
// @author You | |
// @include /^https:\/\/(.+\.)?stackoverflow\.com/ | |
// @icon https://www.google.com/s2/favicons?domain=stackoverflow.com | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function inside(point, vs) { | |
// ray-casting algorithm based on | |
// https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html/pnpoly.html | |
// https://stackoverflow.com/questions/22521982/check-if-point-is-inside-a-polygon/29915728#29915728 | |
// https://github.com/substack/point-in-polygon | |
var x = point[0], y = point[1]; | |
var inside = false; | |
for (var i = 0, j = vs.length - 1; i < vs.length; j = i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getSelector(el){ | |
let nodes = [],c,e,d=el.ownerDocument,h=d.documentElement; | |
do{if (el.id){ nodes.push(`#${el.id}`); break; | |
}else{ if (el==h) c=0; else for (c=1,e=el;e=e.previousElementSibling;c++); | |
nodes.push(c?`:nth-child(${c})`:el.tagName.toLowerCase()); | |
} } while ((el=el.parentNode)&&el!=d); return nodes.reverse().join` > `; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calendar for month `m` of the year `y` with Sunday as first day of week | |
const calS = (y,m) => { | |
let[r,d,w,l]=[[],1,0,!(y%4)-!(y%1e2)+!(y%4e2)], | |
c=((0|23*m/9)+(m<3?y--:y-2)+5+(0|y/4)-(0|y/1e2)+(0|y/4e2))%7; | |
for(;d<29+(0x3bbeecc+16*l>>m*2&3);++d,c=++c%7,w+=!c) | |
(r[w]||(r[w]=[,,,,,,,]))[c]=d; | |
return r | |
} | |
// Calendar for month `m` of the year `y` with Monday as first day of week |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Queue = () => { | |
let idle = true; | |
const stack = [], | |
fx = (...job) => { | |
stack.push(...job); | |
if(idle) | |
(async () => { | |
idle = false; | |
while(stack.length) | |
await stack.shift()(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function floodFill(image, sr, sc, newColor) { | |
const current = image[sr][sc]; | |
if (current != newColor) { | |
fill(image, sr, sc, newColor, current); | |
} | |
return image; | |
function fill(image, sr, sc, newColor, current) { | |
if ( | |
sr < 0 || |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function derelativePathD(d,fixed){ | |
let steps = d | |
.replace(/[,\s]+/g,' ') | |
.replace(/-\./g,'-0.') | |
.replace(/(?<=\.\d+)\./g,' 0.') | |
.split(/([MmLlAaCcSsQqTtVvHhZz])/g) | |
.splice(1) | |
.map((v,i) => !(i%2) ? v : v | |
.split(/\s+/g) | |
.map(v=>v.split(/(-?[\d]*(?:\.\d+)?(?:e-?\d{1,2})?)/g) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function beautify( | |
/* HTML-string */ html, | |
/* new line chars */ nl = '\n', | |
/* indent chars */ tab = '\t', | |
/* disabled format tags */ disabled = /^(code|pre|em|strong|span|b|i|u|sup|sub|a)$/ig, | |
/* without closed tags */ single = /^(area|base|br|col|command|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/gi | |
){ | |
return escape( | |
stringify( | |
new DOMParser() /* parse HTML */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Router is a function that returns async function. | |
const Router = (...chain) => | |
Object.assign( | |
// That async function as object have one method push() | |
async (ctx) => { | |
// When it calls that function it runs recursive algorithm | |
return await (async function run(idx) { | |
// Which calls each function in the chain | |
let res = await ("AsyncFunction" !== chain[idx].constructor.name | |
? new Promise((res) => chain[idx](ctx, res)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const stepTimeout = 505; | |
const Router = (...chain) => | |
Object.assign( | |
async (ctx) => { | |
await (async function run(idx) { | |
if ("function" == typeof chain[idx]) { | |
await new Promise((res, rej) => { | |
const to = setTimeout( | |
() => rej(new Error(`Step [${idx}] timeout on \n${chain[idx]}`)), |