Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Скрытие по флажкам в /mad/.
// ==UserScript==
// @name Genocide /mad/
// @namespace madgenocide
// @version 0.1
// @description Скрытие по флажкам в /mad/.
// @author neko
// @match http://dobrochan.com/mad/*
// @match http://dobrochan.org/mad/*
// @match http://dobrochan.ru/mad/*
// @grant none
// ==/UserScript==
(function() {
"use strict";
var div = document.createElement("div");
div.innerHTML = "Очистить черный список";
div.addEventListener("click", clear);
document.body.querySelector("#delete_form").appendChild(div);
newPropColorEl();
infection(".ipmark", hidePost, ".iphash", "color", true);
infection("img.geoicon", hidePost, "img.geoicon", "title", false);
if (localStorage.ninja === "true") {
localStorage.removeItem("geoicon");
localStorage.removeItem("flag");
}
localStorage.ninja = false;
div.style.color = "#A91D11";
if (localStorage.flag && localStorage.flag !== "") {
localStorage.flag = localStorage.flag;
inspector(true);
} else {
localStorage.flag = "";
}
if (localStorage.geoicon && localStorage.geoicon !== "") {
localStorage.geoicon = localStorage.geoicon;
inspector(false);
} else {
localStorage.geoicon = "";
}
function inspector(check) {
var els,
elsStor,
attr,
i,
j;
if (check) {
els = document.querySelectorAll(".iphash");
elsStor = localStorage.flag;
attr = "color";
} else {
els = document.querySelectorAll("img.geoicon");
elsStor = localStorage.geoicon;
attr = "title";
}
elsStor = elsStor.split(",");
for (i = elsStor.length - 1; i >= 0; i--) {
for (j = els.length - 1; j >= 0; j--) {
if (els[j][attr] === elsStor[i]) {
els[j].closest("table.post").hidden = true;
}
}
}
}
function newPropColorEl() {
var els = document.querySelectorAll("table.post.replypost span.iphash"),
i,
tmp,
color;
for (i = els.length - 1; i >= 0; i--) {
tmp = els[i].children;
color = [].map.call(tmp, function (tmpF) {
return tmpF.getAttribute("style").match(/#(.+);/)[1];
}).join("");
els[i].color = color;
}
}
function hidePost(css, attr, mode) {
var els = document.querySelectorAll(css),
self = this,
i,
tmp = (mode ? self.closest(css).color : self[attr]);
if (mode) {
localStorage.flag += tmp + ",";
} else {
localStorage.geoicon += tmp + ",";
}
for (i = els.length - 1; i >= 0; i--) {
if (mode && els[i][attr] === tmp) {
els[i].closest("table.post").hidden = true;
} else if (!mode && els[i][attr] === tmp) {
els[i].closest("table.post").hidden = true;
}
}
}
function infection(search, func, css, attr, mode) {
var els = document.querySelectorAll(search),
i,
newFunc = save(func, css, attr, mode);
for (i = els.length - 1; i >= 0; i--) {
els[i].addEventListener("click", newFunc);
}
function save(func, css, attr, mode) {
return function() {
return func.call(this, css, attr, mode);
};
}
}
function clear() {
if (div.clear) {
localStorage.ninja = false;
div.style.color = "#A91D11";
} else {
localStorage.ninja = true;
div.style.color = "#00693E";
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.