// ==UserScript==
// @name dA_ignore
// @namespace dA_ignore
// @author Dediggefedde
// @description ignores people on dA
// @match http://*.deviantart.com/*
// @match https://*.deviantart.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js
// @version 1.6
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.xmlHttpRequest
// @downloadURL none
// ==/UserScript==
/* globals $*/
/* globals DiFi*/
/*
Hide comment:
"4757159042", //commentid
"298766207", //devid
"1" //comment/hide ?
DiFi.pushPost("CommentAttributes", "hide", ["4757159042", "298766207", "1"], function (success, data) {
console.log(data.response.content);
//tag-count
});
DiFi.send();
eclipse
www.deviantart.com/_napi/shared_api/comments/hide
{
"itemid": 298766207,
"commentid": 4757159042,
"csrf_token": "ZktacCZRqLRc5PzX.q4d2x4.F9_UD4YFxrV8ewlj4-W5VzfVLZfdTkH5bMO0edRXhTo"
}
Hide description?
DiFi.pushPost("DeviationView","getExtrasHTML",["501848540","",{},{"is_referred":0,"origin":"dynamic_nav_click","is_new_tab":1}],function(success, data){
console.log(data.response.content.html_col1.split("http://www.deviantart.com/tag/").length);
//tag-count
});
DiFi.send();
*/
let ignorenames = [];
let settings = {
hideComments: false,
hideMessages: true,
deleteMessages: true,
hideProfile: true,
hideDeviations: true,
submitHideRequest: true,
};
function inIgnoreList(name) { //n array of string
let rex;
for (let n of name) {
if (n == "" || n == null) continue;
for (let i of ignorenames) {
if (i[0] == '#') {
rex = new RegExp(i.substr(1), "i");
if (rex.test(n.toLowerCase())) {
return true;
}
} else {
if (n.toLowerCase() == i.toLowerCase()) return true;
}
}
}
return false;
}
function pruf() {
//dynamic browsing, check all 1s.
setTimeout(pruf, 500);
let spambut = $("div[data-commentid]").filter(function(ind, el) { return el.innerText == "COMMENT HIDDEN"; });
if (spambut.length > 0 && $("#daIgnore_Unhide").length == 0) {
let unhidebutton = $("UnHide ")
.css({
"position": "absolute",
"top": "0",
"right": "0",
"border": "0",
"background-color": "#fff",
"cursor": "pointer",
});
spambut.append(unhidebutton);
let dUrl = $('meta[property="og:url"]').attr('content');
let deviationID = /(\d+)$/.exec(dUrl);
if (deviationID != null) { //deviation
deviationID = deviationID[1];
} else { //profile
deviationID = $("header[data-hook=top_nav] a.user-link").data("userid");
}
let token = $("input[name=validate_token]").val();
let commentid = spambut.data("commentid");
unhidebutton.click(function() {
let dat = {
"itemid": deviationID,
"commentid": commentid,
"csrf_token": token.toString()
};
GM.xmlHttpRequest({
method: "POST",
url: "https://www.deviantart.com/_napi/shared_api/comments/unhide",
headers: {
"accept": 'application/json, text/plain, */*',
"content-type": 'application/json;charset=UTF-8'
},
dataType: 'json',
data: JSON.stringify(dat),
onerror: function(response) {
console.log("error:", response);
},
onload: async function(response) {
console.log("response", response);
spambut.find("button").first().click();
}
});
});
}
let bnam = $('a.u:not(notignore),a.user-link:not(notignore),div.tt-a:not(notignore),img.avatar:not(notignore)').attr('notignore', '').filter(function() {
return inIgnoreList([$(this).text(), $(this).attr("username"), $(this).attr("title")]);
});
if (bnam.length == 0) return;
if (settings.hideDeviations) {
thumbs = $("section[data-hook=\"deviation_std_thumb\"]:not(notignore)").attr("notignore", "").filter((id, dl) => {
let el = $(dl).find("a[data-hook=\"deviation_link\"]");
if (el.length > 0) el = el.attr("href");
else return false;
el = el.match(/deviantart.com\/(.*?)\//);
if (!el || el.length == 1) return false;
return inIgnoreList([el[1]]);
});
thumbs.remove();
}
if (settings.hideProfile &&
$("#da_unignore_but").length == 0 &&
$("nav[data-hook=profile_nav]").length > 0 &&
inIgnoreList([location.href.match(/deviantart\.com\/(.*)($|\/)/i)[1]])
) {
let replaceSite = '
You blocked this user! ';
$('#content-container section').remove();
$("#content-container").append(replaceSite);
let ignorebut = $("#da_ignore_but").html("UnIgnore")
.attr({ "title": "remove from your ignore-list", "id": "da_unignore_but" })
.off("click");
let clicker = function() {
let foundindex = ignorenames.indexOf($(this).attr("userid"));
ignorenames.splice(foundindex, 1);
setTimeout(() => {
GM.setValue('blocklist', [...new Set(ignorenames)].join("\n"));
location.reload();
}, 0);
};
ignorebut.click(clicker);
let userid = $("#content-container a.user-link").first().data("userid");
ignorebut.attr("userid", userid);
return;
}
if (settings.deleteMessages && location.href.includes("www.deviantart.com/notifications/")) {
bnam.closest("section").find("button[aria-label=Remove]").click();
} else if (bnam.filter("img.avatar").closest("div.grf-deviants").length > 0) {
bnam.filter("img.avatar").closest("span.f").remove();
bnam.filter("img.avatar").closest("div.grf-deviants").remove();
}
if (bnam.filter("img.avatar").closest('a').length > 0) {
bnam.filter("img.avatar").closest("a").remove();
}
if (settings.hideMessages && location.href.includes("www.deviantart.com/notifications/")) {
bnam.closest("section").parent().parent().remove();
}
if (settings.submitHideRequest) {
let dUrl = $('meta[property="og:url"]').attr('content');
let deviationID = /(\d+)$/.exec(dUrl);
if (deviationID != null) { //deviation
deviationID = deviationID[1];
} else { //profile
deviationID = $("header[data-hook=top_nav] a.user-link").data("userid");
}
let token = $("input[name=validate_token]").val();
let els = bnam.closest("div[data-commentid]");
els.not(".ccomment-hidden").addClass("ccomment-hidden").each((i, el) => {
let dat = {
"itemid": deviationID,
"commentid": $(el).data("commentid"),
"csrf_token": token.toString()
};
GM.xmlHttpRequest({
method: "POST",
url: "https://www.deviantart.com/_napi/shared_api/comments/hide",
headers: {
"accept": 'application/json, text/plain, */*',
"content-type": 'application/json;charset=UTF-8'
},
dataType: 'json',
data: JSON.stringify(dat),
onerror: function(response) {
console.log("error:", response);
},
onload: async function(response) {
console.log("response", response);
}
});
});
}
if (settings.hideComments) {
let cContainer = bnam.closest('div.ccomment');
cContainer.remove();
bnam.closest('div').remove(); //eclipse
}
if (settings.hideComments && bnam.parents('div.deviation-full-minipage').length > 0) {
bnam.parents('div.deviation-full-minipage').prev("div.deviation-full-container").remove();
bnam.parents('div.deviation-full-minipage').remove();
}
}
//is profile, add ignorebutton
if ($("nav[data-hook=profile_nav]").length > 0) {
if ($("#da_ignore_but").length == 0) {
let ignoreBut = $('Ignore ');
let nav = $("nav[data-hook=profile_nav]");
nav.append(ignoreBut);
ignoreBut.css("background-image", "linear-gradient(242deg,#f00,#ddef31)")
.attr("class", ignoreBut.prev().find("button").attr("class"))
.click(function() {
ignorenames.push($("#content-container a.user-link").first().data("username").toLowerCase());
setTimeout(() => {
GM.setValue('blocklist', [...new Set(ignorenames)].join("\n")); //save unique array
}, 0);
});
}
}
//settings page, add custom settings
if (location.href.indexOf('https://www.deviantart.com/settings') == 0) {
let ignoremenu = $('Ignore User ');
$('#settings_public').parent().after(ignoremenu);
ignoremenu.find('a').click(function() {
$('a.active').removeClass('active');
$(this).addClass('active');
$('div.settings_form').html('' +
'' +
'
' +
'
Ignore Users ' +
'
Separate usernames by linebreaks! ' +
'
' +
'' +
' ' +
'
' +
'' +
'');
$('#da_ignore_saveblocklist').click(() => {
ignorenames = $('#da_ignore_textarea').val().toLowerCase().split('\n');
setTimeout(() => {
GM.setValue('blocklist', [...new Set(ignorenames)].join("\n"));
}, 0);
alert('List saved!');
});
$('#da_ignore_savesettings').click(() => {
settings.hideComments = $('#da_ignore_hideComments').prop('checked');
settings.hideMessages = $('#da_ignore_hideMessages').prop('checked');
settings.deleteMessages = $('#da_ignore_deleteMessages').prop('checked');
settings.hideProfile = $('#da_ignore_hideprofile').prop('checked');
settings.hideDeviations = $('#da_ignore_hideDeviations').prop('checked');
settings.submitHideRequest = $('#da_ignore_submitHideRquest').prop('checked');
setTimeout(() => {
GM.setValue('settings', JSON.stringify(settings));
}, 0);
alert('List saved!');
});
});
}
async function loadsettings() {
let Zignorenames = await GM.getValue('blocklist', null);
if (Zignorenames != null) ignorenames = Zignorenames.split('\n');
let Zsettings = await GM.getValue('settings', null);
if (Zsettings != null) settings = $.parseJSON(Zsettings);
if (settings.hideComments == null) settings.hideComments = true;
if (settings.hideMessages == null) settings.hideMessages = false;
if (settings.deleteMessages == null) settings.deleteMessages = true;
if (settings.hideProfile == null) settings.hideProfile = true;
if (settings.hideDeviations == null) settings.hideDeviations = true;
}
let prom = loadsettings();
prom.then(pruf);