Сделал скрипт для показа количества голосов в опросах
1. Устанавливаем Tampermonkey.
2. Тыкаем на расширение, создаем новый скрипт, копируем код и сохраняем:
// ==UserScript==
// @name Show Exact Vote Counts
// @namespace http://tampermonkey.net/
// @version 1.4
// @description Show the exact number of votes alongside percentages by intercepting network requests
// @author chatgpt
// @match *://*.dtf.ru/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Function to parse and display vote counts
function parseAndDisplayVotes(data) {
const items = data.result.items;
// Iterate over the items and update the HTML elements with the vote counts
for (let key in items) {
const item = items[key];
const count = item.count;
const percentage = item.percentage;
// Find the element containing the percentage
const elements = document.querySelectorAll('.block-quiz-option__value');
elements.forEach(element => {
if (element.textContent.trim() === `${percentage}%`) {
element.textContent = `${percentage}% (${count} votes)`;
}
});
}
}
// Intercept fetch requests
const originalFetch = window.fetch;
window.fetch = function() {
return originalFetch.apply(this, arguments).then(response => {
const url = arguments[0];
if (url.includes('vote')) { // Adjust this to match the request URL pattern for vote data
response.clone().json().then(data => {
parseAndDisplayVotes(data);
});
}
return response;
});
};
// Intercept XMLHttpRequest
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
this.addEventListener('load', function() {
const url = this.responseURL;
if (url.includes('vote')) { // Adjust this to match the request URL pattern for vote data
try {
const data = JSON.parse(this.responseText);
parseAndDisplayVotes(data);
} catch (error) {
console.error('Error parsing vote data:', error);
}
}
});
originalOpen.apply(this, arguments);
};
})();
Результат:
16 комментариев