Move logic of palette buttons from html to js