`;
// #serviceLnb 하위에 HTML 삽입
const serviceLnbElement = document.getElementById('sidebar');
if (serviceLnbElement) {
serviceLnbElement.insertAdjacentHTML('beforeend', newHtml);
}
try {
// 응답에서 필요한 정보 추출
const jsonData = response;
// 데이터 배열을 순회하면서 각각의 객체에서 broad_info를 확인합니다.
jsonData.data.forEach(item => {
// broad_info가 비어있는지 확인합니다.
if (item.broad_info.length === 0) { //비방
//console.log(`broad_info is empty for user ${item.user_nick}`);
} else { //방송중
// broad_info가 비어있지 않은 경우, 여러가지 작업을 수행할 수 있습니다.
//console.log(`broad_info is not empty for user ${item.user_nick}`);
// users-section에 동적으로 user 요소 추가
let channel = item.broad_info[0];
const usersSection = document.querySelector('.users-section.follow');
const userElement = createUserElement(channel);
usersSection.appendChild(userElement);
}
});
document.querySelector('.users-section.follow').classList.add('loaded');
} catch (error) {
console.error('Error parsing JSON:', error);
}
}
function insertMyplusChannels(){
// 특정 HTML 삽입
const newHtml = `
MY+ 추천 채널
추천 채널이 없습니다
`;
// #serviceLnb 하위에 HTML 삽입
const serviceLnbElement = document.getElementById('sidebar');
if (serviceLnbElement) {
serviceLnbElement.insertAdjacentHTML('beforeend', newHtml);
}
GM_xmlhttpRequest({
method: 'GET',
url: 'https://live.afreecatv.com/api/myplus/preferbjLiveVodController.php?nInitCnt=6&szRelationType=C',
headers: {
'Content-Type': 'application/json',
},
onload: function(response) {
try {
// 응답을 JSON으로 파싱
const jsonResponse = JSON.parse(response.responseText);
// 응답에서 필요한 정보 추출
const channels = jsonResponse.DATA.live_list;
if(channels.length!==0){
const noti = document.querySelector('.twitch-message-section.myplus');
noti.style.display = 'none';
}
// users-section에 동적으로 user 요소 추가
const usersSection = document.querySelector('.users-section.myplus');
channels.forEach(channel => {
if (isCategoryBlocked(channel.broad_cate_no)){
return;
}
if(isUserBlocked(channel.user_id)){
return;
}
const userElement = createUserElement(channel);
usersSection.appendChild(userElement);
});
usersSection.classList.add('loaded');
} catch (error) {
console.error('Error parsing JSON:', error);
}
},
onerror: function(error) {
console.error('Error:', error);
}
});
}
function makethumbnailtooltip(){
// HTMLCollection을 가져옴
const elements = document.getElementsByClassName('user');
const tooltipcontainer = document.getElementsByClassName('tooltip-container')[0];
// 각 요소에 대해 반복하면서 이벤트 리스너 추가
for (const element of elements) {
element.addEventListener('mouseenter', function() {
const rect = this.getBoundingClientRect();
const elementX = rect.left + 240; // 요소의 X 좌표
const elementY = rect.top; // 요소의 Y 좌표
//console.log(elementX,elementY);
// 각 툴팁에 대해 위치 설정
const imgSrc = this.getAttribute('broad_thumnail');
const broad_title = this.getAttribute('tooltip');
// 새로운 div 요소를 생성하고 스타일과 내용을 설정
tooltipcontainer.style.left = `${elementX}px`;
tooltipcontainer.style.top = `${elementY}px`;
tooltipcontainer.innerHTML = `
${broad_title}
`;
tooltipcontainer.style.display = 'block';
});
element.addEventListener('mouseleave', function() {
tooltipcontainer.style.display = 'none';
});
}
}
function showMore_myplus(n){
const userContainer = document.querySelector('.users-section.myplus');
const users = userContainer.querySelectorAll('.user');
if (users.length < n+1){
return false;
}
users.forEach((user, index) => {
if (index >= n) {
user.classList.add('show-more');
}
});
// 동적으로 버튼 생성 및 삽입
const toggleButton = document.createElement('button');
toggleButton.textContent = `더 보기 (${users.length - n})`;
toggleButton.id = 'toggleButton';
userContainer.appendChild(toggleButton);
const toggle_button = document.getElementById('toggleButton');
toggle_button.addEventListener('click', function () {
const users = userContainer.querySelectorAll('.user');
const hiddenUsers = users.length - n; // 숨겨진 요소의 개수 계산
const lastUser = users[users.length - 1];
if (lastUser.classList.contains('show-more')) {
// 더 보기를 눌렀을 때
toggleButton.textContent = `접기`;
users.forEach((user, index) => {
if (index >= n) {
user.classList.remove('show-more');
}
});
} else {
// 접기를 눌렀을 때
toggleButton.textContent = `더 보기 (${hiddenUsers})`;
users.forEach((user, index) => {
if (index >= n) {
user.classList.add('show-more');
}
});
}
});
}
function showMore_follow(n){
const userContainer = document.querySelector('.users-section.follow');
const users = userContainer.querySelectorAll('.user');
if (users.length < n+1){
return false;
}
users.forEach((user, index) => {
if (index >= n) {
user.classList.add('show-more');
}
});
const toggleButton = document.createElement('button');
toggleButton.textContent = `더 보기 (${users.length - n})`;
toggleButton.id = 'toggleButton2';
userContainer.appendChild(toggleButton);
const toggle_button = document.getElementById('toggleButton2');
toggle_button.addEventListener('click', function () {
const users = userContainer.querySelectorAll('.user');
const hiddenUsers = users.length - n; // 숨겨진 요소의 개수 계산
const lastUser = users[users.length - 1];
if (lastUser.classList.contains('show-more')) {
// 더 보기를 눌렀을 때
toggleButton.textContent = `접기`;
users.forEach((user, index) => {
if (index >= n) {
user.classList.remove('show-more');
}
});
} else {
// 접기를 눌렀을 때
toggleButton.textContent = `더 보기 (${hiddenUsers})`;
users.forEach((user, index) => {
if (index >= n) {
user.classList.add('show-more');
}
});
}
});
}
function showMore_top(n){
const userContainer = document.querySelector('.users-section.top');
const users = userContainer.querySelectorAll('.user');
if (users.length < n+1){
return false;
}
users.forEach((user, index) => {
if (index >= n) {
user.classList.add('show-more');
}
});
// 동적으로 버튼 생성 및 삽입
const toggleButton = document.createElement('button');
toggleButton.textContent = `더 보기 (${users.length - n})`;
toggleButton.id = 'toggleButton3';
userContainer.appendChild(toggleButton);
const toggle_button = document.getElementById('toggleButton3');
toggle_button.addEventListener('click', function () {
const users = userContainer.querySelectorAll('.user');
const hiddenUsers = users.length - n; // 숨겨진 요소의 개수 계산
const lastUser = users[users.length - 1];
if (lastUser.classList.contains('show-more')) {
// 더 보기를 눌렀을 때
toggleButton.textContent = `접기`;
users.forEach((user, index) => {
if (index >= n) {
user.classList.remove('show-more');
}
});
} else {
// 접기를 눌렀을 때
toggleButton.textContent = `더 보기 (${hiddenUsers})`;
users.forEach((user, index) => {
if (index >= n) {
user.classList.add('show-more');
}
});
}
});
}
function removeDuplicates(){
if(document.querySelectorAll('.users-section.follow > .user').length ===0){
return false;
}
// .users-section.follow > .user 모든 요소 반복
document.querySelectorAll('.users-section.follow > .user').forEach(followUser => {
const followUserId = followUser.getAttribute('user_id');
// .users-section.myplus > .user 모든 요소 반복
document.querySelectorAll('.users-section.myplus > .user').forEach(myplusUser => {
const myplusUserId = myplusUser.getAttribute('user_id');
// user_id 일치 여부 확인
if (followUserId === myplusUserId) {
// 일치할 경우 .user 요소 제거
myplusUser.remove();
}
});
});
}
function blockButtonOnMutation(){
var target1 = document.querySelector('#broadlist_area > ul');
var target2 = document.querySelector('#btnRefresh');
var observer1 = new MutationObserver(function(mutations) {
//console.log('changed');
target2.classList.add('loaded');
waitForElement('.users-section.top.loaded.nologinuser', function (elementSelector, element) {
appendBlockbutton();
});
waitForElement('.users-section.myplus.loaded', function (elementSelector, element) {
waitForElement('.users-section.top.loaded', function (elementSelector, element) {
appendBlockbutton();
});
});
});
observer1.observe(target1, {
attributes: true,
childList: true
});
}
function appendBlockbutton(){
var nicknames = document.querySelectorAll('.cBox-info > .details > a.nick');
nicknames.forEach(function(nickname) {
if (!nickname.classList.contains("checked")) {
nickname.classList.add("checked");
var user_id = nickname.getAttribute('user_id');
if (isUserBlocked(user_id)) {
//nickname.parentNode.parentNode.parentNode.style.display = 'none';
nickname.parentNode.parentNode.parentNode.remove();
return;
}
var user_name = nickname.querySelector('span').textContent;
nickname.addEventListener('click', function() {
setTimeout(() => {
const isDarkMode = document.querySelector('html').getAttribute('dark') === 'true';
var buttonElement = document.createElement('button');
buttonElement.type = 'button';
if(isDarkMode){
buttonElement.className = 'block-icon-svg-white';
} else {
buttonElement.className = 'block-icon-svg';
}
buttonElement.setAttribute('tip', '채널 차단');
var spanElement = document.createElement('span');
spanElement.textContent = '채널 차단';
buttonElement.appendChild(spanElement);
buttonElement.onclick = function() {
//nickname.parentNode.parentNode.parentNode.style.display = 'none';
nickname.parentNode.parentNode.parentNode.remove();
blockUser(user_name,user_id);
};
// contextMenu 내에 버튼 요소 추가
var contextMenu = document.querySelector('#contextMenu');
if (contextMenu) {
contextMenu.appendChild(buttonElement);
} else {
console.error('#contextMenu를 찾을 수 없습니다.');
}
var cate_no = nickname.parentNode.parentNode.querySelector('div.tag_wrap.checked').getAttribute('cate_no') || null;
if(cate_no){
var buttonElement2 = document.createElement('button');
buttonElement2.type = 'button';
if(isDarkMode){
buttonElement2.className = 'block-icon-svg-white';
} else {
buttonElement2.className = 'block-icon-svg';
}
buttonElement2.setAttribute('tip', '카테고리 차단');
var spanElement2 = document.createElement('span');
spanElement2.textContent = '카테고리 차단';
buttonElement2.appendChild(spanElement2);
buttonElement2.onclick = function() {
//nickname.parentNode.parentNode.parentNode.remove();
blockCategory(getCategoryName(cate_no),cate_no);
};
// contextMenu 내에 버튼 요소 추가
if (contextMenu) {
contextMenu.appendChild(buttonElement2);
} else {
console.error('#contextMenu를 찾을 수 없습니다.');
}
}
}, 100);
});
appendCategory(nickname);
}
});
}
function appendCategory(nickname){
var broadlist_area = nickname.parentNode.parentNode.parentNode.parentNode.parentNode.getAttribute('id');
var tagContainer = nickname.parentNode.parentNode.querySelector('.tag_wrap');
var user_id_list = nickname.getAttribute('user_id');
const channels = aBroadList.broad;
for (const channel of channels) {
const cate_no = channel.broad_cate_no;
const cate_name = getCategoryName(channel.broad_cate_no);
const user_id_js = channel.user_id;
if (user_id_list === user_id_js){
if (isCategoryBlocked(cate_no)) {
nickname.parentNode.parentNode.parentNode.remove();
}
if(!tagContainer.classList.contains("checked")){
tagContainer.classList.add("checked");
tagContainer.setAttribute("cate_no",`${cate_no}`)
var newATag = document.createElement('a');
newATag.textContent = cate_name;
newATag.setAttribute("href",`javascript:`)
newATag.addEventListener('click', function() {
var cate_no_org = `${cate_no}`;
var tag_wrap_checked = document.querySelectorAll('.cBox-info > .tag_wrap.checked');
if(!newATag.classList.contains("clicked")){
newATag.classList.add("clicked");
tag_wrap_checked.forEach(function(element) {
var cate_no_dst = element.getAttribute('cate_no');
if (cate_no_org === cate_no_dst) {
element.querySelector('a').classList.add("clicked");
element.querySelector('a').textContent=cate_name+" ⨉";
return;
}
element.parentNode.parentNode.style.display = 'none';
});
} else {
newATag.classList.remove("clicked");
tag_wrap_checked.forEach(function(element) {
var cate_no_dst = element.getAttribute('cate_no');
if (cate_no_org === cate_no_dst) {
element.querySelector('a').classList.remove("clicked");
element.querySelector('a').textContent=cate_name;
return;
}
element.parentNode.parentNode.style.display = 'block';
});
}
});
tagContainer.insertBefore(newATag, tagContainer.firstChild);
return;
}
}
}
if(broadlist_area === "prefer_broadlist_area"){
waitForElement('div.users-section.myplus.loaded', function (elementSelector, element) {
var users = element.querySelectorAll('.user');
var cate_no;
let checker = 0;
users.forEach(function(user) {
var user_id_myplus = user.getAttribute('user_id');
if (user_id_list === user_id_myplus){
//nickname.parentNode.parentNode.parentNode.remove();
//console.log(user_id_myplus);
cate_no = user.getAttribute('broad_cate_no');
checker = 1;
return;
}
});
if(!checker){
nickname.parentNode.parentNode.parentNode.remove();
} else {
if(!tagContainer.classList.contains("checked")){
tagContainer.classList.add("checked");
tagContainer.setAttribute("cate_no",`${cate_no}`)
var newATag = document.createElement('a');
newATag.textContent = getCategoryName(cate_no);
newATag.setAttribute("href",`javascript:`)
newATag.addEventListener('click', function() {
var cate_no_org = `${cate_no}`;
var tag_wrap_checked = document.querySelectorAll('.cBox-info > .tag_wrap.checked');
if(!newATag.classList.contains("clicked")){
newATag.classList.add("clicked");
tag_wrap_checked.forEach(function(element) {
var cate_no_dst = element.getAttribute('cate_no');
if (cate_no_org === cate_no_dst) {
element.querySelector('a').classList.add("clicked");
element.querySelector('a').textContent=getCategoryName(cate_no)+" ⨉";
return;
}
element.parentNode.parentNode.style.display = 'none';
});
} else {
newATag.classList.remove("clicked");
tag_wrap_checked.forEach(function(element) {
var cate_no_dst = element.getAttribute('cate_no');
if (cate_no_org === cate_no_dst) {
element.querySelector('a').classList.remove("clicked");
element.querySelector('a').textContent=getCategoryName(cate_no);
return;
}
element.parentNode.parentNode.style.display = 'block';
});
}
});
tagContainer.insertBefore(newATag, tagContainer.firstChild);
return;
}
}
});
}
}
function setCategoryOnAjaxResponse(){
var intervalTime = 1000;
// setInterval을 사용하여 주기적으로 실행
var intervalId = setInterval(function() {
// $.ajax가 정의되었는지 확인
if ($.ajax) {
// clearInterval을 사용하여 간격 검사 중지
clearInterval(intervalId);
// 여기에 $.ajax가 설정된 후에 실행할 스크립트를 작성
//console.log('$.ajax is defined:', $.ajax);
// 원본 jQuery.ajax 함수 저장
var originalAjax = $.ajax;
// 새로운 jQuery.ajax 함수 정의
$.ajax = function(settings) {
var url = settings.url;
var data = settings.data;
// 원본 jQuery.ajax 함수 호출
return originalAjax.apply(this, [settings]).done(function(responseData, textStatus, jqXHR) {
if(url==="https://live.afreecatv.com/api/main_broad_list_api.php"){
// tag_wrap_checked가 비어있지 않고, 그 안에 클래스가 'clicked'인 a 태그가 하나라도 있다면 클릭
var isClicked = 0;
var tag_wrap_checked = document.querySelectorAll('.cBox-info > .tag_wrap.checked');
if (tag_wrap_checked.length > 0) {
for (var i = 0; i < tag_wrap_checked.length; i++) {
var aTags = tag_wrap_checked[i].querySelectorAll('a.clicked');
if (aTags.length > 0) {
// 여러 a 태그 중 첫 번째 것을 클릭
aTags[0].click();
isClicked = 1;
break; // 이미 클릭한 경우 더 이상 확인할 필요가 없으므로 반복문 종료
}
}
}
var nicknames = document.querySelectorAll('.cBox-info > .details > a');
nicknames.forEach(function(nickname) {
var tagContainer = nickname.parentNode.parentNode.querySelector('.tag_wrap');
var user_id_org = nickname.getAttribute('user_id');
const elements = responseData.broad;
for (const element of elements) {
const user_id_dst = element.user_id;
if (user_id_org === user_id_dst) {
const cate_no = element.broad_cate_no;
const cate_name = getCategoryName(cate_no);
if (isCategoryBlocked(cate_no)){
nickname.parentNode.parentNode.parentNode.remove();
return;
}
if (!tagContainer.classList.contains("checked")) {
tagContainer.classList.add("checked");
tagContainer.setAttribute("cate_no", `${cate_no}`);
var newATag = document.createElement('a');
newATag.textContent = cate_name;
newATag.setAttribute("href", `javascript:`);
newATag.addEventListener('click', function() {
var cate_no_org = `${cate_no}`;
var tag_wrap_checked = document.querySelectorAll('.cBox-info > .tag_wrap.checked');
if (!newATag.classList.contains("clicked")) {
newATag.classList.add("clicked");
tag_wrap_checked.forEach(function(element) {
var cate_no_dst = element.getAttribute('cate_no');
if (cate_no_org === cate_no_dst) {
element.querySelector('a').classList.add("clicked");
element.querySelector('a').textContent = `${cate_name} ⨉`;
return;
}
element.parentNode.parentNode.style.display = 'none';
});
} else {
newATag.classList.remove("clicked");
tag_wrap_checked.forEach(function(element) {
var cate_no_dst = element.getAttribute('cate_no');
if (cate_no_org === cate_no_dst) {
element.querySelector('a').classList.remove("clicked");
element.querySelector('a').textContent = cate_name;
return;
}
element.parentNode.parentNode.style.display = 'block';
});
}
});
tagContainer.insertBefore(newATag, tagContainer.firstChild);
}
break; // user_id 일치하는 첫 번째 요소만 처리하고 반복문 종료
}
}
});
if(isClicked){
aTags[0].click();
}
}
}).fail(function(jqXHR, textStatus, errorThrown) {
// 실패한 응답 로깅
console.log('JQuery AJAX Error:', textStatus, errorThrown);
});
};
}
}, intervalTime);
}
function refreshPageOnDarkModeToggle(){
// #modeSetArea 요소 찾기
var modecheck = document.querySelector("LABEL.modecheck");
modecheck.addEventListener("click", function (event) {
window.location.href=window.location.href;
});
}
// HTML 요소를 가져옵니다.
const htmlElement = document.querySelector('html');
// dark 속성의 값을 확인합니다.
const isDarkMode = htmlElement.getAttribute('dark') === 'true';
if(isDarkMode){
GM_addStyle(css_Darkmode);
} else {
GM_addStyle(css_Whitemode);
}
// .left_navbar를 찾거나 생성
var leftNavbar = document.querySelector('.left_navbar');
if (!leftNavbar) {
leftNavbar = document.createElement('div');
leftNavbar.className = 'left_navbar';
// 페이지의 적절한 위치에 추가
var targetElement = document.body; // 원하는 위치에 따라 수정
targetElement.insertBefore(leftNavbar, targetElement.firstChild);
}
var buttonData = [
{ href: 'https://www.afreecatv.com/?hash=all', text: '전체' },
{ href: 'https://www.afreecatv.com/?hash=game', text: '게임' },
{ href: 'https://www.afreecatv.com/?hash=bora', text: '보.라' },
{ href: 'https://www.afreecatv.com/?hash=sports', text: '스포츠' }
];
buttonData.reverse().forEach(function (data) {
var newButton = document.createElement('a');
newButton.href = data.href;
newButton.innerHTML = ``;
leftNavbar.appendChild(newButton);
});
var tooltipContainer = document.createElement('div');
tooltipContainer.classList.add('tooltip-container');
var listsection = document.querySelector('#list-section');
listsection.appendChild(tooltipContainer);
waitForElement('.left_nav_button', function (elementSelector, element) {
// Get the current page URL
const currentPage = window.location.href;
// Get all navigation links
const navLinks = document.querySelectorAll('.left_nav_button');
// Loop through each link and check if it matches the current page
navLinks.forEach(link => {
var parentLink = link.parentElement;
if (parentLink.href === currentPage) {
link.classList.add('active'); // Add the 'active' class if it matches
}
});
});
GM_xmlhttpRequest({
method: 'GET',
url: 'https://myapi.afreecatv.com/api/favorite',
headers: {
'Content-Type': 'application/json',
},
onload: function(response) {
response = response.responseText;
response = JSON.parse(response);
// if 문으로 code 값 확인
if (response.code === -10000) {
//console.log('로그인 상태가 아닙니다.');
insertTopChannels();
waitForElement('.users-section.top.loaded', function (elementSelector, element) {
makethumbnailtooltip();
document.querySelector('.users-section.top.loaded').classList.add('nologinuser');
});
return false;
}
let hasNonEmptyBroadInfo = false;
// "data" 배열의 각 요소를 확인하는 반복문
for (const item of response.data) {
// "broad_info"가 비어 있지 않은 경우
if (item.broad_info.length > 0) {
hasNonEmptyBroadInfo = true;
// 여기에 해당 요소에 대한 추가 동작을 수행할 수 있습니다.
break; // 만약 하나라도 비어 있지 않은 경우에 중단하려면 이 부분을 사용합니다.
}
}
if (response.data.length === 0) {
//console.log('즐찾이 없습니다.');
if(myplus_position){
insertMyplusChannels();
insertTopChannels();
} else {
insertTopChannels();
insertMyplusChannels();
}
waitForElement('.users-section.myplus.loaded', function (elementSelector, element) {
waitForElement('.users-section.top.loaded', function (elementSelector, element) {
makethumbnailtooltip();
});
});
waitForElement('.users-section.myplus.loaded', function (elementSelector, element) {
if(!myplus_order){
desc_order('.users-section.myplus');
}
showMore_myplus(display_myplus);
});
waitForElement('.users-section.top.loaded', function (elementSelector, element) {
showMore_top(display_top);
});
} else if (hasNonEmptyBroadInfo) { // 즐찾 중 방송중인 스트리머가 한 명 이상
insertFavoriteChannels(response);
if(myplus_position){
insertMyplusChannels();
insertTopChannels();
} else {
insertTopChannels();
insertMyplusChannels();
}
waitForElement('.users-section.follow.loaded', function (elementSelector, element) {
waitForElement('.users-section.myplus.loaded', function (elementSelector, element) {
removeDuplicates();
waitForElement('.users-section.top.loaded', function (elementSelector, element) {
makethumbnailtooltip();
});
});
});
waitForElement('.users-section.follow.loaded', function (elementSelector, element) {
desc_order('.users-section.follow');
showMore_follow(display_follow);
});
waitForElement('.users-section.myplus.loaded', function (elementSelector, element) {
if(!myplus_order){
desc_order('.users-section.myplus');
}
showMore_myplus(display_myplus);
});
waitForElement('.users-section.top.loaded', function (elementSelector, element) {
showMore_top(display_top);
});
} else { // 즐찾은 있지만 전부 비방
const newHtml = `