Skip to content

Instantly share code, notes, and snippets.

@garcon
garcon / Bookmarklets.md
Last active October 24, 2025 07:46
My personal collection of useful bookmarklets.

Bookmarklets

Text editing

Following bookmarklets work with editable selected text.

  • Jednoznakovky – replace space following single-character words in Czech by non-breaking space.
  • Pomlčky – replace spaces around en-dash by non-breaking narrow space at left and thin space at right side.
  • Spojovník – replace hyphen/minus by soft hyphen and non-breaking hyphen to show hyphen in the wrapped words with hyphen at the beginning of new line.
@garcon
garcon / single-character-words-bookmarklet.js
Created October 24, 2025 07:35
Replace the space following Czech single-character words and some English prepositions and articles with non-breaking space.
javascript:!function(){let e=window.getSelection();if(!e.rangeCount)return;let t=e.getRangeAt(0),n=e.toString();if(!n.trim())return;let a=n.replace(/\b([ksvzouai]|do|na|po|od|ke|ve|za|ze|of|in|at|to|as|the|an)\s(?=\S)/gi,%22$1\xa0%22),o=document.activeElement,r=o&&o.tagName.toLowerCase();if((%22textarea%22===r||%22input%22===r&&%22text%22===o.type)&&%22number%22==typeof%20o.selectionStart){let%20l=o.selectionStart,i=o.selectionEnd;o.setRangeText(a,l,i,%22select%22)}else{let%20s=document.createTextNode(a);t.deleteContents(),t.insertNode(s),e.removeAllRanges();let%20g=document.createRange();g.setStartBefore(s),g.setEndAfter(s),e.addRange(g)}}();
@garcon
garcon / endash-bookmarklet.js
Created October 24, 2025 07:31
Replace spaces surrounding en-dash on both sides with non-breaking narrow space at left and thin space at right side.
javascript:!function(){function e(e){return e.replace(/\u0020\u2013\u0020/g,"%E2%80%AF%E2%80%93%E2%80%89")}let t=document.activeElement;if(!t){alert("%C5%BD\xe1dn\xfd aktivn\xed prvek!");return}let n=t.tagName.toLowerCase(),l=t.getAttribute("type");if("textarea"!==n&&("input"!==n||l&&"text"!==l)){if(t.isContentEditable){let r=window.getSelection();if(!r.rangeCount){alert("Nejprve ozna%C4%8D text k \xfaprav%C4%9B.");return}let a=r.getRangeAt(0),i=a.toString();if(!i){alert("Nejprve ozna%C4%8D text k \xfaprav%C4%9B.");return}let o=e(i);a.deleteContents(),a.insertNode(document.createTextNode(o)),r.removeAllRanges()}else alert("Aktivn\xed prvek nen\xed textov\xe9 pole ani contenteditable.")}else{let u=t.selectionStart,v=t.selectionEnd;if(u===v){alert("Nejprve ozna%C4%8D text k \xfaprav%C4%9B.");return}let c=t.value.slice(0,u),s=t.value.slice(u,v),$=t.value.slice(v),p=e(s);t.value=c+p+$,t.setSelectionRange(u,u+p.length)}}();
@garcon
garcon / hyphen-bookmarklet.js
Created October 24, 2025 07:27
Replace hyphen/minus (-) in text with sequence of soft hyphen and non-breaking hyphen to let hyphenated words repeat the hyphen at the beginning of a new line when wrapped..
javascript:!function(){let e=window.getSelection();if(!e.rangeCount)return;let t=e.getRangeAt(0),n=e.toString();if(!n)return;let r=e=>/^[\p{L}\p{N}]$/u.test(e),l=n.replace(/-/g,(e,t)=>{let l=function e(t,n){let l=0;for(let a=n-1;a>=0;a--){let o=t[a];if(/\s/.test(o)||"-"===o)break;r(o)&&l++}return l}(n,t),a=function e(t,n){let l=0;for(let a=n+1;a<t.length;a++){let o=t[a];if(/\s/.test(o)||"-"===o)break;r(o)&&l++}return l}(n,t);return l>1&&a>1?%22\u00ad\u2011%22:%22\u2011%22}),a=document.activeElement,o=a&&a.tagName&&a.tagName.toLowerCase();if(%22textarea%22===o||%22input%22===o&&%22number%22==typeof%20a.selectionStart){let%20s=a.selectionStart,i=a.selectionEnd;a.setRangeText(l,s,i,%22select%22)}else{let%20f=document.createTextNode(l);t.deleteContents(),t.insertNode(f),e.removeAllRanges();let%20g=document.createRange();g.setStartBefore(f),g.setEndAfter(f),e.addRange(g)}}();
@garcon
garcon / In-browserTextEditor.txt
Last active August 28, 2025 09:09
Paste the code into the browser’s address bar, then save it as a bookmark. You’ll get a Notepad-like text editor. Keep in mind, your text gets lost when you close the window!
data:text/html;charset=utf-8,%3Ctitle%3ETextEditor%3C/title%3E%3Cstyle%3Ebody%7Bbackground:%23fbfbfb;color:%23333;margin:0%20auto;width:50rem%7Dtextarea%7Bbackground:%23fbfbfb;border:0;color:%23333;font-family:sans-serif;font-size:2rem;height:98%25;line-height:1.4;margin:0%20auto;outline:0;padding:4rem;width:100%25%7Dbutton%7Bbackground-color:%23fbfbfb;border:1px%20%23ccc%20solid;color:%23999;cursor:pointer;float:right;margin:10px%200;padding:5px%2010px%7D@media%20(max-width:768px)%7Bbody%7Bwidth:100%25;padding:0%7Dtextarea%7Bpadding:10px%7Dbutton%7Bfloat:none%7D%7D%3C/style%3E%3Cbody%3E%3Cbutton%20onclick=%22sM();%20return%20false%22%3EEmail%20this%3C/button%3E%3Ctextarea%20contenteditable%20id=TE%20spellcheck=false%20placeholder=Write...%20autofocus%3E%3C/textarea%3E%3Cscript%3Efunction%20sM()%7Bvar%20a=%22mailto:?subject=%22+escape(%22Text%20from%20TextEditor%22)+%22&body=%22+escape(document.getElementById(%22TE%22).value);window.location.href=a%7D;%3C/script%3E
@garcon
garcon / bin.json
Last active May 23, 2025 11:36
Wishlist
{
"wishlist": [
{
"title": "Let na Měsíc",
"url": "https://www.spacex.com/",
"image": "https://picsum.photos/300/200?random=1",
"price": "500000000000 Kč",
"reserved_by": null
},
{
@garcon
garcon / seo-slug.php
Last active April 13, 2022 10:48
Change any string into SEO friendly URL slug
<?php
// example code
setlocale(LC_CTYPE, 'cs_CZ');
$str = "Běloučký kůň úpěl ďábelské ódy $ ' 1234";
print
preg_replace('/(?<=-)-+/', '', // Replace all duplicase hyphens with one only
preg_replace( '/[^-a-z0-9]/', '', // Strip all non-alfanumeric characters or hyphens
@garcon
garcon / fullScreen.js
Created April 23, 2021 15:53
Run browser in full screen mode
// JavaScript
document.getElementsByTagName("html")[0].webkitRequestFullScreen();
// document.getElementsByTagName("html")[0].requestFullscreen();
// document.getElementsByTagName("html")[0].msRequestFullscreen();
# OCR PDF file
ocrmypdf -l ces input.pdf output.pdf
# -l => language: -l eng+deu, -l ces
# --sidecar => Generate text files that contain the same text recognized by OCR
# --title TITLE => Set document title (place multiple words in quotes)
# --author AUTHOR => Set document author
# --subject SUBJECT => Set document subject description
# --keywords KEYWORDS => Set document keywords
@garcon
garcon / audio-video-manipulation.md
Last active February 18, 2022 08:04
This is a collection of command line one-liners for manipulating with audio and video files