Greasy Fork is available in English.

Overmind Helper

try to take over the world!

// ==UserScript==
// @name         Overmind Helper
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @author       You
// @include      /^http?://overmind\.hz\.netease\.com/.*$
// @grant        none
// ==/UserScript==

// @include      /^http?://overmind\.hz\.netease\.com/\d+/sprint/list.*$
// @include      /^http?://overmind\.hz\.netease\.com/\d+/sprint/todo/\d+/list.*$

var saveRecentSprints = function(){
    console.log('saveRecentSprints');
    setTimeout(function(){
        hideRecentSprients();

        var title = document.getElementsByClassName("m-header")[0].textContent.split("/")[1];
        var recentSprintsJson = window.localStorage.getItem("recentSprints");
        if (recentSprintsJson == null) {
            recentSprintsJson = "{}";
            window.localStorage.setItem("recentSprints", recentSprintsJson);
        }

        var recentSprints = JSON.parse(recentSprintsJson);
        if (recentSprints[title] == null) {
            recentSprints[title] = location.href;
            recentSprintsJson = JSON.stringify(recentSprints);
            window.localStorage.setItem("recentSprints", recentSprintsJson);
        }
    }, 1000);
};

var showRecentSprints = function(){
    console.log('showRecentSprints');
    setTimeout(function(){
        hideRecentSprients();

        var recentSprintsJson = window.localStorage.getItem("recentSprints");
        if (recentSprintsJson == null) {
            recentSprintsJson = "{}";
            window.localStorage.setItem("recentSprints", recentSprintsJson);
        }
        var recentSprints = JSON.parse(recentSprintsJson);

        var recent = document.createElement('div');
        recent.setAttribute("id", "myRecentSprints");
        var container = document.getElementById("container");
        container.insertBefore(recent, container.children[1]);

        var title = document.createElement('div');
        title.innerHTML = "<span>最近使用&nbsp;<a id=\"clearMyRecentSprints\">[清空]</a></span>";
        recent.appendChild(title);

        document.getElementById("clearMyRecentSprints").addEventListener('click',function(){
            window.localStorage.removeItem("recentSprints");
            hideRecentSprients();
            showRecentSprints();
		}, false)

        var list = document.createElement('ol');
        recent.appendChild(list);
        for(var sprint in recentSprints) {
            var item = document.createElement('li');
            item.innerHTML="<a href=\"" + recentSprints[sprint] + "\">" + sprint + "</a>";
            list.appendChild(item);
        }

     }, 1000);
};

var hideRecentSprients = function() {
    console.log('hideRecentSprients');
    var recent = document.getElementById("myRecentSprints");
    if (recent != null) {
        recent.parentElement.removeChild(recent);
    }
};

var refreshRecentSprints = function() {
    if (location.pathname.includes("/sprint/todo/")) {
        hideRecentSprients();
        saveRecentSprints();
    } else if(location.pathname.includes("/sprint/list")) {
        hideRecentSprients();
        showRecentSprints();
    } else {
        hideRecentSprients();
    }
};

var fixProjectMenuWidth = function() {
    try {
        document.getElementsByClassName("g-page")[0].childNodes[0].childNodes[1].childNodes[0].style.width="400px"
    } catch (error) {
        console.error(error);
    }
};

(function() {
    'use strict';

    // alert("hahaha " + location.pathname );
    setTimeout(function(){

        history.pushState = ( f => function pushState(){
            var ret = f.apply(this, arguments);
            window.dispatchEvent(new Event('pushstate'));
            window.dispatchEvent(new Event('locationchange'));
            return ret;
        })(history.pushState);

        history.replaceState = ( f => function replaceState(){
            var ret = f.apply(this, arguments);
            window.dispatchEvent(new Event('replacestate'));
            window.dispatchEvent(new Event('locationchange'));
            return ret;
        })(history.replaceState);

        window.addEventListener('popstate',()=>{
            window.dispatchEvent(new Event('locationchange'))
        });

        window.addEventListener('locationchange', function(){
            console.log('location changed!');
            refreshRecentSprints();
            fixProjectMenuWidth();
        });

        refreshRecentSprints();
        fixProjectMenuWidth();

    }, 1000);


})();