Skip to content

Instantly share code, notes, and snippets.

const waitForLoad = fn => {
if(document.readyState === 'loading'){
document.addEventListener('DOMContentLoaded', fn)
} else {
fn()
}
}
@piouc
piouc / cqw.js
Last active December 20, 2024 08:45
LP
(() => {
let points = []
const handleClick = (event) => {
const section = event.target.closest('section')
if (!section) return
const rect = section.getBoundingClientRect()
const sectionWidth = rect.width
const x = (event.clientX - rect.left) / sectionWidth * 100
find . -type f \( -iname "*.jpg" -o -iname "*.png" \) -exec sh -c 'cwebp -q 75 "$0" -o "${0%.*}.webp"' {} \;
@piouc
piouc / replace-all-rem.js
Last active January 7, 2025 04:14
replace-all-rem.js
const { writeFile } = require('fs')
const fsp = require('fs/promises')
const { parse } = require('path')
;(async () => {
const files = await fsp.readdir('./', {recursive: true})
for(const file of files){
if(['.js', '.json', '.css', '.liquid', '.html'].includes(parse(file).ext)){
const data = await fsp.readFile(file, 'utf8')
const replaced = data.replace(/(\d+(\.\d+)?|\.?\d+|0)rem/g, match => {
@piouc
piouc / convert-all-png-to-webp.sh
Created August 28, 2023 02:17
convert-all-png-to-webp.sh
find . -type f -name '*.png' -print0 | xargs -0 -n 1 bash -c 'cwebp "$0" -o "${0%.png}.webp"'
@piouc
piouc / getPosision.js
Created August 24, 2023 06:31
getPosision.js
let point = null
window.addEventListener('mousedown', e => {
if(point){
console.log(`x="${point.x / window.innerWidth * 100}vw" y="${point.y / window.innerWidth * 100}vw" width="${(e.clientX + window.scrollX - point.x) / window.innerWidth * 100}vw" height="${(e.clientY + window.scrollY - point.y) / window.innerWidth * 100}vw"`)
point = null
} else {
point = {
x: e.clientX + window.scrollX,
y: e.clientY + window.scrollY
}
@piouc
piouc / remove-outlook-ads.user.js
Last active October 4, 2022 05:44
remove-outlook-ads.user.js
// ==UserScript==
// @name Remove outlook ads
// @include https://outlook.live.com/mail/*
// @version 1.0.2
// @updateURL https://gist.githubusercontent.com/piouc/053352df3e29357240d767a51b0e2e6b/raw/remove-outlook-ads.user.js
// @downloadURL https://gist.githubusercontent.com/piouc/053352df3e29357240d767a51b0e2e6b/raw/remove-outlook-ads.user.js
// @grant none
// ==/UserScript==
const style = document.createElement('style')
@piouc
piouc / illust-ac-download-all-search-result.js
Last active February 18, 2022 07:36
illust-ac-download-all-search-result.js
(async (from) => {
const wait = (ms) => new Promise((resolve) => setTimeout(resolve, ms))
const modalLinks = Array.from(document.querySelectorAll('a.link-to-detail'))
const fromIndex = modalLinks.findIndex(a => a.dataset.id === from.toString()) ?? 0
for(const a of modalLinks.slice(fromIndex)){
const id = a.dataset.id
a.click()
let link
while(!link){
await wait(250)
@piouc
piouc / mirakuruntv.m3u8
Created January 11, 2022 11:05
mirakuruntv.m3u8
#EXTM3U
#EXTVLCOPT:network-caching=1000
#EXTINF:-1,地上波 - NHK総合
http://ubuntu.lan:40772/api/channels/GR/27/services/1024/stream/
#EXTINF:-1,地上波 - NHK Eテレ
http://ubuntu.lan:40772/api/channels/GR/26/services/1032/stream/
#EXTINF:-1,地上波 - 日本テレビ
http://ubuntu.lan:40772/api/channels/GR/25/services/1040/stream/
#EXTINF:-1,地上波 - テレビ朝日
// ==UserScript==
// @name Amazon URL normalizer
// @namespace https://piou.dev
// @include https://www.amazon.co.jp/*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
const regex = /^https:\/\/www.amazon.co.jp\/(?:.+\/)?(?:dp|gp\/product)\/([a-zA-Z0-9]+?)(?:[?\/].*|$)/