mirror of
https://github.com/anatolykopyl/vk-mute.git
synced 2026-03-26 12:55:13 +00:00
Возвращение сообщений без перезагрузки
This commit is contained in:
6
src/dom/controls.js
vendored
6
src/dom/controls.js
vendored
@@ -66,7 +66,11 @@ function setIdToHideHandle() {
|
||||
name: clickedName
|
||||
});
|
||||
chrome.storage.sync.set({idsToHide: idsToHide}, function () {
|
||||
hideExistingMessages();
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
if (data.isExtensionOn) {
|
||||
hideExistingMessages();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {getChatBody} from "../utils/getChatBody";
|
||||
import {tryToAddControls} from "./controls";
|
||||
import {tryToAddControls, hideExistingMessages} from "./controls";
|
||||
|
||||
export function addNewMessageEventListener() {
|
||||
const chatBody = getChatBody();
|
||||
@@ -21,4 +21,38 @@ function newMessageHandler(message) {
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export function returnMessagesEventListener() {
|
||||
chrome.storage.onChanged.addListener(function(changes) {
|
||||
const isExtensionOn = changes.isExtensionOn;
|
||||
const idsToHide = changes.idsToHide;
|
||||
const chatBody = getChatBody();
|
||||
if (isExtensionOn) {
|
||||
if (isExtensionOn.newValue === false) {
|
||||
for (let item of chatBody.children) {
|
||||
item.style.display = "block";
|
||||
}
|
||||
} else {
|
||||
hideExistingMessages();
|
||||
}
|
||||
}
|
||||
if (idsToHide) {
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
if (data.isExtensionOn) {
|
||||
if (idsToHide.newValue.length < idsToHide.oldValue.length) {
|
||||
// for (let item of chatBody.children) {
|
||||
// item.style.display = "block";
|
||||
// }
|
||||
// hideExistingMessages();
|
||||
for (let item of chatBody.children) {
|
||||
if (idsToHide.newValue.filter(user => user.id == item.dataset.peer).length === 0) {
|
||||
item.style.display = "block";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
import './dom.css'
|
||||
import {createTryToInitInterval, hideExistingMessages, tryToInitControls} from "./controls";
|
||||
import {UrlController} from "../utils/Url";
|
||||
import {addNewMessageEventListener} from "./hide_element";
|
||||
import {addNewMessageEventListener, returnMessagesEventListener} from "./hide_element";
|
||||
|
||||
function init() {
|
||||
const url = new UrlController();
|
||||
@@ -9,6 +9,7 @@ function init() {
|
||||
if (tryToInitControls()) {
|
||||
createTryToInitInterval();
|
||||
addNewMessageEventListener();
|
||||
returnMessagesEventListener();
|
||||
hideExistingMessages();
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user