Skip to content

Instantly share code, notes, and snippets.

View canalun's full-sized avatar

canalun canalun

View GitHub Profile
@canalun
canalun / listChangeableBuiltinNames.js
Created June 14, 2024 08:35
list all changeable built-in names
const changeableBuiltInNames = [];
getChangeableBuiltInNamesRecursively(globalThis, "globalThis");
function getChangeableBuiltInNamesRecursively(obj, accessors) {
if (
obj === undefined ||
obj === null ||
obj instanceof String ||
obj.__proto__ === String.prototype ||
(accessors !== "globalThis" && obj === globalThis)
@canalun
canalun / recordCallsForBuiltinFunctions.js
Last active June 28, 2024 11:36
Record all the calls and their serializable args for built-in functions.
window["record"] = [];
// The recording starts when you set it as true.
// Otherwise, the process in this file would be also recorded.
window["isRecorded"] = false;
const changeableBuiltInNames = getChangeableBuiltInNames();
for (const name of changeableBuiltInNames) {
let target = window;
@canalun
canalun / sortNodesByTreeOrder.js
Last active May 12, 2024 14:29
sort nodes in shadow-and-iframe-including tree order (js)
/**
* It returns NEW array sorted by shadow(-and-iframe)-including tree order.
* `shadow-including tree order`: https://dom.spec.whatwg.org/#concept-shadow-including-tree-order
* (If you want the typed version, plz check out the TS version.)
*/
function sortNodesByTreeOrder(nodes) {
return nodes.slice().sort((a, b) => {
if (!a.isConnected && !b.isConnected) {
return 0
}
@canalun
canalun / sortNodesByTreeOrder.ts
Last active May 12, 2024 14:30
sort nodes in shadow-and-iframe-including tree order
type DocumentOrElement = Document | Element
/**
* It returns NEW array sorted by shadow(-and-iframe)-including tree order.
* `shadow-including tree order`: https://dom.spec.whatwg.org/#concept-shadow-including-tree-order
*/
function sortNodesByTreeOrder<T extends DocumentOrElement | Element>(
nodes: T[]
): T[] {
return nodes.slice().sort((a, b) => {
@canalun
canalun / oscillateText.js
Last active October 20, 2024 07:14
text oscillator
const cname = "movearound-text-domdom-enjoy"
addClassToTextsAndImagesRecursively(document.body)
const targets = Array.from(document.getElementsByClassName(cname))
setInterval(() => oscillateElements(targets), 100)
function addClassToTextsAndImagesRecursively(root) {
if (root.tagName === "HEAD" || root.tagName === "SCRIPT" || root.tagName === "STYLE") return
const extendedChildNode = (node) => node.firstChild || node.shadowRoot || node.contentDocument
@canalun
canalun / overwriteTextNodes.js
Last active April 30, 2024 13:19
replace texts on web page
;(function overwriteTextNodes(root, yourText) {
const extendedChildNode = (node) =>
node.firstChild || node.shadowRoot || node.contentDocument
for (let node = extendedChildNode(root); node; node = node.nextSibling) {
node.nodeType === 3 && (node.nodeValue = yourText)
overwriteTextNodes(node, yourText)
}
})(document.body, "👶")
@canalun
canalun / DOM3D.js
Created March 27, 2024 13:54 — forked from OrionReed/dom3d.js
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
// after runnig this code on the console, click click click as fast as possible.
let a = null
let results = []
window.addEventListener('click', (e) => {
if (a === null){
a = performance.now()
return
}
const b = performance.now()
const sleep = (ms) => {
const now = performance.now()
while (performance.now() - now < ms) {
// wait
}
}
(function setSleepRepeatedly() {
Promise.resolve().then(() => {
sleep(3000)
@canalun
canalun / main.dart
Last active March 20, 2024 12:27
a11y in flutter canvas
// The implementation is based on https://developers.cyberagent.co.jp/blog/archives/36573/
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
void main() {
WidgetsFlutterBinding.ensureInitialized();
// Auto-enable accessibility for our Blind and Low Vision customers.
// RendererBinding.instance.accessibilityFeatures