mirror of
https://github.com/anatolykopyl/vk-mute.git
synced 2026-03-26 12:55:13 +00:00
Add eslint
This commit is contained in:
156
src/dom/controls.js
vendored
156
src/dom/controls.js
vendored
@@ -1,5 +1,5 @@
|
||||
import {getChatBody} from "../utils/getChatBody";
|
||||
import muteSvg from "./mute.svg";
|
||||
import { getChatBody } from '../utils/getChatBody'
|
||||
import muteSvg from './mute.svg'
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -7,23 +7,23 @@ import muteSvg from "./mute.svg";
|
||||
* @return {HTMLSpanElement}
|
||||
*/
|
||||
function muteBtnHTML(id) {
|
||||
const element = document.createElement('span');
|
||||
element.setAttribute('class', 'im-mess--mute');
|
||||
element.setAttribute('id', `mute${id}`);
|
||||
element.setAttribute('label', 'Заглушить');
|
||||
element.innerHTML = muteSvg + '<div class="mute_tooltip tt_w tt_black tt_down"><div class="tt_text">Заглушить</div></div>';
|
||||
return element;
|
||||
const element = document.createElement('span')
|
||||
element.setAttribute('class', 'im-mess--mute')
|
||||
element.setAttribute('id', `mute${id}`)
|
||||
element.setAttribute('label', 'Заглушить')
|
||||
element.innerHTML = `${muteSvg}<div class="mute_tooltip tt_w tt_black tt_down"><div class="tt_text">Заглушить</div></div>`
|
||||
return element
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param target {HTMLElenemt}
|
||||
*/
|
||||
export function tryToAddControls(target) {
|
||||
if (target.className === 'im-mess--check fl_l') {
|
||||
const message = target.parentElement;
|
||||
addControlButton(message);
|
||||
}
|
||||
if (target.className === 'im-mess--check fl_l') {
|
||||
const message = target.parentElement
|
||||
addControlButton(message)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,10 +33,10 @@ export function tryToAddControls(target) {
|
||||
* @return {HTMLElement}
|
||||
*/
|
||||
function addMuteButton(actionArea, senderId) {
|
||||
const muteButton = muteBtnHTML(senderId);
|
||||
actionArea.appendChild(muteButton);
|
||||
muteButton.style.visibility = "hidden";
|
||||
return muteButton;
|
||||
const muteButton = muteBtnHTML(senderId)
|
||||
actionArea.appendChild(muteButton)
|
||||
muteButton.style.visibility = 'hidden'
|
||||
return muteButton
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -44,13 +44,13 @@ function addMuteButton(actionArea, senderId) {
|
||||
* @param actionsArea {HTMLElement}
|
||||
*/
|
||||
function addActionAreaEvents(actionsArea) {
|
||||
actionsArea.parentElement.addEventListener("mouseenter", function (event) {
|
||||
event.target.getElementsByClassName("im-mess--mute")[0].style.visibility = "visible";
|
||||
});
|
||||
actionsArea.parentElement.addEventListener('mouseenter', (event) => {
|
||||
event.target.getElementsByClassName('im-mess--mute')[0].style.visibility = 'visible'
|
||||
})
|
||||
|
||||
actionsArea.parentElement.addEventListener("mouseleave", function (event) {
|
||||
event.target.getElementsByClassName("im-mess--mute")[0].style.visibility = "hidden";
|
||||
});
|
||||
actionsArea.parentElement.addEventListener('mouseleave', (event) => {
|
||||
event.target.getElementsByClassName('im-mess--mute')[0].style.visibility = 'hidden'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,47 +58,44 @@ function addActionAreaEvents(actionsArea) {
|
||||
* @this {HTMLElement}
|
||||
*/
|
||||
function setIdToHideHandle() {
|
||||
const clickedId = this.id.substring(4);
|
||||
let clickedName = this.parentElement.parentElement.parentElement.parentElement;
|
||||
clickedName = clickedName.children[0].children[0].children[0].innerText;
|
||||
const clickedId = this.id.substring(4)
|
||||
let clickedName = this.parentElement.parentElement.parentElement.parentElement
|
||||
clickedName = clickedName.children[0].children[0].children[0].textContent
|
||||
|
||||
chrome.storage.sync.get('idsToHide', function(data) {
|
||||
let idsToHide = data.idsToHide || [];
|
||||
if (idsToHide.filter(user => user.id == clickedId).length === 0) {
|
||||
idsToHide.push({
|
||||
id: clickedId,
|
||||
name: clickedName
|
||||
});
|
||||
chrome.storage.sync.set({idsToHide: idsToHide}, function () {
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
if (data.isExtensionOn) {
|
||||
hideExistingMessages();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
chrome.storage.sync.get('idsToHide', (data) => {
|
||||
const idsToHide = data.idsToHide || []
|
||||
if (idsToHide.filter(user => user.id === clickedId).length === 0) {
|
||||
idsToHide.push({
|
||||
id: clickedId,
|
||||
name: clickedName,
|
||||
})
|
||||
chrome.storage.sync.set({ idsToHide }, () => {
|
||||
chrome.storage.sync.get('isExtensionOn', (data) => {
|
||||
if (data.isExtensionOn)
|
||||
hideExistingMessages()
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export function hideExistingMessages() {
|
||||
chrome.storage.sync.get('idsToHide', function(data) {
|
||||
const chatBody = getChatBody();
|
||||
for (let item of chatBody.children) {
|
||||
if (data.idsToHide.filter(user => user.id == item.dataset.peer).length > 0) {
|
||||
item.style.display = "none";
|
||||
}
|
||||
}
|
||||
})
|
||||
chrome.storage.sync.get('idsToHide', (data) => {
|
||||
const chatBody = getChatBody()
|
||||
for (const item of chatBody.children) {
|
||||
if (data.idsToHide.filter(user => user.id === item.dataset.peer).length > 0)
|
||||
item.style.display = 'none'
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// Try to add controls until successful. Needed for page refresh.
|
||||
export function createTryToInitInterval() {
|
||||
const controlsInterval = setInterval(function () {
|
||||
if(!tryToInitControls(controlsInterval)){
|
||||
clearInterval(controlsInterval);
|
||||
}
|
||||
}, 200)
|
||||
return controlsInterval;
|
||||
const controlsInterval = setInterval(() => {
|
||||
if (!tryToInitControls(controlsInterval))
|
||||
clearInterval(controlsInterval)
|
||||
}, 200)
|
||||
return controlsInterval
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,32 +103,33 @@ export function createTryToInitInterval() {
|
||||
* @param message {HTMLElement}
|
||||
*/
|
||||
function addControlButton(message) {
|
||||
// Check if message is not an outgoing one
|
||||
if (!message.classList.contains('im-mess_out')) {
|
||||
const actionsArea = message.getElementsByClassName("im-mess--actions")[0];
|
||||
if (actionsArea && actionsArea.lastChild.className !== "im-mess--mute") {
|
||||
const senderId = message.parentElement.parentElement.parentElement["dataset"].peer;
|
||||
const muteBtn = addMuteButton(actionsArea, senderId);
|
||||
addActionAreaEvents(actionsArea);
|
||||
muteBtn.addEventListener("click", setIdToHideHandle);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
// Check if message is not an outgoing one
|
||||
if (!message.classList.contains('im-mess_out')) {
|
||||
const actionsArea = message.getElementsByClassName('im-mess--actions')[0]
|
||||
if (actionsArea && actionsArea.lastChild.className !== 'im-mess--mute') {
|
||||
const senderId = message.parentElement.parentElement.parentElement.dataset.peer
|
||||
const muteBtn = addMuteButton(actionsArea, senderId)
|
||||
addActionAreaEvents(actionsArea)
|
||||
muteBtn.addEventListener('click', setIdToHideHandle)
|
||||
return true
|
||||
}
|
||||
else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function tryToInitControls() {
|
||||
let status = true;
|
||||
const chatBody = getChatBody();
|
||||
if(!chatBody) return false;
|
||||
for (let item of chatBody.children) {
|
||||
if (item.className.includes('im-mess-stack _im_mess_stack')) {
|
||||
let messages = item.children[1].children[1].getElementsByClassName('im-mess _im_mess');
|
||||
for (let message of messages) {
|
||||
status = addControlButton(message);
|
||||
}
|
||||
}
|
||||
let status = true
|
||||
const chatBody = getChatBody()
|
||||
if (!chatBody)
|
||||
return false
|
||||
for (const item of chatBody.children) {
|
||||
if (item.className.includes('im-mess-stack _im_mess_stack')) {
|
||||
const messages = item.children[1].children[1].getElementsByClassName('im-mess _im_mess')
|
||||
for (const message of messages)
|
||||
status = addControlButton(message)
|
||||
}
|
||||
return status;
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user