forked from trevormkay/splatoon-widgets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplatoon - Large.scriptable
12 lines (11 loc) · 6.71 KB
/
Splatoon - Large.scriptable
1
2
3
4
5
6
7
8
9
10
11
12
{
"always_run_in_app" : false,
"icon" : {
"color" : "pink",
"glyph" : "brush"
},
"name" : "Splatoon - Large",
"script" : "\/\/ Thank you for downloading this script. To get started with it make sure\n\/\/ you are running Scriptable 1.5.1, after that add the Scriptable widget\n\/\/ to your Home Screen and select this script in the editing panel. You will\n\/\/ need to put in \"regular\", \"ranked\", or \"league\" in the parameter field to\n\/\/ select which mode you want to display.\n\n\/\/ Feel free to make changes to this script as you need it. Please don't\n\/\/ redistribute without permission. Instead submit a change request to the\n\/\/ Github project (https:\/\/github.com\/trevormkay\/splatoon-widgets) so everyone\n\/\/ can benefit.\n\n\/\/ All data comes from https:\/\/splatoon2.ink\/ and Splatoon content Copyright\n\/\/ 2015 Nintendo. No copyright or trademark infringement is intended in using\n\/\/ Splatoon content.\n\n\nlet json = await loadJson()\nlet widget = await createWidget(json)\n\n\/\/ Check if the script is running in a widget. If not, show a preview of the widget to easier debug it\nif (!config.runsInWidget) {\n await widget.presentLarge()\n}\n\n\/\/ Tell the system to show the widget\nScript.setWidget(widget)\nScript.complete()\n\n\/\/ Generate widget\nasync function createWidget(json) {\n \/\/ Grab the parameter when setting the widget on the Home Screen\n var parameter = args.widgetParameter;\n \n \/\/ Makes the parameter for ranked mode easier to explain\n if (parameter == \"ranked\") {parameter = \"gachi\"}\n \n \/\/ Handles running the widget inside Scriptable for debugging\n if (parameter == null) {parameter = \"gachi\"}\n \n \/\/ Mode Colors \n var modeColor = \"#000000\"\n if (parameter == \"regular\") {modeColor = \"#19D719\"}\n if (parameter == \"gachi\") {modeColor = \"#F54910\"}\n if (parameter == \"league\") {modeColor = \"#F02D7D\"}\n \n \/\/ Current mode data\n const { gachi, regular, league } = json\n let mode1 = json[parameter][0]\n const stageA = mode1.stage_a\n const stageB = mode1.stage_b\n const modeA = mode1.rule\n let imgStageA = stageA.image\n let imgStageB = stageB.image\n \n \/\/ Next mode data \n let mode2 = json[parameter][1]\n const modeB = mode2.rule\n \n let mode3 = json[parameter][2]\n const modeC = mode3.rule\n \n let mode4 = json[parameter][3]\n const modeD = mode4.rule\n \n \/\/ Time display\n let unix_timestamp = mode2.start_time\n var date = new Date(unix_timestamp * 1000)\n var hours = date.getHours();\n if (hours == 0) {hours = \"12 AM\"}\n if (hours <= 11) {hours = hours + \" AM\"}\n if (hours == 12) {hours = hours + \" PM\"}\n if (hours >= 13) {hours = hours - 12 + \" PM\"}\n \n let unix_timestamp2 = mode3.start_time\n var date2 = new Date(unix_timestamp2 * 1000)\n var hours2 = date2.getHours();\n if (hours2 == 0) {hours2 = \"12 AM\"}\n if (hours2 <= 11) {hours2 = hours2 + \" AM\"}\n if (hours2 == 12) {hours2 = hours2 + \" PM\"}\n if (hours2 >= 13) {hours2 = hours2 - 12 + \" PM\"}\n \n let unix_timestamp3 = mode4.start_time\n var date3 = new Date(unix_timestamp3 * 1000)\n var hours3 = date3.getHours();\n if (hours3 == 0) {hours3 = \"12 AM\"}\n if (hours3 <= 11) {hours3 = hours3 + \" AM\"}\n if (hours3 == 12) {hours3 = hours3 + \" PM\"}\n if (hours3 >= 13) {hours3 = hours3 - 12 + \" PM\"}\n \n \/\/ Create widget frame\n let w = new ListWidget()\n w.setPadding(10, 10, 10, 10)\n w.backgroundColor = new Color(modeColor)\n \n w.addSpacer()\n \n \/\/ Mode logo\n let imgReqMode = new Request('https:\/\/cdn.toast-studio.com\/splatoon\/' + parameter + '.png')\n let imgMode = await imgReqMode.loadImage()\n let logo = w.addImage(imgMode)\n logo.imageSize = new Size(50, 50)\n logo.centerAlignImage()\n \n \/\/ Current mode text\n let modeTxt = w.addText(modeA.name)\n modeTxt.font = Font.boldRoundedSystemFont(30)\n modeTxt.textColor = Color.white()\n modeTxt.centerAlignText()\n \n w.addSpacer(0)\n \n \/\/ Current mode stages text\n let currentStageTxt = w.addText(stageA.name + \" and \" + stageB.name)\n currentStageTxt.font = Font.regularRoundedSystemFont(12)\n currentStageTxt.textColor = Color.white()\n currentStageTxt.centerAlignText()\n currentStageTxt.minimumScaleFactor = 0.1\n \n w.addSpacer(10)\n \n \/\/ Create stack for stage images\n let stages = w.addStack()\n stages.spacing = 10\n\n \/\/ Display Stage 1 image\n let urlStageA = new Request('https:\/\/splatoon2.ink\/assets\/splatnet' + imgStageA)\n let retrvImgStageA = await urlStageA.loadImage()\n let displayImgStageA = stages.addImage(retrvImgStageA)\n displayImgStageA.cornerRadius = 10\n \n \/\/ Display Stage 2 image\n let urlStageB = new Request('https:\/\/splatoon2.ink\/assets\/splatnet' + imgStageB)\n let retrvImgStageB = await urlStageB.loadImage()\n let displayImgStageB = stages.addImage(retrvImgStageB)\n displayImgStageB.cornerRadius = 10\n \n w.addSpacer(10)\n \n \/\/ Create stack for information text\n let infoText = w.addStack()\n infoText.layoutVertically()\n infoText.spacing = 5\n \n let header = infoText.addText(\"Up Next\")\n header.font = Font.boldRoundedSystemFont(16)\n header.textColor = Color.white()\n \n \/\/ Next mode text\n if (parameter == \"regular\") {\n let mode2Txt = infoText.addText(hours + \": \" + mode2.stage_a.name + \" and \" + mode2.stage_b.name)\n mode2Txt.font = Font.regularRoundedSystemFont(16)\n mode2Txt.textColor = Color.white()\n } else {\n let mode2Txt = infoText.addText(hours + \": \" + modeB.name)\n mode2Txt.font = Font.regularRoundedSystemFont(16)\n mode2Txt.textColor = Color.white()\n }\n \n if (parameter == \"regular\") {\n let mode3Txt = infoText.addText(hours2 + \": \" + mode3.stage_a.name + \" and \" + mode3.stage_b.name)\n mode3Txt.font = Font.regularRoundedSystemFont(16)\n mode3Txt.textColor = Color.white()\n } else {\n let mode3Txt = infoText.addText(hours2 + \": \" + modeC.name)\n mode3Txt.font = Font.regularRoundedSystemFont(16)\n mode3Txt.textColor = Color.white()\n }\n \n if (parameter == \"regular\") {\n let mode4Txt = infoText.addText(hours3 + \": \" + mode4.stage_a.name + \" and \" + mode4.stage_b.name)\n mode4Txt.font = Font.regularRoundedSystemFont(16)\n mode4Txt.textColor = Color.white()\n } else {\n let mode4Txt = infoText.addText(hours3 + \": \" + modeD.name)\n mode4Txt.font = Font.regularRoundedSystemFont(16)\n mode4Txt.textColor = Color.white()\n }\n \n w.addSpacer()\n \n return w\n}\n\n\/\/Load the Splatoon 2 Schedule JSON\nasync function loadJson() {\n let url = \"https:\/\/splatoon2.ink\/data\/schedules.json\"\n let req = new Request(url)\n let textres = await req.loadString()\n let json = JSON.parse(textres)\n return json\n}\n\n\n",
"share_sheet_inputs" : [
]
}