Skip to content

Instantly share code, notes, and snippets.

@bilelz
bilelz / 🗺Go to Maps.md
Last active March 5, 2024 15:21
Script pour ouvrir Google Maps avec la recherche en cours

Un script à glisser dans la barre de favoris pour ouvrir Google Maps avec la recherche en cours

javascript:window.open(`https://www.google.com/maps?q=${new URL(document.location).searchParams.get("q") || ""}`); event && event.stopPropagation();

Exemple avec NYC :

image

@bilelz
bilelz / revealDataTestId()
Last active March 2, 2023 10:05
Reveal items with data-testid attribute and copy list to clipboard
javascript: function revealDataTestId(){ const testStyle = document.createElement("style"); testStyle.innerText = '[data-testid]{outline: rgb(255, 87, 34) dashed 5px;}'; document.head.appendChild(testStyle); var list = [...new Set([...document.querySelectorAll('[data-testid]')].map((item) => item.getAttribute('data-testid')))].join('\r\n'); document.body.focus(); navigator.clipboard.writeText(list); setTimeout(()=>{ alert(list ? 'Copied to clipboard:\r\n'+list : 'No [data-testid] element found')},100);} revealDataTestId();
@bilelz
bilelz / clearCookies.js
Last active January 17, 2023 14:50
Clear all cookies in all paths and all variants of the domain (www.mydomain.example, mydomain.example, etc...)
function clearCookies() {
/* Clear all cookies in all paths and all variants of the domain (www.mydomain.example, mydomain.example, etc...) */
const cookies = document.cookie.split("; ");
for (let cookie of cookies) {
const domains = window.location.hostname.split(".");
while (domains.length > 0) {
// prettier-ignore
const cookieName = encodeURIComponent(cookie.split(";")[0].split("=")[0]);
const cookieBase = `${cookieName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=${domains.join(".")} ;path=`; // prettier-ignore
@bilelz
bilelz / getChecksumSha256.ts
Last active December 1, 2022 13:21
generate Checksum (Sha256) from a blob or a file (vanillajs)
async function getChecksumSha256(blob: Blob): Promise<string> {
const uint8Array = new Uint8Array(await blob.arrayBuffer());
const hashBuffer = await crypto.subtle.digest('SHA-256', uint8Array);
const hashArray = Array.from(new Uint8Array(hashBuffer));
return hashArray.map((h) => h.toString(16).padStart(2, '0')).join('');
// if you like, it, yan can buy me a coffee https://paypal.me/bilelz/1000000
}
@bilelz
bilelz / modal-feature-detection.js
Last active April 26, 2022 12:56
HTML's < dialog > element - feature detection
if (!!document.createElement("dialog").showModal) {
console.log('Native support: OK 😀')
}else{
console.log('Native support: KO 😭')
}
@bilelz
bilelz / pkce-generator_vanilla.js
Last active September 21, 2021 04:30
PKCE Code Verifier and Code Challenge Generator without externals libs (vanilla js). Demo : https://codepen.io/bilelz/full/YzNozBe
function generateCodeVerifier() {
return Array(128)
.fill('0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-._~')
.map(x => x[Math.floor(crypto.getRandomValues(new Uint32Array(1))[0] / (0xffffffff + 1) * x.length)])
.join('');
}
async function generateCodeChallenge(code_verifier) {
const encoder = new TextEncoder();
const data = encoder.encode(code_verifier);
@bilelz
bilelz / version.ts
Last active November 10, 2022 09:47
Generate app version file from package.json and git | for angular or other frameworks
/*
From https://gist.github.com/bilelz/04707e300811d2b7fe3815ede073422c
inspired by https://medium.com/@amcdnl/version-stamping-your-app-with-the-angular-cli-d563284bb94d
*/
const fs = require('fs');
const exec = require('child_process').execSync;
/* Get package.json version. */
const packageVersion = JSON.parse(
fs.readFileSync('package.json', 'UTF-8')