const getterKey = Symbol('getterKey');
const setterKey = Symbol('setterKey');
const syncMethodKey = Symbol('syncMethodKey');
const syncGenMethodKey = Symbol('syncGenMethodKey');
const asyncMethodKey = Symbol('asyncMethodKey');
const asyncGenMethodKey = Symbol('asyncGenMethodKey');
This file contains 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 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 |
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.
This file contains 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 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, ''); |
This file contains 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
// 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 => { |
/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 |
This file contains 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
/** | |
* 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( |
This file contains 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 assert = require('assert'); | |
//========== Helper functions | |
/** | |
* Resolves after `ms` milliseconds | |
*/ | |
function delay(ms) { | |
return new Promise((resolve, _reject) => { | |
setTimeout(resolve, ms); |
This file contains 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
// 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) => { |
This file contains 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
// 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') |
NewerOlder