Skip to content

Commit 22021ac

Browse files
committed
feat: Added extremely useful new 'whack' function.
Press 'w' to whack your fediwall.
1 parent 5776b15 commit 22021ac

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/App.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { computed, inject, onBeforeUnmount, onMounted, onUpdated, provide, ref, watch } from 'vue';
3-
import { createFilterWrapper, debounceFilter, useDocumentVisibility, usePreferredDark, useWindowScroll, useWindowSize } from '@vueuse/core'
3+
import { createFilterWrapper, debounceFilter, onKeyStroke, useDocumentVisibility, usePreferredDark, useWindowScroll, useWindowSize } from '@vueuse/core'
44
55
import { type Config, type Post } from '@/types';
66
import { loadConfig } from '@/config';
@@ -10,7 +10,7 @@ import { fetchPosts } from '@/sources'
1010
import Card from './components/Card.vue';
1111
import ConfigModal from './components/ConfigModal.vue';
1212
import InfoBar from './components/InfoBar.vue';
13-
import { arrayUnique } from './utils';
13+
import { whack } from './utils';
1414
1515
const config = ref<Config>();
1616
@@ -82,7 +82,9 @@ watch(() => config.value?.title, () => document.title = config.value?.title || f
8282
// Watch for a update interval changes
8383
watch(() => config.value?.interval, () => restartUpdates())
8484
85-
85+
onKeyStroke(['w'], (e) => {
86+
whack("#wall *", 1)
87+
})
8688
8789
/**
8890
* Starts or restarts the update interval timer.

src/utils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function deepClone(obj: any) {
2727
return JSON.parse(JSON.stringify(obj))
2828
}
2929

30-
export async function sleep(ms:number) {
30+
export async function sleep(ms: number) {
3131
await new Promise(resolve => setTimeout(resolve, Math.max(0, ms)));
3232
}
3333

@@ -67,4 +67,14 @@ export function replaceInText(root: Node, pattern: RegExp, replace: (m: RegExpMa
6767

6868
walk(root)
6969
return root;
70+
}
71+
72+
export function whack(what:string, how_much: number) {
73+
const rand = (scale:number) => (Math.random() * 2 - 1) * scale * how_much;
74+
document
75+
.querySelectorAll(what)
76+
.forEach((node) => {
77+
if(node instanceof HTMLElement)
78+
node.style.transform = how_much > 0 ? `translate(${rand(4)}px, ${rand(4)}px) rotate(${rand(1)}deg)` : ""
79+
})
7080
}

0 commit comments

Comments
 (0)