JSFiddle - React, Tailwind, and code Playground

by dshilkret

JavaScript

var file = "dog.xlsx";
var url = "https://dtecho365.sharepoint.com/:w:/r/sites/ServiceNowDev1/_layouts/15/Doc.aspx?sourcedoc=%7Bebd48061-26f0-4dd7-9892-de62a89c11dd%7D";
var protocol = openInMS(file, url);
console.log(protocol);

function openInMS(file,url){
var protocol;
var ext = file.substring(file.lastIndexOf(".") + 1);
//if "pdf" and "Open in native App." set to true. Next do string replace "https:" with "docint".
if(ext == "pdf"){
	protocol = "docint";
  return protocol;
}
//start MS Office block. prepend uri with result of "protocol"
switch (ext) {
        case "doc":
            protocol = "ms-word";
            break;
        case "docx":
            protocol = "ms-word";
            break;
        case "vsdx":
            protocol = "ms-visio";
            break;
        case "xlsx":
            protocol = "ms-excel";
            break;
        case "xls":
            protocol = "ms-excel";
            break;
        case "pptx":
            protocol = "ms-powerpoint";
            break;
        case "ppt":
            protocol = "ms-powerpoint";
            break;
        case "accdb":
            protocol = "Excel XLSX";
            break;
        case "pub":
            protocol = "ms-publisher";
            break;
        case "one":
            protocol = "ms-one";
            break;
        default:
            protocol = "default";
}
return protocol + ":" + url;
}