Skip to content

Instantly share code, notes, and snippets.

View AshKyd's full-sized avatar
🐳
a frood who really knows where his towel is

Ash Kyd AshKyd

🐳
a frood who really knows where his towel is
View GitHub Profile
@AshKyd
AshKyd / typeahead.svelte
Created March 10, 2025 07:35
Svelte native-ish typeahead
<script lang="ts">
import { untrack } from 'svelte';
let { values = [], value = [], disabled, onChange = () => {} } = $props();
const uniqueId = 'list' + (Math.random() * 10e15).toString(16);
let selectedValues = $state<string[]>(value);
let isFocused = $state(false);
let inputElement = $state<HTMLInputElement>();
let inputValue = $state('');
@AshKyd
AshKyd / abcnews-tidy.js
Last active February 23, 2025 01:10
Tampermonkey scripts to remove US politics from ABC News and Brisbane Times
// ==UserScript==
// @name Tidy up news homepage
// @namespace http://tampermonkey.net/
// @version 2025-02-03
// @description try to take over the world!
// @author You
// @match https://www.abc.net.au/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=abc.net.au
// @grant none
// ==/UserScript==
@AshKyd
AshKyd / gist:750c81d436badedb809fdb1f2c4eb3fc
Created July 15, 2024 04:43
Update NPM dependencies to latest
npx npm-check-updates -u
function cancellable() {
let isRunning = true;
const p = new Promise((resolve, reject) => {
setTimeout(() => {
if (!isRunning) return reject();
resolve();
}, 1000)
});
@AshKyd
AshKyd / methodSpy.js
Created May 29, 2024 01:38
Spy on video element methods and log when & where they're called from
['pause', 'play'].forEach(method => {
const oldMethod = video[method];
video[method] = function () {
console.log(`${method} (dom call)`, { video, e: new Error('here') });
return oldMethod.apply(video);
};
});
@AshKyd
AshKyd / photos.js
Last active March 11, 2025 08:19
Delete photos, videos, and reviews from the Google Maps desktop site. Huge disclaimer: these will probably get out of date at some point and may not work. You should read and understand the code before you do anything with it.
// delete photos from Google Maps
(async () => {
const sleep = (time) => new Promise(resolve => setTimeout(resolve,time));
const go = async () => {
// click the kebab
document.querySelector('button[jsaction*="pane.photo.actionMenu"]:not([aria-hidden="true"])').click();
await sleep(200);
// click the delete menu item
document.querySelector('#action-menu div[role="menuitemradio"]').click();
@AshKyd
AshKyd / readme.md
Last active January 12, 2024 03:19
Failsafe way to programmatically play a video, falling back to muted

https://developer.chrome.com/blog/autoplay

  1. Safari will not autoplay any videos when in low power mode.
    1. Requires a user interaction, after which the remainder of autoplay videos in the page work fine.
    2. Interaction means some form of click interaction. Doesn't even matter on what.
    3. Attempting to trigger an unumuted video with the element.play() api only works after interaction. Attempting this without an interaction will throw immediately, it does NOT return a rejected promise.
    4. It's not straightforward to detect the low power behaviour happening because Safari runs through all the standard video events as if the video is playing correclty. But the very last event will be "paused" which we can use to show a button to start the interactive.
  2. Chrome will always play muted autoplay videos.
  3. Attempting to play an unmuted video in Chrome with element.play() will return a rejected promise.
function dataTransferItemToArrayBuffer(dataTransferItem){
return new Promise((resolve, reject) => {
if(dataTransferItem.kind !== 'file') {return reject(new Error('DataTransferItem is not of kind "file"'));}
const file = dataTransferItem.getAsFile();
var reader = new FileReader();
reader.onload = function() {
var arrayBuffer = this.result,
array = new Uint8Array(arrayBuffer);
@AshKyd
AshKyd / index.html
Created December 17, 2023 06:36
iOS Chat bubbles
<p class="send">Hey there! What's up</p>
<p class="receive">Checking out iOS7 you know..</p>
<p class="send">Check out this bubble!</p>
<p class="receive">It's pretty cool…</p>
<p class="receive">Not gonna lie!</p>
<p class="send">Yeah it's pure CSS &amp; HTML</p>
<p class="receive">Wow that's impressive. But what's even more impressive is that this bubble is really high.</p>
@AshKyd
AshKyd / makeTsv.js
Created November 29, 2023 00:32
Make a tsv file out of a geojson blob. The properties must all be consistent or this won't really work.
const geojson = require('file.geojson');
function makeLine(object){
return Object.keys(object).map(key => {
const value = object[key];
if(!['string', 'number'].includes(typeof value)) return '-';
return value;
}).join('\t')
}