@everyone для бедных получил кнопку

Долгожданное обновление

UPD: Эти маняпуляции больше не нужны, но смотрятся прикольно. Как будто пупырки лопаешь.

Что было раньше

Как установить

Скачать Tampermonkey

Нажать на иконку расширения. Выбрать "Создать новый скрипт".

Заменить код на этот. Нажать "Файл > Сохранить".

// ==UserScript== // @name DTF Mention All // @namespace http://tampermonkey.net/ // @version 2024-03-21 // @description @ for everyone // @author Demon59901 // @match https://dtf.ru/* // @icon https://www.google.com/s2/favicons?sz=64&domain=dtf.ru // @grant none // ==/UserScript== const NEVER_MENTION = [-1, 1,] const SHOW_LAST_LINE = true const DELAY = 5000 function setup() { const contentId = window.location.href.match(/\/(\d+)[^\/]*$/) if (!contentId) return const commentsTree = document.querySelector('.comments-tree') const inputField = document.querySelector('.contenteditable__input') const buttonGroup = document.querySelector('.comments-form__actions') if (!commentsTree || !inputField || !buttonGroup || buttonGroup.querySelector('#mention-all')) return function createMentionButton(mentions) { const mentionButton = document.createElement('button') mentionButton.id = 'mention-all' mentionButton.innerText = '@' mentionButton.className = 'icon-button' mentionButton.style.width = '28px' mentionButton.style.height = '28px' let currentIndex = -1 mentionButton.onclick = e => { if (inputField.innerText.length > 0) { inputField.innerText += '\n\n' } if (e.altKey) { inputField.innerText += mentions.join('\n\n') return } currentIndex = e.shiftKey ? (currentIndex - 1 + mentions.length) % mentions.length : (currentIndex + 1) % mentions.length inputField.innerText += mentions[currentIndex] + '⌦' if (SHOW_LAST_LINE && mentions.length > 1 && currentIndex + 1 === mentions.length) { inputField.innerText += '\n--- конец ---' } } return mentionButton } fetchData(`https://api.dtf.ru/v2.4/comments?sorting=hotness&contentId=${contentId[1]}`) .then(({ result: { items } }) => { const ids = new Set() items.forEach(item => { const { author: { id, name }, isIgnored } = item if (!NEVER_MENTION.includes(id) && !isIgnored) { ids.add(JSON.stringify({ id, name })) } }) const mentions = makeMentions(ids) if (!mentions || !mentions.length) return buttonGroup.appendChild(createMentionButton(mentions)) }) } async function fetchData(url) { try { const response = await fetch(url) if (!response.ok) { const error = await response.text() throw new Error(error) } return await response.json() } catch (error) { console.log(error) } } function makeMentions(ids) { return Array.from(ids).reduce((result, cur, idx) => { const strIdx = Math.floor(idx / 10) if (!result[strIdx]) { result[strIdx] = '' } const author = JSON.parse(cur) result[strIdx] += `[@${author.id}|${author.name}] ` return result }, []) } let prevPage = window.location.href const pageObserver = new MutationObserver(() => { if (window.location.href !== prevPage) { prevPage = window.location.href setTimeout(setup, DELAY) } }) pageObserver.observe(document.body, { childList: true, subtree: true }) setTimeout(setup, DELAY)

Параметры

NEVER_MENTION
id, которые не надо показывать в выдаче, например свой, аккаунт удалён (-1) или редакции (1). Писать через запятую.

SHOW_LAST_LINE (true/false)
На последней строке выведет такое сообщение

@everyone для бедных получил кнопку

DELAY
Время в мс, которое нужно, чтобы страница успела загрузить элементы, необходимые, чтобы добавить кнопку. Если не подгружается, попробуйте увеличить.

После всех изменений не забывайте сохранять файл

Как пользоваться

Нажать на кнопку @. Стереть символ ⌦, чтобы появилась кнопка "Отправить".

За раз выводится 10 id, т.к. это максимум упоминаний в одном комментарии.

Чтобы вывести следующие 10, ещё раз нажать @.

Чтобы вывести предыдущие 10, нажать shift + @.

Чтобы вывести все (зачем-то) нажать alt + @.

Теперь будете пользоваться скриптом?
Да
Нет
Возможно
3.5K3.5K показов
291291 открытие
5 комментариев

Что-то на хакерском

Ответить

Кайфарики)

Ответить

ЗБС

теперь сделай кнопку вернуть нормальный дизайн

Ответить

у меня кнопка пропала(((

Ответить

Потому что название класса поменяли
Было .comments__tree, стало .comments-tree

Ответить