Thanos script

random remove half elements when triple click page

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Thanos script
// @name:zh-CN   灭霸脚本
// @version      0.2.1
// @description  random remove half elements when triple click page
// @description:zh-CN 鼠标三击页面的时候,随机移除页面上的一半元素
// @author       tabedit
// @include     *
// @grant        none
// @namespace https://greasyfork.org/users/225710
// ==/UserScript==

(function() {
    'use strict';

    function fingerSnap(){
        'use strict'
        var nodeIter = document.createNodeIterator(
            document.body,NodeFilter.SHOW_TEXT + NodeFilter.SHOW_ELEMENT +
            NodeFilter.SHOW_COMMENT ,null);
        var leafNode = [];
        var nn;
        while (true){
            nn = nodeIter.nextNode();
            if(nn === null){
                break;
            }
            if (nn.childNodes.length === 0){
                leafNode.push(nn);
            }
        }
        for(var ind = 0; ind < leafNode.length; ind++){
            if (Math.random() < 0.5){
                removeLeafNode(leafNode[ind]);
            }
        }
    }

    function removeLeafNode(aNode){
        var timeDurition = 2;
        try {
            if (aNode.nodeType === 1){
                aNode.style.transition='transform ' + timeDurition + 's' + ',opacity ' + timeDurition + 's';
                aNode.style.transform = 'rotate(180deg) scale(0, 0)';
                aNode.style.opacity = '0.3';
            } else if(aNode.nodeType === 3){
                var aNodeParent = aNode.parentNode;
                aNodeParent.style.transition='color ' + timeDurition + 's';
                var aNodeCompStyle = document.defaultView.getComputedStyle(aNodeParent);
                aNodeParent.style.color = aNodeCompStyle.color.replace('rgb','rgba').replace(')',',0)')
            }

            setTimeout(function(){
                aNode.parentNode.removeChild(aNode);
            },timeDurition * 1000);
        }
        catch(e){
            debugger;
        }
    }


    var threeClick = function (){
        'use strict'
        var timeSeq = [1, 100000, 200000];
        var MININTERVAL = 400;
        return function(){
            var now = new Date();
            console.log(now.getTime());
            timeSeq.push(now.getTime());
            timeSeq.shift();
            if(timeSeq[1] - timeSeq[0] < MININTERVAL &&
               timeSeq[2] - timeSeq[1] < MININTERVAL){
                fingerSnap()
            }
        }
    }();

    document.addEventListener('click',threeClick);
})();