// ==UserScript==
// @name 보배드림 닉네임차단
// @author 보배이용자
// @namespace 없다
// @version 1.8
// @include *://*bobaedream.co.kr/*
// @description 특정 닉네임의 게시글 색상변경 및 클릭시 물어보기 & 댓글차단
// @require http://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js
// @grant GM.setValue
// @grant GM.getValue
// @grant GM.listValues
// @grant GM.deleteValue
// ==/UserScript==
var blockUserLists= [
'이웃과함께','계몽군주김정은','관종식물','와앙강우','THENEWK7PS','비깨도','문재인이머했너'
];
var mystoreg
if(window.localStorage.getItem('enc_id')==null?true:false){
mystoreg = window.localStorage;
}
window.Object['cueent_enc_id']="";
let gm_before,gm_after,list_count;
(async () => {
list_count = await GM.listValues();
if(list_count.some(function(arrayValue){return "enc_id" === arrayValue;})){
gm_before = await GM.getValue('enc_id');
console.log('Greasemonkey get has run', gm_before);
if(gm_before.length != 0){
let list = [];
if(localStorage.getItem('enc_id')==null?true:false){
localStorage.getItem('enc_id',[]);
}else{
if(JSON.parse(localStorage.getItem('enc_id')).length!=0){
list = JSON.parse(localStorage.getItem('enc_id'));
gm_before = await GM.setValue('enc_id', JSON.parse(JSON.stringify(list)));
gm_after = await GM.getValue('enc_id');
//localStorage.setItem('enc_id', JSON.stringify(gm_after));
console.log('Greasemonkey set has run', gm_after);
}else{
gm_after = await GM.getValue('enc_id');
localStorage.setItem('enc_id', JSON.stringify(gm_after));
console.log('Greasemonkey set localstorage has run', gm_after);
}
}
}else{
}
}else{
}
// Note awaiting the set -- required so the next get sees this set.
//await GM.setValue('count', gm_before + 1);
// Get the value again, just to demonstrate order-of-operations.
})();
//회원아이디 클릭 이베트 감지 설정
var config = { childList: true };
$(document).ready(function(){
//회원아이디 클릭 이베트 감지 타겟
var observer_target = document.getElementById('submenusel');
$("#cmt_reply > li > dl > dt > span.name > span").on('mouseenter',function(event){
add_ct=0; Object["cueent_enc_id"]=event.target.attributes.item('onclick').nodeValue.split("','")[0].split("('")[1];}); //코멘트
$("#boardlist > tbody > tr > td.author02 > span.author").on('mouseenter',function(event){
add_ct=0; Object["cueent_enc_id"]=event.target.attributes.item('onclick').nodeValue.split("','")[0].split("('")[1];}); //리스트게시물
$("#boardlist > tbody > tr > td.author > span.author").on('mouseenter',function(event){
add_ct=0; Object["cueent_enc_id"]=event.target.attributes.item('onclick').nodeValue.split("','")[0].split("('")[1];});//뷰어+리스트 게시물
var observer = new MutationObserver(
function(mutations) {
let add_ct=0;
mutations.forEach(
function(mutation) {
if(add_ct ==0){
if(mutation.type=="childList"){
//menu_add(Object["cueent_enc_id"]);
$("#submenusel > ol").prepend("<li style='width:130px;height:20px;text-align:left;padding-left:10px;color:4c4c4c;'><a href=\"javascript:Object.fn_save('"+Object["cueent_enc_id"]+"');\">차단하기</a></li>");
$("#submenusel > ol").prepend("<li style='width:130px;height:20px;text-align:left;padding-left:10px;color:4c4c4c;'><a href=\"javascript:Object.fn_delete('"+Object["cueent_enc_id"]+"');\">차단해재</a></li>");
setTimeout(function(){
var height =0;
$("#submenusel > ol > li").each(function(index,item){height +=item.offsetHeight;});
$("#submenusel").height((height+20)+"px");
},500);
add_ct++;
}
}
});
});
observer.observe(observer_target, config);
setlocalstoreg(blockUserLists);
});
function view_board_list(){
var link="";
var templocation="";
let target = null;
if(document.querySelectorAll(".author02").length==0){
target =document.querySelectorAll("td.author");
}else{
target = document.querySelectorAll("td.author02");
}
for (const nmt of target) {
for (const undi of blockUserLists) {
if(nmt.innerHTML.toString().indexOf(undi)!=-1 || check_enc_id(decodeURIComponent(nmt.firstElementChild.getAttribute('onclick').split("')")[0].split("('")[1]))){
nmt.parentElement.setAttribute("style", "background-color: red;");
var current_title = nmt.parentElement.children[1].firstChild.getAttribute("title");
console.log("=="+nmt.parentElement.querySelector('a').href == null? false:true);
if(nmt.parentElement.querySelector('a').href == null? false:true){//링크가 있는 녀석만 만들기
link=nmt.parentElement.querySelector('a').href.split('/view')[1].replace("';}","");
templocation = "javascript:if(confirm('차단한글이야 열어볼꺼야?')){this.location='"+"/view"+(link+"';}");
nmt.parentElement.querySelector('a').href=templocation;
nmt.parentElement.querySelector('a').setAttribute("title",current_title);
}
if(document.querySelector("#conView > div > div > div.docuArea02 > div.docuview_updown")!=null){//이전글 다음글 색상표시
var up_title = document.querySelector("#conView > div > div > div.docuArea02 > div.docuview_updown > dl > dd:nth-child(2)").firstElementChild.innerText;
var down_title = document.querySelector("#conView > div > div > div.docuArea02 > div.docuview_updown > dl > dd:nth-child(4)").firstElementChild.innerText;
if(current_title.indexOf(up_title) !=-1){
document.querySelector("#conView > div > div > div.docuArea02 > div.docuview_updown > dl > dd:nth-child(2)").firstElementChild.setAttribute("style","color:red");
}else if(current_title.indexOf(down_title) !=-1){
document.querySelector("#conView > div > div > div.docuArea02 > div.docuview_updown > dl > dd:nth-child(4)").firstElementChild.setAttribute("style","color:red")
}
}
}
}
}
return;
}
function view_comment_list(){
var link="";
let target_comment = null;
target_comment = document.querySelectorAll(".name");
for (const nmt of target_comment) {
var befor_text ="";
befor_text = nmt.parentElement.parentElement.children[1].innerText;
for (const undi of blockUserLists) {
if(nmt.innerHTML.toString().indexOf(undi)!=-1||check_enc_id(decodeURIComponent(nmt.firstElementChild.getAttribute('onclick').split("','")[0].split("('")[1]))){
//console.log("=="+nmt.innerHTML.toString().indexOf(undi)!=-1);
//console.log("=="+check_enc_id(decodeURIComponent(nmt.firstElementChild.getAttribute('onclick').split("','")[0].split("('")[1])));
nmt.parentElement.parentElement.children[1].innerHTML = "차단된사용자의 글입니다.<details><summary>원글보기</summary><span>"+befor_text+"</span></details>";
}
}
}
return;
}
window.Object["fn_save"] = function save_localstoreg(cid){
let list = [];
if(localStorage.getItem('enc_id')==null?true:false){
list.push(decodeURIComponent(cid));
}else{
var temp = JSON.parse(localStorage.getItem('enc_id'));
//개선필요
if(!check_enc_id(cid)){
temp.push(decodeURIComponent(cid));
}
list= temp;
}
localStorage.setItem('enc_id', JSON.stringify(list));
setGM(list);
alert("차단아이디 등록완료");
}
window.Object["fn_delete"] = function delete_localstoreg(cid){
let list = [];
var temp = JSON.parse(localStorage.getItem('enc_id'));
if(temp.length == 0){
alert("차단한 사용자가없습니다.");
return;
}
const idx = temp.indexOf(decodeURIComponent(cid));
if(idx > -1){
temp.splice(idx,1);
}
list = temp;
localStorage.setItem('enc_id', JSON.stringify(list));
setGM(list);
alert("차단아이디 삭제완료");
}
async function setGM(list){
await GM.setValue('enc_id', JSON.parse(JSON.stringify(list))).then((value) =>{
//console.log(value);
document.location.reload();
});
}
async function getGM(){
var temp = await GM.getValue('enc_id');
return temp;
}
function setlocalstoreg(blockUserLists){
let list = [];
let target = null;
let listObject = getGM();
listObject.then((value) =>{
if(value != undefined){
localStorage.setItem('enc_id',JSON.stringify(value));
if(document.querySelectorAll(".author02").length==0){
target =document.querySelectorAll("td.author");
}else{
target = document.querySelectorAll("td.author02");
}
for (const nmt of target) {
for (const undi of blockUserLists) {
if(nmt.innerHTML.toString().indexOf(undi)!=-1){
if(localStorage.getItem('enc_id')==null?true:false){
list.push(nmt.firstElementChild.getAttribute('onclick').split("')")[0].split("('")[1]);
}else{
var temp = JSON.parse(localStorage.getItem('enc_id'));
//개선필요
if(!check_enc_id(nmt.firstElementChild.getAttribute('onclick').split("')")[0].split("('")[1])){
temp.push(nmt.firstElementChild.getAttribute('onclick').split("')")[0].split("('")[1]);
}
list= temp;
}
}
}
}
if(list.length !=0){
localStorage.setItem('enc_id', JSON.stringify(list));
}
waitForKeyElements('#boardlist', view_board_list); //게시물 블럭
waitForKeyElements('#cmt_list', view_comment_list);// 코맨트리스트
}else{
localStorage.setItem('enc_id', []);
}
});
}
function check_enc_id(enc_id){
var ls = JSON.parse(localStorage.getItem('enc_id'));
return ls.some(function(arrayValue){
return decodeURIComponent(enc_id) === arrayValue;
});
}
function menu_add(cid){
}
function waitForKeyElements(selectorTxt, /* Required: The jQuery selector string that specifies the desired element(s). */
actionFunction, /* Required: The code to run when elements are found. It is passed a jNode to the matched element. */
bWaitOnce, /* Optional: If false, will continue to scan for new elements even after the first match is found. */
iframeSelector /* Optional: If set, identifies the iframe to search. */
) {
var targetNodes,
btargetsFound;
if (typeof iframeSelector == 'undefined')
targetNodes = $(selectorTxt);
else
targetNodes = $(iframeSelector).contents().find(selectorTxt);
if (targetNodes && targetNodes.length > 0) {
btargetsFound = true;
/*--- Found target node(s). Go through each and act if they
are new.
*/
targetNodes.each(function () {
var jThis = $(this);
var alreadyFound = jThis.data('alreadyFound') || false;
if (!alreadyFound) {
//--- Call the payload function.
var cancelFound = actionFunction(jThis);
if (cancelFound)
btargetsFound = false;
else
jThis.data('alreadyFound', true);
}
});
}
else {
btargetsFound = false;
} //--- Get the timer-control variable for this selector.
var controlObj = waitForKeyElements.controlObj || {
};
var controlKey = selectorTxt.replace(/[^\w]/g, '_');
var timeControl = controlObj[controlKey];
//--- Now set or clear the timer as appropriate.
if (btargetsFound && bWaitOnce && timeControl) {
//--- The only condition where we need to clear the timer.
clearInterval(timeControl);
delete controlObj[controlKey]
}
else {
//--- Set a timer, if needed.
if (!timeControl) {
timeControl = setInterval(function () {
waitForKeyElements(selectorTxt, actionFunction, bWaitOnce, iframeSelector
);
}, 300
);
controlObj[controlKey] = timeControl;
}
}
waitForKeyElements.controlObj = controlObj;
}