Skip to content

Instantly share code, notes, and snippets.

View davecra's full-sized avatar
💭
Coding for arrays

David E. Craig davecra

💭
Coding for arrays
View GitHub Profile
@davecra
davecra / index.html
Created October 22, 2023 19:55
index.html for Trello Power-Up
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta http-equiv="Cache-control" content="no-cache"/>
<meta http-equiv="pragma" content="no-cache"/>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<!-- if you want Trello sizeTo to work correctly, you need to keep this -->
<link crossorigin="anonymous" rel="stylesheet" href="https://p.trellocdn.com/power-up.min.css">
<title>Power-Up</title>
@davecra
davecra / commands.js
Created September 13, 2023 13:33
JSRuntime to get it working
/**
* Checks to see if we are running in Windows Outlook
* @returns {Boolean}
*/
function isPC() {
try {
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform === null) {
return true;
} else {
return false;
@davecra
davecra / onready.js
Created September 13, 2023 13:30
Office OnReady in JSRuntime
/**
* Ensures the Office.js library is loaded.
*/
Office.onReady((info) => {
/**
* Maps the event handler name specified in the manifest's LaunchEvent element to its JavaScript counterpart.
* This ensures support in Outlook on Windows.
*/
if (Office.context.platform === Office.PlatformType.PC || Office.context.platform == null) {
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
@davecra
davecra / sanitizeString.js
Created September 8, 2023 03:16
HTML Sanitizer
/**
* Sanitizes the string for possible malicious values
* @param {String} string
* @returns {String}
*/
static sanitizeString = (string) => {
try {
string = string.replace(/(javascript:|onerror)/gi, "");
string = string.replace(/undefined/gi, "");
string = string.replace(/<script/gi, "&lt;script");
@davecra
davecra / inline4.js
Created May 12, 2023 21:58
inline4.js
const myObj = new MyClassToCallTheServer();
let someValue = await myObj.doSomegthingWithTheServerData();
@davecra
davecra / inline3.js
Last active May 12, 2023 22:04
inline3.js
export default class MyClassToCallTheServer {
#internvalValue = null;
#loading = false;
constrcutor() {
this.#internalValue = this.#callTheServer();
}
doSomethingWithTheServerData = async () => {
while(this.#loading) await new Promise(resolve => setTimeout(resolve, 10));
// the #internalValue is not null because we waited
return this.#internalValue;
@davecra
davecra / inline2.js
Last active May 12, 2023 22:05
inline2.js
export default class MyClassToCallTheServer {
#internvalValue = null;
constrcutor() {
// this.#internalValue = await this.#callTheServer(); <-- the await will fail to compile
this.#internalValue = this.#callTheServer();
}
doSomethingWithTheServerData = () => {
// the #internalValue is still null becasue we could not await in the constructor
return this.#internalValue;
}
@davecra
davecra / inline1.js
Last active May 12, 2023 21:55
inline1.js
const myObj = new MyClassToCallTheServer();
let someValue = myObj.doSomegthingWithTheServerData();
@davecra
davecra / detectMimeType.js
Created December 31, 2022 02:53
A JavaScript function to detect the Media/Mime Type for a base64 string
/**
* Returns the data type based on the base64 string
* @param {String} base64String
* @param {String} fileName
* @returns {String}
*/
detectMimeType(base64String, fileName) {
var ext = fileName.substring(fileName.lastIndexOf(".") + 1);
if (ext === undefined || ext === null || ext === "") ext = "bin";
ext = ext.toLowerCase();
@davecra
davecra / getUsername.js
Created July 27, 2020 14:51
Gets the username for the current user using the SSO API
export async function getUserName() {
try {
let tokenData = await OfficeRuntime.auth.getAccessToken({ allowSignInPrompt: false, forMSGraphAccess: true });
var parts = tokenData.split(".");
var token = JSON.parse(atob(parts[1]));
return token.preferred_username;
}
catch (exception) {
console.log(exception.message);
}