Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name FlyerMeter
- // @version 0.2
- // @author stsyn
- // @match https://tabun.everypony.ru/*
- // @require https://github.com/stsyn/derpibooruscripts/raw/master/YouBooru/libs/CreateElement.js
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- let cache;
- function render(container, dose) {
- let alertLevelItem;
- if (dose > 0.33) alertLevelItem = createElement('img', {src: 'https://sun2.ufanet.userapi.com/FOl-s-OK8s3K5gL3QwvnqmmbXXddB6or0YnS0g/YxNmCCqUoCI.jpg', height: 50});
- else if (dose > 0.20) alertLevelItem = createElement('img', {src: 'https://sun1.ufanet.userapi.com/SlOZjhYxCAj0gmjTO41_M0nRSPiqSPLAVKzlKg/pAWqlJUathU.jpg', height: 50});
- else if (dose > 0.10) alertLevelItem = 'Значение многократно превышает допустимую концентрацию, воздержитесь от присутствия в помещении и не дышите.';
- else if (dose > 0.05) alertLevelItem = 'Значение превышает ПДК. Соблюдайте дистанцию и применяйте средства индивидуальной защиты!';
- else if (dose > 0.02) alertLevelItem = 'Значение приближается к предельно допустимой концентрации.';
- else alertLevelItem = 'Табунпотребназдор одобряет.';
- container.parentNode.appendChild(createElement('div', {
- style: {
- color: dose > 0.10 ? 'red' : 'inherit'
- }
- }, [
- 'Доза Флаера в комментах составляет ',
- createElement('b', Math.round(dose*100)),
- '%. ',
- alertLevelItem
- ]));
- }
- try {
- cache = JSON.parse(localStorage._flyerMeterCache) || {};
- } catch (_) {
- cache = {};
- }
- Array.from(document.querySelectorAll('ul.topic-info')).forEach(item => {
- const topicId = parseInt(item.querySelector('.topic-info-comments a').href.split('/').pop().split('.')[0]);
- const total = item.querySelector('.topic-info-comments a').innerText;
- if (cache[topicId] && cache[topicId].total == total) {
- render(item, parseInt(cache[topicId].metric) / (parseInt(total) || 1));
- return;
- }
- fetch(`/blog/${topicId}.html`, {
- credentials: 'omit'
- })
- .then(resp => resp.text())
- .then(text => {
- const content = createElement('div', text);
- const total = parseInt(content.querySelector('#count-comments').innerText);
- const metric = content.querySelectorAll('.comment-author a:first-child[href*="/Sasha-Flyer/"]').length;
- cache[topicId] = {total, metric};
- localStorage._flyerMeterCache = JSON.stringify(cache);
- render(item, metric / (parseInt(total) || 1));
- })
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement