DomainKiller

Automatycznie zakopuje wybrane domeny. Działa na wykopy sponsorowane.

当前为 2017-08-16 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name DomainKiller
// @version 0.92
// @description Automatycznie zakopuje wybrane domeny. Działa na wykopy sponsorowane. 
// @author llinney małpa outlook.com
// @grant none
// @match http://www.wykop.pl/wykopalisko/*
// @match https://www.wykop.pl/wykopalisko/*
// @namespace http://www.wykop.pl/
// ==/UserScript==

// you can fill hardcoded domains table for preserving settings even after browser storage has been cleared.
// example:
// var hardCodedDomains = ['youtube.pl', 'liveleak.com'];
var hardCodedDomains = [];

const icoLock = '<i class="fa fa-lock"></i>';
const icoEye = '<i class="fa fa-eye-slash"></i>';
const icoX = '<i class="fa fa-times"></i>';
const blockedIconLi = '<li><a id="domainKillerPanel" title="Zakopywane domeny" class="dropdown-show ajax">' + icoLock + '</a></li>';
const blockedPanel = '<div id="domainKillerPanelDiv" class="dropdown right notificationsContainer bodyClosable"><div><ul id="domainKillerPanelList" class="menu-list"></ul><div></div>';

function getBlockedDomains() {
    return JSON.parse(localStorage.getItem("unwantedDomains"));
}

function setBlockedDomains(domains) {
    localStorage.setItem("unwantedDomains", JSON.stringify(domains));
}

function removeDomainFromArray(ind) {
    var array = getBlockedDomains();
    var removedIt = array.splice(ind,1);
    setBlockedDomains(array);
    $('#domainKillerPanelListItem' + ind).parent().parent().hide();
}

function createPanel() {
    $('#domainKillerPanel').after(blockedPanel);
        var array = getBlockedDomains();
        var iter = 0;
        array.forEach(function(domain) {
            var currIt = iter;
            $('#domainKillerPanelList').append('<li><p><a  href="' + 'https://www.wykop.pl/szukaj/url:' + domain + '">' + domain + '</a><a id="domainKillerPanelListItem' + iter + '"title="Usuń z listy" class="close">' + icoX + '</a></p></li>');
            var name = '#domainKillerPanelListItem' + iter;
            $(name).on( "click", function() {
                removeDomainFromArray(currIt);
            });
            iter++;
        });
}

function togglePanel() {
    $('#domainKillerPanelDiv').toggle();
}

function addSettingsIcon() {
    $('#openNaturalSearch').parent().parent().prepend(blockedIconLi);

    $( "#domainKillerPanel" ).on( "click", function() {
        togglePanel();
    });
}

function addDownIcon(tagLine) {
    var source = $(tagLine)[0].getElementsByClassName('affect')[1].innerHTML.toString();
    $(tagLine).children('.tag.create').eq(2).before("<a href='' class='tag affect create' onclick='var array = JSON.parse(localStorage.getItem(\"unwantedDomains\"));Array.prototype.push.apply(array, [\"" + source + "\"]);localStorage.setItem(\"unwantedDomains\", JSON.stringify(array));'>zakopuj domenę</a>");
}

function downAll() {
    var array = getBlockedDomains();
    var iter = 0;

    $('.article.clearfix.preview.dC').each(function() {
        var downvote;
        var tagLine = $(this).find('.fix-tagline');
        addDownIcon(tagLine, iter);
	iter++;
        var source = $(tagLine)[0].getElementsByClassName('affect')[1].innerHTML.toString();

        if (shouldDown(source, array)) {
		try {
	  	    //console.log('Proba zakopania: ' + $(this).find('h2').children().eq(0).attr('href'));
		    var hide = this.getElementsByClassName('fix-tagline')[0].getElementsByClassName('ajax affect create')[0];
		    if (typeof hide === "undefined") {
			return;
		    } else {
			hide.click();
		    }
		    var that = this;
		    downvote = this.getElementsByClassName('dropdown fix-dropdown bodyClosable');

		    if (downvote.length > 0) {
		        downvote = downvote[0].getElementsByClassName('ajax');
		     	downvote[4].click();    
		    } else {
		        var upVote = this.getElementsByClassName('button button submit');
			if (typeof upVote[0] != "undefined") {
		            upVote[0].click();
			} else { return }
		        var undo = this.getElementsByClassName('ajax');

		        setTimeout(function() {
		            undo[0].click();

		            setTimeout(function() {
		                downvote = that.getElementsByClassName('dropdown fix-dropdown bodyClosable')[0].getElementsByClassName('ajax');
		                downvote[4].click();
		            }, 2000);
		        }, 2000);
		    }
		    //console.log('Zakopano: ' + $(this).find('h2').children().eq(0).attr('href'));
		} catch (e) {
			console.log('Blad podczas zakopywania: ' + $(that).find('h2').children().eq(0).attr('href'));
			console.log(e);
		}
        }
    });
}

$(document).ready(function() {
    if (localStorage.getItem("unwantedDomains") === null) {
        setBlockedDomains(hardCodedDomains);
    }
    work();
});

function shouldDown(source, array) {

    if(jQuery.inArray(source, array) > -1) {
        return true;
    }

    return false;
}

function work() {
    addSettingsIcon();
    createPanel();
    downAll();
}