NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name Lunchmarket Total // @namespace https://lunchmarket.ru/ // @version 1.0 // @description Отображает недельную стоимость еды в ланчмаркете // @author sad dev // @license MIT // @match https://lunchmarket.ru/* // @require https://gist.github.com/raw/2625891/waitForKeyElements.js // @grant none // ==/UserScript== /* jshint esversion: 6 */ (function () { 'use strict'; let totalMax = 1000; function recalcTotal(node) { let dayListContainer = document.getElementsByClassName("week_day")[0]; let iStyle = getComputedStyle(dayListContainer.getElementsByTagName("i")[0]); let dayListItems = Array.from(document.getElementsByClassName("week_day_item")).slice(0, 5); let total = dayListItems.map(el => el.innerHTML.match(/\d+(?=р\.)/)) .map(el => parseInt(el, 10)) .reduce((a, b) => a + b); let totalNode = document.createElement("div"); totalNode.style.cssText = "color: #fff; background: #232323; padding: 18px; text-transform: uppercase; font-size: 12px"; totalNode.style.paddingLeft = "50px"; let iconPosition = total <= totalMax ? "-18px 0" : "-18px -15px"; let iconNode = document.createElement("i"); iconNode.style.cssText = "width: 15px; height: 15px; display: block; position: absolute"; iconNode.style.left = iStyle.left; iconNode.style.background = iStyle.background; iconNode.style.backgroundPosition = iconPosition; let totalTextNode = document.createTextNode(`Всего: ${total}р.`); totalNode.appendChild(iconNode); totalNode.appendChild(totalTextNode); dayListContainer.parentNode.insertBefore(totalNode, dayListContainer); } waitForKeyElements(".week_day", recalcTotal); })();