ybbond

My site. The main domain
Log | Files | Refs | README | LICENSE | CC-LICENSE

commit 27d6022c717b5494cc2082e61d94ba58ed07d2e1
parent 9086c624225ed06c48ec8334bf46015b6afb2342
Author: Yohanes Bandung Bondowoso <hi@ybbond.dev>
Date:   Mon, 27 Jul 2020 11:05:01 +0700

update custom Boop script

Diffstat:
Mcontent/posts/June 2020 Links.md | 2+-
Astatic/hex2rgb.js | 44++++++++++++++++++++++++++++++++++++++++++++

2 files changed, 45 insertions(+), 1 deletion(-)

diff --git a/content/posts/June 2020 Links.md b/content/posts/June 2020 Links.md
@@ -25,7 +25,7 @@ Highlight that I like:
 ## Apps
 
 [Boop](https://apps.apple.com/us/app/boop/id1518425043) &nbsp;<small>macOS App</small>
-Great utility app to process many kind of text, it can pretty format HTML, XML and JSON, convert HEX color to rgb, and more trivial stuff. It is a great tool as I often open a web tool to do those things.
+Great utility app to process many kind of text, it can pretty format HTML, XML and JSON, convert HEX color to rgb, and more trivial stuff. It is a great tool as I often open a web tool to do those things. I [made a custom script](/hex2rgb.js) for Hex to RGB based on the placeholder script.
 
 [Org-roam](https://www.orgroam.com/)
 I think, this is the end of my quest to search the best note taking app (on desktop, at the very least). I've written about it [on this post](/posts/2020-06-org-mode-with-org-roam/).
diff --git a/static/hex2rgb.js b/static/hex2rgb.js
@@ -0,0 +1,44 @@
+/**
+     {
+         "api":1,
+         "name":"HEX2RGB",
+         "description":"Convert colors in hexadecimal to RGB.",
+         "author":"Yohanes Bandung Bondowoso",
+         "icon":"table",
+         "tags":"flip"
+     }
+ **/
+
+function main(input) {
+  const items = input.text.split("\n");
+  const convertedItems = items.map((item) => {
+    if (item) {
+      return makin(item);
+    } else {
+      return item;
+    }
+  });
+  input.text = String(convertedItems.join("\n"));
+}
+
+function makin(input) {
+  R = hexToR(input);
+  G = hexToG(input);
+  B = hexToB(input);
+
+  return `rgb(${R.toString()}, ${G.toString()}, ${B.toString()})`;
+}
+
+function hexToR(h) {
+  return parseInt(cutHex(h).substring(0, 2), 16);
+}
+function hexToG(h) {
+  return parseInt(cutHex(h).substring(2, 4), 16);
+}
+function hexToB(h) {
+  return parseInt(cutHex(h).substring(4, 6), 16);
+}
+function cutHex(h) {
+  return h.charAt(0) == "#" ? h.substring(1, 7) : h;
+}
+