Возвращение сообщений без перезагрузки

This commit is contained in:
2021-06-27 12:40:25 +03:00
parent 4756ce8894
commit cfd6691eba
7 changed files with 945 additions and 45 deletions

81
extension/dist/dom.js vendored

File diff suppressed because one or more lines are too long

View File

@@ -6,7 +6,7 @@
"128": "assets/icons/icon128.png",
"48": "assets/icons/icon48.png"
},
"version": "1.0",
"version": "1.2",
"description": "Позволяет заглушить нежелаемых собеседников",
"permissions": [
"activeTab",

859
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -24,6 +24,7 @@
"css-loader": "^3.5.2",
"html-webpack-plugin": "^4.2.0",
"style-loader": "^1.1.4",
"webpack": "^4.42.1"
"webpack": "^4.42.1",
"webpack-cli": "^4.7.2"
}
}

6
src/dom/controls.js vendored
View File

@@ -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();
}
});
});
}
});

View File

@@ -1,5 +1,5 @@
import {getChatBody} from "../utils/getChatBody";
import {tryToAddControls} from "./controls";
import {tryToAddControls, hideExistingMessages} from "./controls";
export function addNewMessageEventListener() {
const chatBody = getChatBody();
@@ -22,3 +22,37 @@ 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";
}
}
}
}
});
}
});
}

View File

@@ -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();
}
})