Skip to content

Instantly share code, notes, and snippets.

@litvinovvo
litvinovvo / contenteditable.ts
Last active July 29, 2024 18:55
contenteditable div with textarea like behaviour for plain text, correct process new lines on enter
function onKeypress(event: KeyboardEvent) {
const isEnter = ['Enter', '\n'].includes(event.key)
if (isEnter && !event.shiftKey) {
// document.execCommand('insertLineBreak') // short and more solid alternative, despide of deprecation
const selection = window.getSelection()
if (selection) {
const range = selection.getRangeAt(0)
@litvinovvo
litvinovvo / .zshrc
Created March 22, 2021 11:09
macos zsh git highlight
function parse_git_branch() {
git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
setopt PROMPT_SUBST
export PROMPT='%F{grey}%n%f %F{cyan}%~%f %F{green}$(parse_git_branch)%f %F{normal}$%f '
@litvinovvo
litvinovvo / vk_add_audio_to_the_playlist.js
Created August 23, 2020 12:46
add vk audio to the given playlist
// scroll down fully
var songs = document.querySelectorAll('.audio_row');
var playlistId = '15359214_51903820';
for (var i = songs.length - 1; i >= 0; i--) {
console.log(i, 'more');
const mouseoverEvent = new Event('mouseover');
songs[i].dispatchEvent(mouseoverEvent);
await new Promise((a)=>setTimeout(a, 500));
songs[i].querySelector('.audio_row__action_more').click();
@litvinovvo
litvinovvo / getboundingClientRect.js
Created March 5, 2020 16:27
Long task free getboundingClientRect
function getBoundingClientRect(element) {
return new Promise(resolve => {
const observer = new IntersectionObserver(([entity]) => {
observer.unobserve(element);
observer.disconnect();
resolve(entity.boundingClientRect);
});
observer.observe(element);
});