js-tampermonkey-public-scripts/Nextcloud_Show-Original-DB-User-ID.user.js
Unkas Amanjolov 42b29defae first commit
2024-10-07 10:25:50 +05:00

92 lines
4.9 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ==UserScript==
// @name Nextcloud:Show-Original-DB-User-ID
// @namespace http://tampermonkey.net/
// @version 2024-09-26
// @description Скрипт который добавляет кнопку в меню сайта, позволяющую извлекать и отображать ID элементов из списка, обновляя текстовые значения счетчиков на странице и выводя все ID в консоль.
// @author LukasEndigo
// @match https://*.lkaz.ru/apps/memories/facerecognition
// @icon https://nextcloud.com/c/uploads/2022/03/favicon.png
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Функция для обработки элементов
function processItems() {
// Ищем все элементы с классом vue-recycle-scroller__item-view
const items = document.querySelectorAll('.vue-recycle-scroller__item-view');
// Создаем массив для хранения всех lastPart
const ids = [];
items.forEach(function(item) {
// Находим элемент <a> внутри текущего элемента
const linkElement = item.querySelector('a.cluster');
if (linkElement) {
// Извлекаем href из элемента <a> и разбиваем его по "/"
const href = linkElement.getAttribute('href');
const parts = href.split('/');
const lastPart = parts[parts.length - 1]; // Последняя часть URL, то есть ID
// Находим элемент с классом counter-bubble__counter
const counterElement = item.querySelector('.counter-bubble__counter');
if (counterElement) {
// Получаем текущий текст (число)
const currentCount = counterElement.textContent.trim();
// Проверяем, является ли currentCount числом
if (!isNaN(currentCount) && currentCount !== '' && (lastPart/1)) {
// Вставляем текст " / ID=#ID" к числу
counterElement.textContent = `${currentCount} / ID=#${lastPart}`;
// Сохраняем lastPart в массив
ids.push(lastPart);
}
}
}
});
// Выводим все lastPart в консоль в одну строку, разделяя их запятыми
console.info(ids.join(','));
}
// Ожидаем загрузки страницы
window.addEventListener('load', function() {
// Ищем элемент ul с классом app-navigation__settings
const settingsMenu = document.querySelector('.app-navigation__settings');
if (settingsMenu) {
// Создаем новый элемент li
const newLi = document.createElement('li');
newLi.className = 'app-navigation-entry-wrapper'; // Добавляем класс как у других элементов
// Создаем содержимое li с flex-контейнером
newLi.innerHTML = `
<div class="app-navigation-entry" style="display: flex; align-items: center; padding: 5px;">
<a href="#" title="Отоброзить PERSON ID" class="app-navigation-entry-link" style="display: flex; align-items: center;">
<div class="app-navigation-entry-icon" style="margin-right: 8px;">
<span aria-hidden="true" role="img" class="material-design-icon bell-icon">
<svg fill="currentColor" width="20" height="20" viewBox="0 0 24 24" class="material-design-icon__svg">
<path d="M12,22A2,2 0 0,0 14,20H10A2,2 0 0,0 12,22M18,16V11A6,6 0 0,0 12,5V4A1,1 0 0,0 11,3A1,1 0 0,0 10,4V5A6,6 0 0,0 6,11V16L4,18V19H20V18L18,16Z"></path>
</svg>
</span>
</div>
<span class="app-navigation-entry__name">Отоброзить</span>
</a>
</div>
`;
// Добавляем новый элемент в ul
settingsMenu.appendChild(newLi);
// Добавляем обработчик клика для новой ссылки
newLi.querySelector('a').addEventListener('click', function(e) {
e.preventDefault(); // Останавливаем переход по ссылке
processItems(); // Вызов функции показа уведомления
});
}
});
})();