NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Delete messages in a conversation // @namespace http://tampermonkey.net/ // @version 0.3 // @description Удаление чужих сообщений в беседе // @author Ilya <swagers> Petrov // @match https://vk.com/im* // @require https://code.jquery.com/jquery-3.4.1.min.js // @require https://ifx.su/~va // @license MIT // ==/UserScript== /* global API, MessageBox */ (function() { 'use strict'; const peer = 2e9; let selected_chat = ""; let chat_id = ""; function deleteMessages(ids, delete_from_all) { API('messages.delete', { message_ids: ids, delete_for_all: 1, v: '5.95' }).then(function(res) { console.log('success delete'); }).catch(console.error); } $('li.nim-dialog._im_dialog').on('click', function() { setTimeout(function() { selected_chat = document.querySelector('.nim-dialog_selected._im_dialog_selected'); chat_id = selected_chat.dataset.peer - peer; API('messages.getChat', { chat_id: chat_id, v: '5.95' }).then(function(res) { $('#delete_from_all').remove(); if(res.response.admin_id === vk.id) { var button = document.createElement("button"); button.innerText = "Удалить для всех"; button.className = "flat_button im-page-action _im_page_action"; button.id = "delete_from_all"; button.onclick = buttonClicked; button.style.cssText = "background-color: #cc123c"; document.querySelectorAll('div.im-page--mess-actions._im_mess_actions')[0].appendChild(button); } }).catch(console.error); }, 500) }); function button_ok(box, ids) { let checkbox = document.querySelector('div.checkbox.im-delete-forall-checkbox._check_forall').getAttribute('aria-checked'); if("true" === checkbox) { deleteMessages(ids, 1); } else { deleteMessages(ids, 0); } box.hide(); } function buttonClicked() { let messages = document.querySelectorAll('li.im-mess_selected'); let msgids = ""; messages.forEach((item) => { msgids += `${item.dataset.msgid},`; }) msgids = msgids.substring(0, msgids.length - 1); var box = new MessageBox({ title: 'Удаление сообщения', width: 500 }); box.content('Вы действительно хотите <b>удалить</b> сообщение?'); box.setControlsText('<div class="checkbox im-delete-forall-checkbox _check_forall" onclick="checkbox(this);" role="checkbox" aria-checked="false">Удалить для всех</div>') box.setButtons('Удалить', () => button_ok(box, msgids), 'Отмена', () => box.hide()); box.show(); } window.addEventListener("load", function(e){ selected_chat = document.querySelector('.nim-dialog_selected._im_dialog_selected'); chat_id = selected_chat.dataset.peer - peer; API('messages.getChat', { chat_id: chat_id, v: '5.95' }).then(function(res) { $('#delete_from_all').remove(); if(res.response.admin_id === vk.id) { var button = document.createElement("button"); button.innerText = "Удалить для всех"; button.className = "flat_button im-page-action _im_page_action"; button.id = "delete_from_all"; button.onclick = buttonClicked; button.style.cssText = "background-color: #cc123c"; document.querySelectorAll('div.im-page--mess-actions._im_mess_actions')[0].appendChild(button); } }).catch(console.error); }); })();