Skip to content

Instantly share code, notes, and snippets.

View nuxodin's full-sized avatar

Tobias Buschor nuxodin

View GitHub Profile
@nuxodin
nuxodin / tryAgain.js
Created February 14, 2023 23:17
tryAgain function
function tryAgain(fn, times = 2){
try {
return fn(times);
} catch (e) {
if (times > 1) return tryAgain(fn, times-1);
throw e;
}
}
@nuxodin
nuxodin / keyboard word event.js
Last active July 1, 2022 20:02
track words using a delay to clean
// better a "WordObserver" that can better handle chanching targets?
let word = '';
let wordClearTimeout = null;
let wordTarget = null;
addEventListener('keyup', e=>{
const isChar = /^.$/u.test(e.key);
// if (wordTarget !== e.target) { // clear if target changes
function computedLang(el){
let root = el.closest('[lang]');
let lang = root ? root.getAttribute('lang') : navigator.language;
if (!el.matches(':lang('+lang+')')) {
console.warn('lang missmatch!');
for (let l of ['de','en','it','es', /*...*/ ]) if (el.matches(':lang('+l+')')) return l;
}
c1.c1Use('onElement',function(){ 'use strict';
// check supported
var x = document.createElement('input');
x.type = 'datetime-local';
if (x.type === 'datetime-local') return;
document.head.insertAdjacentHTML(
'afterbegin',
if (!('onscrollend' in document.documentElement)) {
document.addEventListener('scroll',function(e){
var scrollPort = e.target
clearTimeout(scrollPort._scrollEndTimeout);
scrollPort._scrollEndTimeout = setTimeout(function () {
const event = new Event('scrollend');
Object.defineProperty(event,'snapTarget',{
get(){
return 'todo';
document.addEventListener('load',function(e){
if (e.target.tagName !== 'LINK') return;
if (e.target.rel !== 'stylesheet') return;
console.log(e.target.sheet)
},true);
@nuxodin
nuxodin / style-once.js
Last active October 16, 2023 03:39
Polyfill "style once" hopefully standardised soon :)
const selector = 'link[rel="stylesheet"], style';
onElement(selector, function(el){ // NOT IMPLEMENTED IN THIS SCRIPT
// checks all styleSheets and importRules, todo store urls global and check all if used url found
// console.log(el.sheet)
checkAllSheets()
});
function checkAllSheets(){
const urls = {};
/* ussage
<div flex-gap=fallback-margin style="--x-gap:10px">
<span>a</span>
<span>b</span>
</div>
*/
var div = document.createElement('div');
div.innerHTML = '<i></i><i></i>';
div.style.display = 'inline-flex';
@nuxodin
nuxodin / href-everywere.js
Last active June 9, 2020 05:48
Enable each element to be linked
/* Copyright (c) 2016 Tobias Buschor https://goo.gl/gl0mbf | MIT License https://goo.gl/HgajeK */
/**
ussage:
<table>
<tr data-c1-href="https://example.com" data-c1-target="_blank">
<td> <a href="https://example.com" target="_blank">example.com</a>
<td> Do not forget to add a real link so that your content is accessible.
</table>
*/
c1 = {
@nuxodin
nuxodin / requestSubmit_and_reportValidity.js
Last active April 17, 2020 08:58 — forked from mcshaz/reportValidity.js
reportValidity polyfill for IE 10, 11
if (!HTMLFormElement.prototype.requestSubmit) {
HTMLFormElement.prototype.requestSubmit = function(submitter) {
let submitBtn = submitter;
if (!submitBtn) {
submitBtn = document.createElement('input');
submitBtn.type = 'submit';
submitBtn.hidden = true;
this.appendChild(submitBtn);
}
submitBtn.click();