justyns / trilium-scripts

scripts and utilities for Trilium

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Color Picker Command (Code, NOT bug)

sottey opened this issue · comments

NOTE: Chrome only. IE, Edge and Safari do not yet support the HTML5 input type "color".

Name: Color Picker

Attributes:

  • #cmdPalette="Sort Current Note (asc)"
  • #cmdPaletteDesc="Sort the current note's lines ascending"

Code:

async function onInput(event) {
    await navigator.clipboard.writeText(picker.value.toUpperCase());
    picker.removeEventListener("input", onInput);
    picker.getParent().remove(picker);
    event.preventDefault();
}

var picker = document.createElement('input');
picker.addEventListener("input", onInput);
picker.type="color";
picker.value="#936FC8";
picker.id = 'color-picker';

document.body.appendChild(picker);
picker.click();

Notes:

  • Selecting a color and pressing enter results in the selected color being put in the clipboard
  • Pressing escape does not change the clipboard
  • On usage, everything is created on the fly. On exit, it tears everything down to not leave remnants.