Easy Analysis Extension

Easy Analysis Extension(http://analyzeit.azurewebsites.net/)

目前為 2016-08-05 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Easy Analysis Extension
// @version      2.9
// @description  Easy Analysis Extension(http://analyzeit.azurewebsites.net/)
// @icon         https://www.microsoft.com/favicon.ico?v2
// @license      GPL version 3
// @encoding     utf-8
// @date         12/08/2015
// @modified     8/5/2016
// @author       Myfreedom614 <[email protected]>
// @supportURL   http://openszone.com/
// @match        https://social.msdn.microsoft.com/Forums/*
// @match        https://social.technet.microsoft.com/Forums/*
// @match        stackoverflow.com/questions/*
// @match        serverfault.com/questions/*
// @match        superuser.com/questions/*
// @match        community.powerbi.com/t5/*/*-p/*
// @match        powerusers.microsoft.com/t5/PowerApps-Forum/*/*-p/*
// @match        powerusers.microsoft.com/t5/Flow-Forum/*/*-p/*
// @exclude      https://social.msdn.microsoft.com/Forums/*/home*
// @exclude      https://social.technet.microsoft.com/Forums/*/home*
// @grant        none
// @copyright	 2015-2016, Jeffrey Chen, Franklin Chen
// @namespace https://greasyfork.org/users/4544
// ==/UserScript==
(function (window) {
    'use strict';
    if (typeof window.addin !== 'undefined') {
        return;
    }

    var rootElement = document.getElementById('eas-iframe');

    if (rootElement !== null)
    {
        return;
    }

    var _globalSession = {
        url: location.href,
        host: location.host,
        platform: null,
        context: {},
        options: {}
    };

    var rules = {
        'mt': {
            'exp': new RegExp('social..*.microsoft.com/Forums/.*/({{0,1}([0-9a-fA-F]){8}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){4}-([0-9a-fA-F]){12}}{0,1})'),
            'instanceIdIndex': 1,
            'render': function () {
                var sidebar = document.getElementById('sidebar');

                var firstChild = sidebar.getElementsByTagName('section')[0];

                var section = document.createElement('section');

                section.innerHTML = '<section id="eas-iframe"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="auto-expand-checkbox" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label></div><div><a id="eas-collapse-button" title="Load EA iframe" href="#" style="color: #fff;background-color: #1e75bb;line-height: normal;padding: .3em 1em .48em 1em;display: block;">+ Easy Analysis</a></div><div id="eas-iframe-placeholder"></div></section>';

                sidebar.insertBefore(section, firstChild);
            }
        },
        'powerbi': {
            'exp': new RegExp('community.powerbi.com/t5/.*/*-p/([0-9]+)'),
            'instanceIdIndex': 1,
            'render': function () {
                var sidebar = document.getElementsByClassName("lia-quilt-column-main-left")[0].getElementsByClassName("lia-component-author")[0].parentNode;

                var firstChild = sidebar.getElementsByTagName('div')[0];

                var section = document.createElement('div');

                section.innerHTML = '<div class="module" id="eas-iframe"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="auto-expand-checkbox" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label><a id="eas-collapse-button" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">+ Easy Analysis</a></div><div id="eas-iframe-placeholder"></div></div>';

                sidebar.insertBefore(section, firstChild);
            }
        },
        'powerapps': {
            'exp': new RegExp('powerusers.microsoft.com/t5/(PowerApps-Forum|Flow-Forum)/.*/*-p/([0-9]+)'),
            'instanceIdIndex': 2,
            'render': function () {
                var sidebar = document.getElementsByClassName("lia-quilt-column-main-left")[0].getElementsByClassName("lia-component-author")[0].parentNode;

                var firstChild = sidebar.getElementsByTagName('div')[0];

                var section = document.createElement('div');

                section.innerHTML = '<div class="module" id="eas-iframe"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="auto-expand-checkbox" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label><a id="eas-collapse-button" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">+ Easy Analysis</a></div><div id="eas-iframe-placeholder"></div></div>';

                sidebar.insertBefore(section, firstChild);
            }
        },
        'sotool': {
            'exp': new RegExp('(stackoverflow.com|serverfault.com|superuser.com)/questions/([0-9]*)/'),
            'instanceIdIndex': 2,
            'render': function () {
                var sidebar = document.getElementById('sidebar');

                var firstChild = sidebar.getElementsByTagName('div')[0];

                var section = document.createElement('div');

                section.innerHTML = '<div class="module" id="eas-iframe"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="auto-expand-checkbox" style="vertical-align: middle;position: relative;bottom: -2px;">&nbsp;Auto Expand?</label><a id="eas-collapse-button" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">+ Easy Analysis</a></div><div id="eas-iframe-placeholder"></div></div>';

                sidebar.insertBefore(section, firstChild);
            }
        }
    };

    for(var name in rules)
    {
        if (rules[name].exp.test(_globalSession.url))
        {
            _globalSession.platform = name;

            console.log('platform: ' + name);
        }
    }

    if(_globalSession.platform === null)
    {
        console.log("not supported platform");

        return;
    }

    // set instance id
    var array = rules[_globalSession.platform].exp.exec(_globalSession.url);

    _globalSession.context.instanceId = array[rules[_globalSession.platform].instanceIdIndex];
    
    console.log('instanceId: ' + _globalSession.context.instanceId);

    // load options from local storage
    var auto = localStorage.getItem(_globalSession.platform + ".auto");

    _globalSession.options.auto = (auto !== undefined && auto === 'true');

    // render the html and bind events
    rules[_globalSession.platform].render();

    var collapseButton = document.getElementById('eas-collapse-button');

    var autoExpandCheckbox = document.getElementById('auto-expand-checkbox');

    var placeholder = document.getElementById('eas-iframe-placeholder');

    autoExpandCheckbox.checked = _globalSession.options.auto;

    autoExpandCheckbox.addEventListener('change', function () {
        localStorage.setItem(_globalSession.platform + ".auto", autoExpandCheckbox.checked);
    });

    collapseButton.addEventListener("click", function () {
        updatePanel();
    }, false);

    function updatePanel() {
        var icon = collapseButton.textContent[0];

        if (icon === '+') {

            var iframeUrl = 'https://analyzeit.azurewebsites.net/Redirection/Navigate/' + _globalSession.context.instanceId + '?external=' + _globalSession.platform + '&type=iframe';

            var iframeHtml = '<iframe src="' + iframeUrl + '" style="width:100%;height:500px;"></iframe>';

            placeholder.innerHTML = iframeHtml;

            collapseButton.textContent = "- Easy Analysis";
        }
        else if (icon === '-') {

            while (placeholder.firstChild) {
                placeholder.removeChild(placeholder.firstChild);
            }

            collapseButton.textContent = "+ Easy Analysis";
        }
    }

    if (_globalSession.options.auto)
    {
        updatePanel();
    }

    window.addin = this;
})(window);