Skip to content

Instantly share code, notes, and snippets.

@Akjosch
Akjosch / tools.js
Last active February 28, 2023 09:14
Simple DiceRoller buttons via `<<dice spec>>` inside an ObsidianMD note. Requires Dice Roller and CustomJS plugins to work. Extendable for more `<<tag>>` types.
class Tools {
static Macros = {
dice(code) {
code = String(code);
var b = createEl("button");
b.replaceChildren(code);
b.addEventListener("click", () => {
app.commands.executeCommandById("obsidian-dice-roller:open-view");
app.plugins.getPlugin("obsidian-dice-roller")?.view.roll(code)
});
@Akjosch
Akjosch / ext.array.min.js
Last active October 25, 2021 11:39
Array extension methods for SugarCube, quick & dirty version
"use strict";Object.defineProperty(Array.prototype,"countWith",{configurable:!0,writable:!0,value:function value(predicate,thisArg){if(null==this)throw new TypeError("Array.prototype.countWith called on null or undefined");if("function"!=typeof predicate)throw new Error("Array.prototype.countWith predicate parameter must be a function");var length=this.length>>>0;if(0==length)return[];for(var count=0,i=0;i<length;++i)count+=!!predicate.call(thisArg,this[i],i,this);return count}});
@Akjosch
Akjosch / animg_macro.js
Created October 9, 2020 11:33
Image-with-replacement for SugarCube
/**
* Usage:
* <<animg source.jpg class imageclass class anotherclass id image42 replacement.jpg>>
*/
Macro.add("animg", {
handler() {
if(this.args.length === 0) {
return this.error("No image source given.");
}
var src = this.args[0]
@Akjosch
Akjosch / exampleusage.tw
Last active October 7, 2020 15:31
Fun with reading Google Sheets in SugarCube
:: Show Responses [nobr]
/* assume setup.responseSheet is set to the ID of the sheet with the responses to some form */
<<run setup.getSheetData(setup.responseSheet, function(data) {
State.variables.responses = data;
setPageElement("responses", "Responses");
})>>
<div id="responses"></div>
:: Responses [nobr]
@Akjosch
Akjosch / hover-macro.js
Created September 23, 2020 07:13
Tippy 6.2.6 for Twine/SugarCube
/**
* <<hover>> macro - add an <abbr> element with the passage or text and optional theme
*
* Usage examples:
* <<hover passage "Passage Name">>Text<</hoverabbr>>
* <<hover passage "Passage Name" "theme">>Text<</hoverabbr>>
* <<hover text "Some text comes here" "optional_theme">>Text<</hoverabbr>>
*
* If "passage" and "text" aren't present, the macro tries to interpret
@Akjosch
Akjosch / dialog.css
Last active July 30, 2020 17:40
Simple dialog system
.chat {
position: absolute;
left: 0;
right: 0;
bottom: 0;
visibility: hidden;
}
.chat.chat-open {
visibility: visible;
}
@Akjosch
Akjosch / quest.babel.js
Last active July 11, 2020 20:29
Simple-as-hell quest system for SugarCube
"use strict";
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
/* quest holder */
var quests = new Map();
@Akjosch
Akjosch / handlers.js
Last active August 24, 2020 07:32
SugarCube macros for delayed execution handlers/triggers
/* SugarCube code block to be executed later */
Macro.add('handler', {
tags: null,
isAsync: true,
validIdRe: /^[A-Za-z_]\w*$/,
handler() {
if(this.args.length === 0) {
return this.error('Missing handler ID(s).');
}
const ids = Array.from(this.args);
/* SugarCube code block to be executed later */
Macro.add('handler', {
tags: null,
isAsync: true,
validIdRe: /^[A-Za-z_]\w*$/,
handler() {
if(this.args.length === 0) {
return this.error('Missing handler ID(s).');
}
const ids = Array.from(this.args);
@Akjosch
Akjosch / backup_event.tw
Last active May 21, 2020 11:02
Random event engine for SugarCube/TweeGo
:: Backup Event [event]
/*
PRIORITY: Number.MIN_SAFE_INTEGER
*/
<div class="error-view"><span class="error">No valid events found. Write some?</span></div>