Skip to content

Instantly share code, notes, and snippets.

View vsemozhetbyt's full-sized avatar

Vse Mozhe Buty vsemozhetbyt

View GitHub Profile
const primaryColumn = document.querySelector('div[data-testid="primaryColumn"]');
document.body.innerHTML = '';
document.body.append(primaryColumn);
// Per-tweet controls
for (const ele of document.querySelectorAll('div[role="group"]')) {
ele.remove();
}
// Reply widget

Cheat sheet: public prototype methods and accessors

const getterKey = Symbol('getterKey');
const setterKey = Symbol('setterKey');
const syncMethodKey = Symbol('syncMethodKey');
const syncGenMethodKey = Symbol('syncGenMethodKey');
const asyncMethodKey = Symbol('asyncMethodKey');
const asyncGenMethodKey = Symbol('asyncGenMethodKey');
@rishabhrpg
rishabhrpg / puppeteer_on_termux.md
Last active December 31, 2023 09:12
Run puppeteer inside termux

Run Puppeteer inside termux

Assumptions

  • You have termux installed and have sufficient permissions
  • You have loggedin as root user
  • You are okay with running Puppeteer inside a container (Alpine)

Gotchas

  • There is no build of Google Chrome available for ARM at this moment, so using chromium instead.
  • Installing chromium on Termux directly requires snap which is another big hurdle so alternively using alpine distro here.
function verboseRegExp(input) {
if (input.raw.length !== 1) {
throw Error('verboseRegExp: interpolation is not supported');
}
let source = input.raw[0];
let regexp = /(?<!\\)\s|[/][/].*|[/][*][\s\S]*[*][/]/g;
let result = source.replace(regexp, '');
@ericelliott
ericelliott / parallel-fetch.js
Created April 13, 2020 02:10
Parallel requests example
// setup
const wait = value => new Promise(resolve => {
setTimeout(() => resolve(value), 3000);
});
const fetchFoo = () => wait('foo');
const fetchBar = () => wait('bar');
const fetchBaz = () => wait('baz');
const fetchDataSlowly = async time => {

Summary: .global (/g) and .sticky (/y)

/g /y /yg
.exec() at .lI or later at .lI same as /y
.test() at .lI or later at .lI same as /y
.replace() ignores & resets .lI at .lI /g w/o gaps
.replaceAll() ignores .lI TypeError /g w/o gaps
.search() no effect no effect no effect
.match() Array of group 0 captures like .exec() /g w/o gaps
@brunnerh
brunnerh / xpath.js
Created May 3, 2019 18:11
Iterable document.evaluate wrapper.
/**
* Executes an XPath expression returning an iterable node list.
* @param {string} expression XPath expression.
* @param {Node} node Optional context node for query. Default is document element.
* @param {XPathNSResolver | ((prefix: string) => string | null) | null} nsResolver Optional namespace resolver function.
* @returns {Iterator<Node>} Result nodes iterator.
*/
function* xpath(expression, node = document.documentElement, nsResolver = null)
{
const xPathResult = document.evaluate(
const assert = require('assert');
//========== Helper functions
/**
* Resolves after `ms` milliseconds
*/
function delay(ms) {
return new Promise((resolve, _reject) => {
setTimeout(resolve, ms);
// From callbacks to Promises to async functions
function callbackFunc(x, callback) {
f1(x, (err1, result1) => {
if (err1) {
console.error(err1);
callback(err1);
return;
}
f2(result1, (err2, result2) => {
// Add flag 'g' if it isn’t there, yet
// Solution 1
let cloneFlags = regExp.flags;
if (!cloneFlags.includes('g')) {
cloneFlags += 'g';
}
// Solution 2
const cloneFlags = regExp.flags.includes('g')