Easy Analysis Extension

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

当前为 2016-03-21 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Easy Analysis Extension
// @version      2.4
// @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     3/21/2016
// @author       Myfreedom614 <[email protected]>
// @supportURL   http://openszone.com/
// @match        https://social.msdn.microsoft.com/Forums/*
// @match        https://social.technet.microsoft.com/Forums/*
// @match        http://stackoverflow.com/questions/*
// @match        https://stackoverflow.com/questions/*
// @match        community.powerbi.com/t5/*/m-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 () {
    'use strict';
    if (typeof window.addin !== 'undefined') {
        return;
    }
    function UserException(message) {
        this.message = message;
        this.name = "UserException";
    }
    function OpenLinkNewTab(link) {
        window.open(link, '_blank');
    }
    function CacheSafeReload(urlBase) {
        return urlBase + "&cache=" + (new Date()).getTime();
    }
    function AddListenerToAutoExpand(settingItem) {
        document.getElementById("autoExpand").addEventListener("click", function(){
            SaveAutoExpangeSetting(settingItem); }, false);
    }
    function LoadAutoExpangeSetting(settingItem) {
        var isAutoExpand = localStorage.getItem(settingItem);
        if(isAutoExpand !== undefined && isAutoExpand == "true") {
            var chkBox = document.getElementById('autoExpand');
            chkBox.checked = true;
        }
    }
    function SaveAutoExpangeSetting(settingItem) {
        var chkBox = document.getElementById('autoExpand');
        if (chkBox.checked) {
            //alert("checked");
            localStorage.setItem(settingItem, true);
        }
        else {
            //alert("unchecked");
            localStorage.setItem(settingItem, false);
        }
    }
    function AddEAMSDNButton(sidebar, firstChild, link) {
        var section = document.createElement('section');
        section.innerHTML = '<section id="eas-iframe"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="autoExpand" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label></div><div><a id="gotoeas" class="btn goToEALink" 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></section>';
        sidebar.insertBefore(section.firstChild, firstChild);
        document.getElementById("gotoeas").addEventListener("click", function(){
            InsertMSDNIframe(link);}, false);
        LoadAutoExpangeSetting("isMSDNAutoExpand");
        AddListenerToAutoExpand("isMSDNAutoExpand");
    }
    function AddEASOButton(sidebar, link) {
        firstChild = sidebar.getElementsByTagName('div')[0];
        var adddiv = document.createElement('div');
        adddiv.innerHTML = '<div class="module" id="eas-iframe"><label style="font-size: 80%;color: red;"><input type="checkbox" id="autoExpand" style="vertical-align: middle;position: relative;bottom: -2px;">&nbsp;Auto Expand?</label><a id="gotoeas" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">+ Easy Analysis</a></div>';
        sidebar.insertBefore(adddiv, firstChild);

        document.getElementById("gotoeas").addEventListener("click", function(){
            InsertSOIframe(link);}, false);
        LoadAutoExpangeSetting("isSOAutoExpand");
        AddListenerToAutoExpand("isSOAutoExpand");
    }
    function AddEAPBIButton(sidebar, link) {
        firstChild = sidebar.getElementsByTagName('div')[0];
        var adddiv = document.createElement('div');
        adddiv.innerHTML = '<div class="module" id="eas-iframe"><label style="font-size: 80%;color: red;"><input type="checkbox" id="autoExpand" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label><a id="gotoeas" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">+ Easy Analysis</a></div>';
        sidebar.insertBefore(adddiv, firstChild);

        document.getElementById("gotoeas").addEventListener("click", function(){
            InsertPBIIframe(link);}, false);
        LoadAutoExpangeSetting("isPBIAutoExpand");
        AddListenerToAutoExpand("isPBIAutoExpand");
    }
    function InsertMSDNIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        var section = document.createElement('section');
        section.innerHTML = '<div id="eas-iframe" style="height:500px;"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="autoExpand" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label></div><a id="collapseeas" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">- Easy Analysis</a><iframe src="' + link + '" style="width:100%;height:90%;"></iframe></div>';
        goToSection.parentNode.replaceChild(section, goToSection);
        document.getElementById("collapseeas").addEventListener("click", function(){
            CollapseMSDNIframe(link);}, false);
        LoadAutoExpangeSetting("isMSDNAutoExpand");
        AddListenerToAutoExpand("isMSDNAutoExpand");
    }
    function CollapseMSDNIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        goToSection.parentNode.removeChild(goToSection);
        var sidebar = document.getElementById('sidebar');
        var firstChild = sidebar.getElementsByTagName('section')[0];
        AddEAMSDNButton(sidebar, firstChild, link);
    }
    function InsertSOIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        var divs = document.createElement('div');
        divs.innerHTML = '<div class="module" id="eas-iframe" style="height:500px;"><label style="font-size: 80%;color: red;"><input type="checkbox" id="autoExpand" style="vertical-align: middle;position: relative;bottom: -2px;">&nbsp;Auto Expand?</label><a id="collapseeas" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">- Easy Analysis</a><iframe src="' + link + '" style="width:100%;height:90%;"></iframe></div>';
        var div= divs.firstChild;
        goToSection.parentNode.replaceChild(div, goToSection);
        document.getElementById("collapseeas").addEventListener("click", function(){
            CollapseSOIframe(link);}, false);
        LoadAutoExpangeSetting("isSOAutoExpand");
        AddListenerToAutoExpand("isSOAutoExpand");
    }
    function CollapseSOIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        goToSection.parentNode.removeChild(goToSection);
        var sidebar = document.getElementById('sidebar');
        AddEASOButton(sidebar, link);
    }
    function InsertPBIIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        var section = document.createElement('section');
        section.innerHTML = '<div id="eas-iframe" style="height:500px;"><div><label style="font-size: 80%;color: red;"><input type="checkbox" id="autoExpand" style="vertical-align: middle;position: relative;bottom: 1px;">&nbsp;Auto Expand?</label></div><a id="collapseeas" href="#" style="color: #FFFFFF;background: #1e75bb;padding: 4px 10px 5px;font-size: 14px;line-height: 1.3;display: block;">- Easy Analysis</a><iframe src="' + link + '" style="width:100%;height:90%;"></iframe></div>';
        goToSection.parentNode.replaceChild(section, goToSection);
        document.getElementById("collapseeas").addEventListener("click", function(){
            CollapsePBIIframe(link);}, false);
        LoadAutoExpangeSetting("isPBIAutoExpand");
        AddListenerToAutoExpand("isPBIAutoExpand");
    }
    function CollapsePBIIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        goToSection.parentNode.removeChild(goToSection);
        var referenceNode = document.getElementsByClassName("lia-quilt-column-main-left")[0].getElementsByClassName("lia-component-author")[0];
        AddEAPBIButton(referenceNode.parentNode, link);
    }
    try {
        var isAdded = document.getElementById('eas-iframe');

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

        var siteurl = document.URL;

        var regSite = "(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}))|(stackoverflow.com/questions/([0-9]*)/)|(community.powerbi.com/t5/.*/m-p/([0-9]*))";

        var re = new RegExp(regSite);
        
        var myArray = re.exec(siteurl);
        
        var isAutoExpand = false;
        
        var firstChild;
        var sidebar;
        
        if (siteurl.match(re)) {
            if(siteurl.indexOf("microsoft.com") > -1){
                //MSDN&TechNet
                //alert("MSDN&TechNet");
                sidebar = document.getElementById('sidebar');
                if(sidebar === null )
                    return;
                firstChild = sidebar.getElementsByTagName('section')[0];
                if(firstChild!==undefined){
                //MSDN
                var url = CacheSafeReload('https://analyzeit.azurewebsites.net/Redirection/Navigate/' + myArray[2] + '?external=mt&type=iframe');
                isAutoExpand = localStorage.getItem("isMSDNAutoExpand");
                if(isAutoExpand !== undefined && isAutoExpand == "true") {
                    var section = document.createElement('section');
                    section.innerHTML = '<section id="eas-iframe"></section>';
                    sidebar.insertBefore(section.firstChild, firstChild);
                    InsertMSDNIframe(url);
                }
                else {
                    AddEAMSDNButton(sidebar, firstChild, url);
                }

                var isAddedLink = document.getElementById('earedirect');
                if(isAddedLink === null)
                {
                    var div = document.getElementById('threadPageContainer').getElementsByTagName('h1')[0];
                    div.innerHTML += "<a id='earedirect' target='_blank' href='https://analyzeit.azurewebsites.net/Redirection/Navigate/"+ myArray[2] +"?external=mt' style='cursor: pointer;margin-left: -10px;'><img src='http://analyzeit.azurewebsites.net/content/images/tag.png' class='icon' style='width: 25px;height: 25px;'></a>";
                }
            }
            }
            if(siteurl.indexOf("stackoverflow.com") > -1){
                //StackOverflow
                //alert("StackOverflow");
                regSite = "stackoverflow.com/questions/([0-9]*)/";
                re = new RegExp(regSite);
                myArray = re.exec(siteurl);
                sidebar = document.getElementById('sidebar');
                var sourl = CacheSafeReload('https://analyzeit.azurewebsites.net/Redirection/Navigate/' + myArray[1] + '?external=sotool&type=iframe');
                isAutoExpand = localStorage.getItem("isSOAutoExpand");
                if(isAutoExpand !== undefined && isAutoExpand == "true") {
                    firstChild = sidebar.getElementsByTagName('div')[0];
                    var adddiv = document.createElement('div');
                    adddiv.innerHTML = '<div class="module" id="eas-iframe"></div>';
                    sidebar.insertBefore(adddiv, firstChild);
                    InsertSOIframe(sourl);
                }
                else {
                    AddEASOButton(sidebar, sourl);
                }
            }
            if(siteurl.indexOf("powerbi.com") > -1){
                //PowerBI
                //alert("PowerBI");
                regSite = "community.powerbi.com/t5/.*/m-p/([0-9]*)";
                re = new RegExp(regSite);
                myArray = re.exec(siteurl);
                //alert(myArray[1]);
                var pbiurl = CacheSafeReload('https://analyzeit.azurewebsites.net/Redirection/Navigate/'+ myArray[1] +'?external=powerbi&type=iframe');
                isAutoExpand = localStorage.getItem("isPBIAutoExpand");
                var referenceNode = document.getElementsByClassName("lia-quilt-column-main-left")[0].getElementsByClassName("lia-component-author")[0];
                if(isAutoExpand !== undefined && isAutoExpand == "true") {
                    var addpbidiv = document.createElement('div');
                    addpbidiv.innerHTML = '<div class="module" id="eas-iframe"></div>';
                    referenceNode.parentNode.insertBefore(addpbidiv, referenceNode);
                    InsertPBIIframe(pbiurl);
                }
                else {
                    AddEAPBIButton(referenceNode.parentNode, pbiurl);
                }
            }
        }
    }
    catch (err) {
        //alert(err.message);
        if (confirm(err.message + ', report it now ?')) {
            OpenLinkNewTab("https://github.com/myfreedom614/easy-analysis/issues");
        } else {
            // Do nothing!
        }
    }

    window.addin = this;
})();