mirror of
https://github.com/anatolykopyl/vk-mute.git
synced 2026-03-26 21:05:16 +00:00
Compare commits
26 Commits
afa274b651
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
544ef14295 | ||
|
|
218fc0610e | ||
|
|
02a46d4908 | ||
|
|
07bcb773f5 | ||
| b926f0edbf | |||
| 91f1833534 | |||
|
|
4089f640ea | ||
|
|
85596a95a6 | ||
|
|
4cebd66a85 | ||
|
|
bc49282b62 | ||
|
|
78c6b02214 | ||
|
|
97a8920057 | ||
|
|
a22c3485fa | ||
|
|
fd8c01e41b | ||
|
|
aad1365953 | ||
|
|
de578fd210 | ||
|
|
59ca6bb360 | ||
|
|
f7474d863b | ||
|
|
9a2381690e | ||
|
|
ecc265430b | ||
|
|
a8290e41f3 | ||
|
|
343ebe14ea | ||
|
|
31dcbae1da | ||
|
|
2330704243 | ||
|
|
56bf77001c | ||
|
|
d8f653382b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -4,3 +4,4 @@
|
||||
/.idea
|
||||
/assets
|
||||
.zip
|
||||
/.vscode
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
# vk-mute
|
||||
|
||||
[](https://github.com/antfu/eslint-config)
|
||||
|
||||
Заглушить собеседника в беседе в ВК. 🔇
|
||||
|
||||
На данный момент ВКонтакте не позволяет заглушать людей в беседах. Это расширение для Chrome берется это исправить.
|
||||
|
||||
3
eslint.config.js
Normal file
3
eslint.config.js
Normal file
@@ -0,0 +1,3 @@
|
||||
const antfu = require('@antfu/eslint-config').default
|
||||
|
||||
module.exports = antfu()
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 2.2 KiB |
119
extension/dist/background.js
vendored
119
extension/dist/background.js
vendored
File diff suppressed because one or more lines are too long
1208
extension/dist/dom.js
vendored
1208
extension/dist/dom.js
vendored
File diff suppressed because one or more lines are too long
5
extension/dist/popup.html
vendored
5
extension/dist/popup.html
vendored
@@ -2,12 +2,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<script defer src="popup.js"></script></head>
|
||||
<body>
|
||||
<div class="header">
|
||||
<h3 align="center">VK Mute</h3>
|
||||
</div>
|
||||
<!--<button id="disableButton">Toggle</button>-->
|
||||
<div style="text-align: center;">
|
||||
<label class="switch">
|
||||
<input type="checkbox" id="disableCheckbox">
|
||||
@@ -19,5 +18,5 @@
|
||||
<div class="donation_btn">
|
||||
<a href="./donate.html" title="Пожертвовать" target="_blank">💸</a>
|
||||
</div>
|
||||
<script src="popup.js"></script></body>
|
||||
</body>
|
||||
</html>
|
||||
414
extension/dist/popup.js
vendored
414
extension/dist/popup.js
vendored
File diff suppressed because one or more lines are too long
@@ -6,20 +6,21 @@
|
||||
"128": "assets/icons/icon128.png",
|
||||
"48": "assets/icons/icon48.png"
|
||||
},
|
||||
"version": "1.4",
|
||||
"version": "1.5.0",
|
||||
"description": "Позволяет заглушить нежелаемых собеседников",
|
||||
"permissions": [
|
||||
"declarativeContent",
|
||||
"storage"
|
||||
],
|
||||
"background": {
|
||||
"scripts": ["dist/background.js"],
|
||||
"persistent": false
|
||||
"action": {
|
||||
"default_icon": {
|
||||
"140": "assets/icons/icon140.png",
|
||||
"128": "assets/icons/icon128.png",
|
||||
"48": "assets/icons/icon48.png"
|
||||
},
|
||||
"page_action": {
|
||||
"default_title": "VK Mute",
|
||||
"default_popup": "dist/popup.html"
|
||||
},
|
||||
"manifest_version": 2,
|
||||
"manifest_version": 3,
|
||||
"content_scripts": [
|
||||
{
|
||||
"matches": ["https://*.vk.com/*"],
|
||||
@@ -27,6 +28,9 @@
|
||||
}
|
||||
],
|
||||
"web_accessible_resources": [
|
||||
"assets/mute.png"
|
||||
{
|
||||
"resources": ["assets/mute.png"],
|
||||
"matches": ["https://*.vk.com/*"]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
13509
package-lock.json
generated
13509
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -1,30 +1,34 @@
|
||||
{
|
||||
"name": "vk-mute",
|
||||
"version": "1.0.0",
|
||||
"version": "1.5.0",
|
||||
"description": "Заглушить собеседника в беседе в ВК. 🔇",
|
||||
"main": "src/dom/main.js",
|
||||
"scripts": {
|
||||
"build": "webpack --config webpack.config.js",
|
||||
"watch": "webpack --config webpack.config.js --watch"
|
||||
"watch": "webpack --config webpack.config.js --watch",
|
||||
"lint": "eslint ."
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/anatolykopyl/vk-mute.git"
|
||||
},
|
||||
"author": "",
|
||||
"license": "ISC",
|
||||
"author": "Anatoly Kopyl <hi@kopyl.dev>",
|
||||
"license": "GPL-3.0",
|
||||
"bugs": {
|
||||
"url": "https://github.com/anatolykopyl/vk-mute/issues"
|
||||
},
|
||||
"homepage": "https://github.com/anatolykopyl/vk-mute#readme",
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "^2.4.3",
|
||||
"@babel/core": "^7.9.0",
|
||||
"@babel/preset-env": "^7.9.5",
|
||||
"babel-loader": "^8.1.0",
|
||||
"css-loader": "^3.5.2",
|
||||
"html-webpack-plugin": "^4.2.0",
|
||||
"babel-loader": "^8.3.0",
|
||||
"css-loader": "^6.7.3",
|
||||
"eslint": "^8.55.0",
|
||||
"html-webpack-plugin": "^5.5.0",
|
||||
"raw-loader": "^4.0.2",
|
||||
"style-loader": "^1.1.4",
|
||||
"webpack": "^4.42.1",
|
||||
"webpack": "^5.94.0",
|
||||
"webpack-cli": "^4.7.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
chrome.runtime.onInstalled.addListener(function () {
|
||||
chrome.storage.sync.set({ isExtensionOn: true }, function () {
|
||||
console.log('isExtensionOn: ' + true);
|
||||
});
|
||||
|
||||
chrome.declarativeContent.onPageChanged.removeRules(undefined, function () {
|
||||
chrome.declarativeContent.onPageChanged.addRules([{
|
||||
conditions: [new chrome.declarativeContent.PageStateMatcher({
|
||||
pageUrl: { hostEquals: 'vk.com' },
|
||||
})],
|
||||
actions: [new chrome.declarativeContent.ShowPageAction()]
|
||||
}]);
|
||||
});
|
||||
});
|
||||
138
src/dom/controls.js
vendored
138
src/dom/controls.js
vendored
@@ -1,24 +1,28 @@
|
||||
import { getChatBody } from '../utils/getChatBody'
|
||||
import muteSvg from './mute.svg'
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id {String}
|
||||
* @return {HTMLSpanElement}
|
||||
*/
|
||||
import {getChatBody} from "../utils/getChatBody";
|
||||
|
||||
function muteBtnHTML(id) {
|
||||
const element = document.createElement('span');
|
||||
element.setAttribute('class', 'mute_message');
|
||||
element.setAttribute('id', `mute${id}`);
|
||||
element.setAttribute('label', 'Заглушить');
|
||||
element.style.background = `url(${chrome.runtime.getURL("assets/mute.png")}) center no-repeat`;
|
||||
element.innerHTML = '<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);
|
||||
const message = target.parentElement
|
||||
addControlButton(message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,10 +33,10 @@ export function tryToAddControls(target) {
|
||||
* @return {HTMLElement}
|
||||
*/
|
||||
function addMuteButton(actionArea, senderId) {
|
||||
const muteButton = muteBtnHTML(senderId);
|
||||
actionArea.appendChild(muteButton);
|
||||
muteButton.style.display = "none";
|
||||
return muteButton;
|
||||
const muteButton = muteBtnHTML(senderId)
|
||||
actionArea.appendChild(muteButton)
|
||||
muteButton.style.visibility = 'hidden'
|
||||
return muteButton
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -40,63 +44,58 @@ function addMuteButton(actionArea, senderId) {
|
||||
* @param actionsArea {HTMLElement}
|
||||
*/
|
||||
function addActionAreaEvents(actionsArea) {
|
||||
actionsArea.parentElement.addEventListener("mouseenter", function (event) {
|
||||
event.target.getElementsByClassName("mute_message")[0].style.display = "inline-block";
|
||||
});
|
||||
actionsArea.parentElement.addEventListener('mouseenter', (event) => {
|
||||
event.target.getElementsByClassName('im-mess--mute')[0].style.visibility = 'visible'
|
||||
})
|
||||
|
||||
actionsArea.parentElement.addEventListener("mouseleave", function (event) {
|
||||
event.target.getElementsByClassName("mute_message")[0].style.display = "none";
|
||||
});
|
||||
actionsArea.parentElement.addEventListener('mouseleave', (event) => {
|
||||
event.target.getElementsByClassName('im-mess--mute')[0].style.visibility = 'hidden'
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return {function(...[]=)}
|
||||
* @this {HTMLElement}
|
||||
*/
|
||||
function setIdToHideHandle() {
|
||||
return function (event) {
|
||||
const clickedId = event.target.id.substr(4); // get id of sender from element id
|
||||
let clickedName = event.target.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) {
|
||||
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: idsToHide}, function () {
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
if (data.isExtensionOn) {
|
||||
hideExistingMessages();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
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);
|
||||
}
|
||||
const controlsInterval = setInterval(() => {
|
||||
if (!tryToInitControls(controlsInterval))
|
||||
clearInterval(controlsInterval)
|
||||
}, 200)
|
||||
return controlsInterval;
|
||||
return controlsInterval
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -106,30 +105,31 @@ export function createTryToInitInterval() {
|
||||
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 !== "mute_message") {
|
||||
const senderId = message.parentElement.parentElement.parentElement["dataset"].peer;
|
||||
const muteBtn = addMuteButton(actionsArea, senderId);
|
||||
addActionAreaEvents(actionsArea);
|
||||
muteBtn.addEventListener("click", setIdToHideHandle());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
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) {
|
||||
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')) {
|
||||
let messages = item.children[1].children[1].getElementsByClassName('im-mess _im_mess');
|
||||
for (let message of messages) {
|
||||
status = addControlButton(message);
|
||||
const messages = item.children[1].children[1].getElementsByClassName('im-mess _im_mess')
|
||||
for (const message of messages)
|
||||
status = addControlButton(message)
|
||||
}
|
||||
}
|
||||
}
|
||||
return status;
|
||||
return status
|
||||
}
|
||||
@@ -10,19 +10,24 @@
|
||||
}
|
||||
|
||||
/* Show the tooltip text when you mouse over the tooltip container */
|
||||
.mute_message:hover .mute_tooltip {
|
||||
.im-mess--mute:hover .mute_tooltip {
|
||||
display: block !important;
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.mute_message {
|
||||
.im-mess--mute {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
vertical-align: top;
|
||||
padding-top: 2px;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
background-size: 11px !important;
|
||||
opacity: .5;
|
||||
color: var(--vkui--color_icon_secondary);
|
||||
}
|
||||
|
||||
.im-mess--mute:hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.im-mess--actions {
|
||||
|
||||
@@ -1,58 +1,52 @@
|
||||
import {getChatBody} from "../utils/getChatBody";
|
||||
import {tryToAddControls, hideExistingMessages} from "./controls";
|
||||
import { getChatBody } from '../utils/getChatBody'
|
||||
import { hideExistingMessages, tryToAddControls } from './controls'
|
||||
|
||||
export function addNewMessageEventListener() {
|
||||
const chatBody = getChatBody();
|
||||
chatBody.addEventListener('DOMNodeInserted', function(event) {
|
||||
const chatBody = getChatBody()
|
||||
chatBody.addEventListener('DOMNodeInserted', (event) => {
|
||||
newMessageHandler(event.target)
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
function newMessageHandler(message) {
|
||||
tryToAddControls(message);
|
||||
tryToAddControls(message)
|
||||
if (message.className === 'im-mess-stack _im_mess_stack ') {
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
chrome.storage.sync.get('isExtensionOn', (data) => {
|
||||
if (data.isExtensionOn) {
|
||||
chrome.storage.sync.get('idsToHide', function(data) {
|
||||
if (data.idsToHide.filter(user => user.id == message.dataset.peer).length > 0) {
|
||||
message.style.display = "none";
|
||||
chrome.storage.sync.get('idsToHide', (data) => {
|
||||
if (data.idsToHide.filter(user => user.id === message.dataset.peer).length > 0)
|
||||
message.style.display = 'none'
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export function returnMessagesEventListener() {
|
||||
chrome.storage.onChanged.addListener(function(changes) {
|
||||
const isExtensionOn = changes.isExtensionOn;
|
||||
const idsToHide = changes.idsToHide;
|
||||
const chatBody = getChatBody();
|
||||
chrome.storage.onChanged.addListener((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";
|
||||
for (const item of chatBody.children)
|
||||
item.style.display = 'block'
|
||||
}
|
||||
} else {
|
||||
hideExistingMessages();
|
||||
else {
|
||||
hideExistingMessages()
|
||||
}
|
||||
}
|
||||
if (idsToHide) {
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
chrome.storage.sync.get('isExtensionOn', (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";
|
||||
for (const item of chatBody.children) {
|
||||
if (idsToHide.newValue.filter(user => user.id === item.dataset.peer).length === 0)
|
||||
item.style.display = 'block'
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
@@ -1,22 +1,21 @@
|
||||
import './dom.css'
|
||||
import {createTryToInitInterval, hideExistingMessages, tryToInitControls} from "./controls";
|
||||
import {UrlController} from "../utils/Url";
|
||||
import {addNewMessageEventListener, returnMessagesEventListener} from "./hide_element";
|
||||
import { UrlController } from '../utils/Url'
|
||||
import { createTryToInitInterval, hideExistingMessages, tryToInitControls } from './controls'
|
||||
import { addNewMessageEventListener, returnMessagesEventListener } from './hide_element'
|
||||
|
||||
function init() {
|
||||
const url = new UrlController();
|
||||
const url = new UrlController()
|
||||
url.onChange(() => {
|
||||
if (tryToInitControls()) {
|
||||
createTryToInitInterval();
|
||||
addNewMessageEventListener();
|
||||
returnMessagesEventListener();
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
if (data.isExtensionOn) {
|
||||
hideExistingMessages();
|
||||
}
|
||||
});
|
||||
createTryToInitInterval()
|
||||
addNewMessageEventListener()
|
||||
returnMessagesEventListener()
|
||||
chrome.storage.sync.get('isExtensionOn', (data) => {
|
||||
if (data.isExtensionOn)
|
||||
hideExistingMessages()
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
init();
|
||||
init()
|
||||
|
||||
9
src/dom/mute.svg
Normal file
9
src/dom/mute.svg
Normal file
@@ -0,0 +1,9 @@
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="16"
|
||||
height="16"
|
||||
fill="currentColor"
|
||||
viewBox="2 1 13 13"
|
||||
>
|
||||
<path d="M4.69 5.5 11 11.8v1.7c0 .3-.23.47-.49.5l-3.63-3.5H4a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1h.69Zm.77-2.85 2.2 2.19L10.5 2.5c.27.02.49.2.49.48v5.2l2.6 2.6a.75.75 0 0 1-1.06 1.06L4.4 3.71a.75.75 0 0 1 1.06-1.06Z"></path>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 348 B |
@@ -6,7 +6,7 @@ body {
|
||||
min-width: 160px;
|
||||
margin: 0;
|
||||
}
|
||||
/* The switch - the box around the slider */
|
||||
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
@@ -14,14 +14,12 @@ body {
|
||||
height: 34px;
|
||||
}
|
||||
|
||||
/* Hide default HTML checkbox */
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* The slider */
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
@@ -60,7 +58,6 @@ input:checked + .slider:before {
|
||||
transform: translateX(26px);
|
||||
}
|
||||
|
||||
/* Rounded sliders */
|
||||
.slider.round {
|
||||
border-radius: 34px;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
<div class="header">
|
||||
<h3 align="center">VK Mute</h3>
|
||||
</div>
|
||||
<!--<button id="disableButton">Toggle</button>-->
|
||||
<div style="text-align: center;">
|
||||
<label class="switch">
|
||||
<input type="checkbox" id="disableCheckbox">
|
||||
|
||||
@@ -1,54 +1,51 @@
|
||||
import './popup.css'
|
||||
|
||||
//let disableButton = document.getElementById('disableButton');
|
||||
let disableCheckbox = document.getElementById('disableCheckbox');
|
||||
let idsToHideElements = document.getElementsByClassName('idToHide');
|
||||
let idList = document.getElementById("id_list");
|
||||
let isExtensionOn;
|
||||
let idsToHide = [];
|
||||
const disableCheckbox = document.getElementById('disableCheckbox')
|
||||
const idsToHideElements = document.getElementsByClassName('idToHide')
|
||||
const idList = document.getElementById('id_list')
|
||||
let isExtensionOn
|
||||
let idsToHide = []
|
||||
|
||||
function idBtnHTML(user) {
|
||||
const element = document.createElement('div');
|
||||
element.setAttribute('class', 'idToHide');
|
||||
const element = document.createElement('div')
|
||||
element.setAttribute('class', 'idToHide')
|
||||
element.innerHTML = `
|
||||
<a href="https://vk.com/id${user.id}" target="_blank" title="Перейти в профиль">🤐 ${user.name}</a>
|
||||
<span class="del_item" title="Удалить">🗑️</span>
|
||||
`;
|
||||
element.id = user.id;
|
||||
return element;
|
||||
`
|
||||
element.id = user.id
|
||||
return element
|
||||
}
|
||||
|
||||
chrome.storage.sync.get('isExtensionOn', function(data) {
|
||||
isExtensionOn = data.isExtensionOn;
|
||||
chrome.storage.sync.get('isExtensionOn', (data) => {
|
||||
isExtensionOn = data.isExtensionOn
|
||||
|
||||
disableCheckbox.checked = isExtensionOn;
|
||||
});
|
||||
disableCheckbox.checked = isExtensionOn
|
||||
})
|
||||
|
||||
chrome.storage.sync.get('idsToHide', function(data) {
|
||||
idsToHide = data.idsToHide;
|
||||
chrome.storage.sync.get('idsToHide', (data) => {
|
||||
idsToHide = data.idsToHide
|
||||
for (const id in idsToHide) {
|
||||
const row = idBtnHTML(idsToHide[id]);
|
||||
idList.appendChild(row);
|
||||
const row = idBtnHTML(idsToHide[id])
|
||||
idList.appendChild(row)
|
||||
}
|
||||
|
||||
for (const element of idsToHideElements) {
|
||||
for (const child of element.childNodes) {
|
||||
if (child.className === "del_item") {
|
||||
child.addEventListener('click', function() {
|
||||
idsToHide = idsToHide.filter(user => user.id != element.id);
|
||||
chrome.storage.sync.set({idsToHide: idsToHide}, function() {
|
||||
element.remove();
|
||||
console.log('Cleared idsToHide');
|
||||
});
|
||||
});
|
||||
if (child.className === 'del_item') {
|
||||
child.addEventListener('click', () => {
|
||||
idsToHide = idsToHide.filter(user => user.id !== element.id)
|
||||
chrome.storage.sync.set({ idsToHide }, () => {
|
||||
element.remove()
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
disableCheckbox.addEventListener('change', (event) => {
|
||||
isExtensionOn = event.target.checked;
|
||||
isExtensionOn = event.target.checked
|
||||
|
||||
chrome.storage.sync.set({isExtensionOn}, function() {
|
||||
console.log('isExtensionOn: '+isExtensionOn);
|
||||
});
|
||||
});
|
||||
chrome.storage.sync.set({ isExtensionOn })
|
||||
})
|
||||
|
||||
@@ -1,38 +1,34 @@
|
||||
const INTERVAL_TIME = 100;
|
||||
const INTERVAL_TIME = 100
|
||||
|
||||
export class UrlController {
|
||||
|
||||
constructor() {
|
||||
this._changeListeners = [];
|
||||
this._interval = null;
|
||||
this._url = window.location.href;
|
||||
this._changeListeners = []
|
||||
this._interval = null
|
||||
this._url = window.location.href
|
||||
}
|
||||
|
||||
onChange(cb) {
|
||||
this._changeListeners.push(cb);
|
||||
if (this._interval === null) {
|
||||
this._createInterval();
|
||||
}
|
||||
this._changeListeners.push(cb)
|
||||
if (this._interval === null)
|
||||
this._createInterval()
|
||||
}
|
||||
|
||||
removeEventListener(cb) {
|
||||
this._changeListeners = this._changeListeners.filter(item=>item !== cb);
|
||||
if(this._changeListeners.length === 0) {
|
||||
this._clearInterval();
|
||||
}
|
||||
this._changeListeners = this._changeListeners.filter(item => item !== cb)
|
||||
if (this._changeListeners.length === 0)
|
||||
this._clearInterval()
|
||||
}
|
||||
|
||||
_intervalTick() {
|
||||
const currentUrl = window.location.href;
|
||||
const currentUrl = window.location.href
|
||||
if (currentUrl !== this.url) {
|
||||
this._broadcast(this.url, currentUrl);
|
||||
this.url = currentUrl;
|
||||
this._broadcast(this.url, currentUrl)
|
||||
this.url = currentUrl
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
_broadcast(oldUrl, newUrl) {
|
||||
this._changeListeners.forEach(cb => cb(oldUrl, newUrl));
|
||||
this._changeListeners.forEach(cb => cb(oldUrl, newUrl))
|
||||
}
|
||||
|
||||
_createInterval() {
|
||||
@@ -43,5 +39,4 @@ export class UrlController {
|
||||
clearInterval(this.interval)
|
||||
this.interval = null
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,3 +1,3 @@
|
||||
export function getChatBody() {
|
||||
return document.getElementsByClassName("_im_peer_history im-page-chat-contain")[0];
|
||||
return document.getElementsByClassName('_im_peer_history im-page-chat-contain')[0]
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
const path = require('path');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const path = require('node:path')
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
|
||||
module.exports = {
|
||||
mode: "development",
|
||||
devtool: "inline-source-map",
|
||||
mode: 'development',
|
||||
devtool: 'inline-source-map',
|
||||
entry: {
|
||||
dom: './src/dom/main.js',
|
||||
background: './src/background/background.js',
|
||||
popup: './src/popup/popup.js'
|
||||
popup: './src/popup/popup.js',
|
||||
},
|
||||
output: {
|
||||
filename: '[name].js',
|
||||
path: path.resolve(__dirname, 'extension/dist')
|
||||
path: path.resolve(__dirname, 'extension/dist'),
|
||||
},
|
||||
module: {
|
||||
rules: [
|
||||
@@ -21,25 +20,30 @@ module.exports = {
|
||||
use: {
|
||||
loader: 'babel-loader',
|
||||
options: {
|
||||
presets: ['@babel/preset-env']
|
||||
}
|
||||
}
|
||||
presets: ['@babel/preset-env'],
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
test: /\.css$/i,
|
||||
use: ['style-loader', 'css-loader'],
|
||||
}
|
||||
]
|
||||
},
|
||||
plugins: [new HtmlWebpackPlugin({
|
||||
template: "./src/popup/popup.html",
|
||||
filename: "popup.html",
|
||||
chunks: ['popup']
|
||||
{
|
||||
test: /\.svg$/i,
|
||||
use: 'raw-loader',
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
new HtmlWebpackPlugin({
|
||||
template: './src/popup/popup.html',
|
||||
filename: 'popup.html',
|
||||
chunks: ['popup'],
|
||||
}),
|
||||
new HtmlWebpackPlugin({
|
||||
template: "./src/donate.html",
|
||||
filename: "donate.html",
|
||||
chunks: ['donate']
|
||||
})]
|
||||
|
||||
template: './src/donate.html',
|
||||
filename: 'donate.html',
|
||||
chunks: ['donate'],
|
||||
}),
|
||||
],
|
||||
}
|
||||
Reference in New Issue
Block a user