Last active
May 7, 2024 02:28
-
-
Save PtruckStar/e80b8d89197775ff2fff6fd3b452aaab to your computer and use it in GitHub Desktop.
sticky notes widget with scriptable
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: deep-green; icon-glyph: sticky-note; | |
/* | |
################################# | |
####simple sticky note widget#### | |
################################# | |
please read below for usage!! | |
you must configure font size and | |
background-color first before | |
typing your notes and separating | |
it by "." from your note | |
CONFIG: | |
---background color--- | |
green, red, yellow, blue, dynamic, #hex | |
---text size--- | |
small, medium, large | |
---pointed note--- | |
if you want to add more than one poin | |
use ", " to sparate each poin | |
SEPARATE YOUR NOTE AND CONFIG BY "." | |
USAGE: (config).(note) | |
e.g : medium green. note1, note2, ... | |
or just note: note1, note2, ... | |
made by @morinagapltynm | |
################################# */ | |
let placeholder = "Please type your note on the widget parameter" | |
let input = (args.widgetParameter == null) ? placeholder : args.widgetParameter | |
let define = input.split(/\.\s(.*)|\.(.*)/) | |
let conf = define[0] | |
let noteColor = Color.black() | |
// fontSize | |
if (conf.match(/small/i)){ | |
fontSize = 16 | |
}else if (conf.match(/medium/i)){ | |
fontSize = 32 | |
}else if (conf.match(/large/i)){ | |
fontSize = 45 | |
}else{ | |
//default | |
fontSize = 16 | |
} | |
// bgColor default is random | |
color = { | |
"green": "C5EA9C", | |
"yellow": "FFFFA1", | |
"blue": "B1DAE4", | |
"red": "FFC2E4", | |
"white": "F6F6F7", | |
"black": "191919" | |
} | |
if (conf.match(/green/i)){ | |
bgColor = new Color(color.green) | |
}else if (conf.match(/yellow/i)){ | |
bgColor = new Color(color.yellow) | |
}else if (conf.match(/blue/i)){ | |
bgColor = new Color(color.blue) | |
}else if (conf.match(/red/i)){ | |
bgColor = new Color(color.red) | |
}else if (conf.match(/#/)){ | |
//custom color | |
let prefix = conf.indexOf("#") | |
let ctmClr = conf.slice(prefix + 1, prefix + 7) | |
bgColor = new Color(ctmClr) | |
}else if (conf.match(/dynamic/i)){ | |
bgColor = Color.dynamic(new Color(color.white), new Color(color.black)) | |
noteColor = Color.dynamic(new Color(color.black), new Color(color.white)) | |
}else{ | |
//random as default | |
let hex = Object.values(color) | |
bgColor = new Color(hex[Math.floor(Math.random() * 4)]) | |
} | |
// note | |
if (define.length == 1){ | |
note = define[0].replace(/, |,/g, "\n• ") | |
}else{ | |
note = define[1].replace(/, |,/g, "\n• ") | |
} | |
// draw widget | |
let w = new ListWidget() | |
w.refreshAfterDate = new Date(Date.now()+1000*60*60*24*30*12) | |
let text = (note.match("\n") === null) ? w.addText(note) : w.addText("• " + note) | |
text.font = Font.mediumMonospacedSystemFont(fontSize) | |
text.textColor = noteColor | |
w.backgroundColor = bgColor | |
// run widget | |
if(!config.runsInWidget){ | |
w.presentMedium() | |
} | |
Script.setWidget(w) | |
Script.complete() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
simple sticky note widget
Type the configuration and note in widget parameter
config:
sparate config and note by: "."
text note:
usage:
e.g :
or just note: *w/random background color