Skip to content

Instantly share code, notes, and snippets.

@Aymkdn
Aymkdn / method1a.js
Last active October 27, 2016 08:02
Examples to retrieve a manager in Sharepoint 2013
// Retrieve Manager for a username
// using REST API
var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
var accountName = 'domain\\login';
// I suppose you use jQuery
$.ajax({
url: siteUrl + "/_api/SP.UserProfiles.PeopleManager/GetPropertiesFor(accountName=@v)?@v='" + encodeURIComponent(accountName) + "'",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
@Aymkdn
Aymkdn / loadExt.js
Last active December 31, 2022 04:32
To load JS and CSS files with vanilla JavaScript
// long version
function loadExt(files, after) {
var _this=this;
_this.files = files;
_this.js = [];
_this.head = document.getElementsByTagName("head")[0];
_this.after = after || function(){};
_this.loadStyle = function(file) {
var link = document.createElement("link");
link.rel = "stylesheet";
@Aymkdn
Aymkdn / Date.parseFrom.js
Created January 30, 2017 11:02
Date.parseFrom() permits to parse a string to a JavaScript Date
/**
* Parse a string to a Date
* @param {String} strDate
* @param {String} format Supported format including YYYY, YY, MM, M, DD, D, with - and / separators
* @return {Date|Throw} the JS Date object, or throw Error("Invalid Date") if strDate is invalid
* @compatibility IE9+
* @example
* Date.parseFrom("1/10/2017", "MM/DD/YYYY"); // -> new Date(2017,0,10)
*/
Date.parseFrom=function(strDate, format) {
@Aymkdn
Aymkdn / CompareLibrairies.js
Created May 18, 2017 08:11
Use node to compare two Sharepoint librairies and copy the source to the destination. It will create the folders and files, but it will also update the Modified date and Modifier author in the destination to match the source
// Command: node index.js "http://my.site.com/my_root/my_source_libary/" "http://my.othersite.com/my_root/my_destination_libary/"
if (process.argv.length !== 4) throw "ERROR: please provide the source and the destination on the command line";
const colors = require('colors');
// load credentials
const credentials = require('../credentials');
const $SP = require('sharepointplus');
const sp = $SP().auth(credentials);
var requestdigest = '';
// contains the references to the items to update in the dest lib
@Aymkdn
Aymkdn / jsonpost.xml
Last active January 2, 2019 17:17
Post JSON using YQL Open Table
<?xml version="1.0" encoding="UTF-8"?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Johannes Charman</author>
<description>JSON pages that need post data (this table is based on htmlpost by Christian Heilmann)</description>
<sampleQuery>select * from {table} where url='http://search.twitter.com/search.json' and postdata="q=test"</sampleQuery>
<documentationURL></documentationURL>
</meta>
<bindings>
<select itemPath="" produces="XML">
<?xml version="1.0" encoding="UTF-8" ?>
<table xmlns="http://query.yahooapis.com/v1/schema/table.xsd">
<meta>
<author>Todd Vierling</author>
<description>HTML selector that returns a flat, escaped string rather than a node tree. Suitable for use with Pipes and other applications wishing to embed HTML in another XML-like container.</description>
<sampleQuery>select * from {table} where url='http://www.yahoo.com/' and xpath='//a'</sampleQuery>
</meta>
<bindings>
<select itemPath="" produces="XML">
<urls>
@Aymkdn
Aymkdn / notifier.js
Last active November 14, 2017 15:52
Have Google Home to speak
// npm install castv2-client google-tts-api
var Client = require('castv2-client').Client;
var client = new Client();
var DefaultMediaReceiver = require('castv2-client').DefaultMediaReceiver;
var GoogleTTS = require('google-tts-api');
var host = "192.168.0.13"; // IP Address of the Google Home
var text = "Bonjour et bienvenue"; // Text to speach
var lang = "fr-FR"; // language
GoogleTTS(text, lang, 1)
.then(function(url) {
@Aymkdn
Aymkdn / linkify
Created June 5, 2018 10:08
Parse URL in a string and convert in a link
var urlRegex =/(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
function linkify(text, safeText) {
safeText = (safeText===false? false : true);
if (safeText) text=escapeHtml(text);
return text.replace(urlRegex, function(url) {
return '<a href="' + url + '">' + url + '</a>';
});
}
@Aymkdn
Aymkdn / fedauth.js
Last active May 5, 2021 13:36
Node JS way to get the FedAuth cookie for a Sharepoint 2019 OnPrem with AzureAD authentication – See https://github.com/Aymkdn/SharepointPlus/wiki/Using-the-FedAuth-Cookie/
const extend=require('extend');
const { sso } = require('node-expose-sspi');
const fetch = require('node-fetch');
var debugMode = false;
var globalCredentials = {};
/**
* Returns an object of cookies
* @param {Array} cookies An array of "cookieName=cookieValue;whatever…"
@Aymkdn
Aymkdn / RichText.vue
Created March 3, 2021 10:12
TipTap TextColor extension
// this is a simplified example using Vuetify v1 and TipTap v1
<template>
<div>
<editor-menu-bar :editor="editor" v-else>
<div class="menubar" slot-scope="{ commands, isActive }">
<v-tooltip top>
<button :class="{ 'menubar__button':true, 'is-active': isActive.bold() }" @click="commands.bold" slot="activator">
<v-icon>format_bold</v-icon>
</button>
<span>Bold</span>