Easy Analysis Extension

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

目前为 2016-03-03 提交的版本。查看 最新版本

// ==UserScript==
// @name         Easy Analysis Extension
// @version      1.9.5
// @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/3/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/*
// @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://gf.qytechs.cn/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 AddListenerToAutoExpand() {
        document.getElementById("autoExpand").addEventListener("click", function(){
            SaveAutoExpangeSetting(); }, false);
    }
    function LoadAutoExpangeSetting() {
        var isAutoExpand = localStorage.getItem("isAutoExpand");
        if(isAutoExpand !== undefined && isAutoExpand == "true") {
            var chkBox = document.getElementById('autoExpand');
            chkBox.checked = true;
        }
    }
    function SaveAutoExpangeSetting() {
        var chkBox = document.getElementById('autoExpand');
        if (chkBox.checked) {
            //alert("checked");
            localStorage.setItem("isAutoExpand", true);
        }
        else {
            //alert("unchecked");
            localStorage.setItem("isAutoExpand", 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();
        AddListenerToAutoExpand();
    }
    function AddEASOButton(sidebar, link) {
        firstChild = sidebar.getElementsByTagName('div')[0];
        var adddiv = document.createElement('div');
        adddiv.innerHTML = '<div class="module" id="eas-iframe"><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);
    }
    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();
        AddListenerToAutoExpand();
    }
    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;"><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:95%;"></iframe></div>';
        var div= divs.firstChild;
        goToSection.parentNode.replaceChild(div, goToSection);
        document.getElementById("collapseeas").addEventListener("click", function(){
            CollapseSOIframe(link);}, false);
    }
    function CollapseSOIframe(link) {
        var goToSection = document.getElementById('eas-iframe');
        goToSection.parentNode.removeChild(goToSection);
        var sidebar = document.getElementById('sidebar');
        AddEASOButton(sidebar, 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]*)/)";

        var re = new RegExp(regSite);

        if (siteurl.match(re)) {
            var myArray = re.exec(siteurl);
            var sidebar = document.getElementById('sidebar');
            if(sidebar === null )
                return;
            var firstChild = sidebar.getElementsByTagName('section')[0];
            if(firstChild!==undefined){
                //MSDN
                var url = 'https://analyzeit.azurewebsites.net/Redirection/Navigate/' + myArray[2] + '?external=mt&type=iframe';
                var isAutoExpand = localStorage.getItem("isAutoExpand");
                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='http://analyzeit.azurewebsites.net/Redirection/Navigate/"+ myArray[2] +"?external=mt' style='cursor: pointer;margin-left: -10px;'><img src='http://skift.com/wp-content/themes/skift/img/redesign/sprites/tag.png' class='icon' style='width: 25px;height: 25px;'></a>";
                }
            }else {
                //StackOverflow
                regSite = "stackoverflow.com/questions/([0-9]*)/";
                re = new RegExp(regSite);
                myArray = re.exec(siteurl);
                var sourl = 'https://analyzeit.azurewebsites.net/Redirection/Navigate/' + myArray[1] + '?external=sotool&type=iframe';
                AddEASOButton(sidebar, sourl);
            }

        }
    }
    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;
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址