// ==UserScript== // @name SD++ Extension // @version 0.1 // @description SD++ Extension for Microsoft Service Desk // @icon https://www.microsoft.com/favicon.ico?v2 // @license GPL version 3 // @encoding utf-8 // @date 10/14/2019 // @modified 10/14/2019 // @author Franklin Chen // @supportURL http://franklin614.com/ // @include http*://servicedesk.microsoft.com/* // @grant none // @copyright 2019, Franklin Chen // @namespace https://greasyfork.org/en/scripts/xxxxxx // @downloadURL none // ==/UserScript== (function (window) { 'use strict'; if (typeof window.addin !== 'undefined') { return; } var rootElement = document.getElementById('eas-iframe'); if (rootElement !== null) { return; } var platforms = [], url = location.href, options = {}; function getByValue(arr, value) { for (var i = 0, iLen = arr.length; i < iLen; i++) { if (arr[i].getAttribute("rel") == value) return arr[i]; } } platforms.push({ 'name': 'sd', 'id': 12, 'exp': new RegExp('servicedesk.microsoft.com/#/customer/commercial.*caseNumber=([0-9]*)'), 'instanceIdIndex': 1, 'render': function () { var checkExist = setInterval(function() { if (document.getElementsByClassName('case-basic-info').length) { clearInterval(checkExist); var fireOnHashChangesToo = true; var pageURLCheckTimer = setInterval ( function () { if (this.lastPathStr !== location.pathname || this.lastQueryStr !== location.search || (fireOnHashChangesToo && this.lastHashStr !== location.hash) ) { this.lastPathStr = location.pathname; this.lastQueryStr = location.search; this.lastHashStr = location.hash; gmMain(); } } , 111 ); function removeElementsParentById(id) { var elem = document.getElementById(id).parentNode; return elem.parentNode.removeChild(elem); } function gmMain() { if(document.getElementById('eas-iframe') !== null){ removeElementsParentById('eas-iframe'); } var topBar = document.getElementsByClassName('case-basic-info')[0]; var topRightArea = topBar.getElementsByClassName('section-2')[0]; var items = topRightArea.getElementsByClassName('item'); var firstChild = items[items.length-2]; var section = document.createElement('div'); section.className = 'item ng-scope'; section.innerHTML = '
'; topRightArea.insertBefore(section, firstChild); var collapseButton = document.getElementById('eas-collapse-button'); var array = platform.exp.exec(location.href); collapseButton.addEventListener("click", function () { var iframeUrl = 'https://cas-ext-app.azurewebsites.net/#/boot/' + platform.id + '/' + array[platform.instanceIdIndex] + '/'; console.log(iframeUrl); //window.open(iframeUrl, '_blank', 'location=no,height=450,width=800,left=300,top=100,scrollbars=yes'); window.open(iframeUrl, '_blank', 'location=no,height=570,width=600,scrollbars=yes,status=yes'); }, false); } } }, 500); } }); function getCurrentPlatform() { for (var name in platforms) { if(platforms[name].exp !== undefined){ if (platforms[name].exp.test(url)) { return platforms[name]; } } } return null; } var platform = getCurrentPlatform(); if (platform === null) { console.log("not supported platform"); return; } var array = platform.exp.exec(url); var indentity = array[platform.instanceIdIndex]; console.log('indentity = ' + indentity); // load options from local storage var auto = localStorage.getItem(platform.name + ".auto"); options.auto = (auto !== undefined && auto === 'true'); function afterRender(){ var collapseButton = document.getElementById('eas-collapse-button'); var autoExpandCheckbox = document.getElementById('auto-expand-checkbox'); var placeholder = document.getElementById('eas-iframe-placeholder'); autoExpandCheckbox.checked = options.auto; autoExpandCheckbox.addEventListener('change', function () { localStorage.setItem(platform.name + ".auto", autoExpandCheckbox.checked); }); collapseButton.addEventListener("click", function () { updatePanel(); }, false); function updatePanel() { var icon = collapseButton.textContent[0]; if (icon === '+') { var iframeUrl = 'https://cas-ext-app.azurewebsites.net/#/boot/' + platform.id + '/' + indentity + '/'; var iframeHtml = ''; placeholder.innerHTML = iframeHtml; collapseButton.textContent = "- Community Analysis"; } else if (icon === '-') { while (placeholder.firstChild) { placeholder.removeChild(placeholder.firstChild); } collapseButton.textContent = "+ Community Analysis"; } } if (options.auto) { updatePanel(); } } // render the html and bind events platform.render(); afterRender(); window.addin = this; })(window);