Google+ Column Adjustments

Google+ Columns Adjustment

2015-11-19 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

/*

Following code belongs to Avatars Plus! and More for Google+.
Copyright (C) 2016 Jackson Tan
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.

*/

// ==UserScript==
// @id             GPlusColumnAdj
// @name           Google+ Column Adjustments
// @version        0.1.1
// @namespace      gplus.columnadj
// @author         Jackson Tan
// @description    Google+ Columns Adjustment
// @include        https://plus.google.com/*
// @exclude        /https://plus\.google\.com(/u/\d+)?/?stream/circles/.+/i
// @exclude	       /https://plus\.google\.com(/u/\d+)?/?b/.+/i
// @run-at         document-end
// @grant          GM_xmlhttpRequest
// ==/UserScript==

GM_addStyle = function (css) {
    var head = document.getElementsByTagName('head')[0], style = document.createElement('style');
    if (!head) { return }
    style.type = 'text/css';
    try { style.innerHTML = css } catch (x) { style.innerText = css }
    head.appendChild(style);
}

function minIndexThreeNum(a, b, c) {
    var result = Math.min(Math.min(a, b), c);
    if (result == a)
        return 0;
    else if (result == b)
        return 1;
    return 2;
}

function appendHtmlToNode(html, node) {
    node.innerHTML += html;
}

function buildElem(tagName, className, attr1, val1, attr2, val2) {
    var elem = document.createElement(tagName);
    elem.className = className;
    elem.setAttribute(attr1, val1);
    elem.setAttribute(attr2, val2);
    return elem;
}

function buildArr(length, colA, colB, modulo) {
    var newColumn = new Array();
    var a = 0, b = 0, flag = false, count = 0;
    for (var i = 0; i < length; i++) {
        flag = !flag;
        if (i != 0 && (i + 1) % modulo == 0) {
            if (flag)
                newColumn[newColumn.length] = colA[a + 1];
            else
                newColumn[newColumn.length] = colB[b];
        }
        if (flag) {
            a++;
        }
        else {
            b++;
        }
    }
    return newColumn;
}

function buildColumn(colArr, className, jsName, insertTarget) {
    var colDiv = buildElem("div", className, "jsName", jsName, "role", "list");
    for (var i = 0; i < colArr.length; i++) {
        appendHtmlToNode(colArr[i].outerHTML, colDiv);
        colArr[i].outerHTML = "";
    }
    insertTarget.appendChild(colDiv);
}

var listenerPostInsertion = function (e) {
    document.getElementsByClassName(streamColClass)[0].removeEventListener('DOMNodeInserted', listenerPostInsertion, false);
    document.getElementsByClassName(streamColClass)[1].removeEventListener('DOMNodeInserted', listenerPostInsertion, false);
    if (e.target.nodeType != 3 && e.target.tagName == postTagName) {
        console.log(minIndexThreeNum(col0.length - 1, col1.length, colParent.childNodes[2].childNodes.length));
        var postHTML = e.target.outerHTML;
        e.target.outerHTML = "none";
        console.log(postHTML);
        console.log(e.target.outerHTML);
        insertTargetNode.childNodes[minIndexThreeNum(col0.length - 1, col1.length, colParent.childNodes[2].childNodes.length)].innerHTML += postHTML;
    }
    document.getElementsByClassName(streamColClass)[0].addEventListener('DOMNodeInserted', listenerPostInsertion, false);
    document.getElementsByClassName(streamColClass)[1].addEventListener('DOMNodeInserted', listenerPostInsertion, false);
};

function onLoad() {
    var streamColClass = "H68wj jxKp7";
    var streamColJsName = "dJDgTb";

    var colParent = document.getElementsByClassName(streamColClass)[0].parentNode;
    var col0 = document.getElementsByClassName(streamColClass)[0].childNodes;
    var col1 = document.getElementsByClassName(streamColClass)[1].childNodes;

    var len_col0 = col0.length - 1;
    var len_col1 = col1.length;
    var total_col = 3;
    var newColArr = buildArr(len_col0 + len_col1, col0, col1, total_col);
    buildColumn(newColArr, streamColClass, streamColJsName, colParent);

    var postTagName = "C-FPDNBB";
    var insertTargetNode = colParent;

    document.getElementsByClassName(streamColClass)[0].addEventListener('DOMNodeInserted', listenerPostInsertion, false);
    document.getElementsByClassName(streamColClass)[1].addEventListener('DOMNodeInserted', listenerPostInsertion, false);
}

document.addEventListener("DOMContentLoaded", onLoad, false);