Immodem

try to take over the world!

目前为 2018-10-08 提交的版本。查看 最新版本

// ==UserScript==
// @name         Immodem
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  try to take over the world!
// @author       coz3n
// @match        https://immodem.poste-immo.intra.laposte.fr/*
// @grant        none
// ==/UserScript==

var obsconf = {childList: true},
    nodes = [],
    hash,
    initlaunch,
    url = [],
    css = document.createTextNode("html{box-sizing:border-box}body{background:linear-gradient(to bottom,#fff 0,#ddd 100%)!important}div vertilize-container{justify-content:space-between}#wrap{display:-webkit-flex;display:-moz-flex;display:-ms-flex;display:-o-flex;display:flex;flex-flow:row nowrap}.entete{width:100%;height:48px;text-align:center;font-size:1.5em;color:#fff;text-shadow:0 1px solid #aaa}.bucket{padding:24px 8px 8px;margin:0 10px;display:flex;flex-flow:column nowrap;flex:1 100%;background:#ddd}.bucket>div{width:100%!important}[id=\"Validation technique\"]{order:1}#Réalisation{order:2}.taskCard{border-radius:2px!important;border:none;box-shadow:0 1px 2px 0 rgba(0,0,0,.5);transition:box-shadow .25s linear;height:auto!important}.taskCard:hover{box-shadow:0 2px 4px 1px rgba(0,0,0,.5)}p{margin-bottom:6px}@font-face{font-family:Roboto;font-style:normal;font-weight:400;src:local('Roboto Regular'),local('Roboto-Regular'),url(https://themes.googleusercontent.com/static/fonts/roboto/v11/2UX7WLTfW3W8TclTUvlFyQ.woff) format('woff')}*{font-family:roboto}"),
    initLaunch,
    buckets = {};


var observer = new MutationObserver(function(mutations) {
    // For the sake of...observation...let's output the mutation to console to see how this all works
    mutations.forEach(function(mutation) {
        //console.log(mutation);
        var cards = document.getElementsByClassName('taskCard');
        if (cards) {
            for (var card = 0; card < cards.length; card++) {
                var step = cards[card].getElementsByClassName("label-info")[0];
                if (step) {
                    var bucket = document.getElementById(step.innerHTML);
                    if (bucket) {
                        bucket.appendChild(cards[card].parentElement);
                    } else {
                        console.log("Il n'y a pas de de bucket pour ranger : ", cards[card]);
                    }
                }
            }
        }
    });
});

window.onload = function() {
    console.log("page loaded");
}

window.onhashchange = function(event) {
    url = event.newURL.split("/");
    hash = url[url.length - 1];

    if (hash == "cartTasks") {
        initLaunch = setTimeout(init, 500);
    } else {
        console.log("Pas de modification sur cette url")
    };
}

function init() {
    var wrap = document.querySelectorAll("[vertilize-container]")[0],
        style = document.createElement('style');
    style.type = 'text/css';
    style.appendChild(css);
    document.head.appendChild(style);

    wrap.id = "wrap";

    var cards = wrap.children;
    for (var i = 0; i < cards.length; i++) {
        var label = cards[i].getElementsByClassName("itemStep")[0].firstElementChild.innerHTML;
        if (buckets[label]) {
            buckets[label].push(cards[i]);
        } else {
            buckets[label] = [];
            buckets[label].push(cards[i]);
        }
    }
    makeEnv(buckets, wrap);
    observer.observe(wrap, obsconf);
}

function makeEnv(buckets, wrap) {
//    console.log(el);
    var step = Object.keys(buckets);
    for (var i = 0; i < step.length; i++) {
        var bucket = document.createElement("div");
        bucket.classList.add('bucket');
        bucket.id = step[i];
        for (var j = 0; j < buckets[step[i]].length; j++){
            bucket.appendChild(buckets[step[i]][j]);
        }
        //console.log(bucket);
        wrap.appendChild(bucket);
    }
}