constb / Beta MyShows Compactify UI

// ==UserScript==
// @id           BetaMyshowsCompactify
// @name         Beta MyShows Compactify UI
// @description  Более компактный и удобный для десктопа UI для новой версии MyShows. Убрал воздух, отменил дублирование дат в календаре (как в старой версии).
// @namespace    http://tampermonkey.net/
// @version      0.6
// @author       constb
// @match        https://myshows.me/*
// @icon         data:image/x-icon;base64,AAABAAEAEBAAAAEAGABoAwAAFgAAACgAAAAQAAAAIAAAAAEAGAAAAAAAAAMAAAAAAAAAAAAAAAAAAAAAAAD///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////8AD78AD78AD78AD78AD78AD78AD78AD78AD78AD7////////////////////8AD78AD78AD78AD78AD78AD78AD78AD78AD78AD78AD78AD7////////////////8AD78AD7////////////////////////////////8AD78AD7////////////////8AD78AD7////////////////////////////////8AD78AD7////////////////8AD78AD7////////////////////////////////8AD78AD7////////////////8AD78AD7////////////////////////////////8AD78AD7////////////////8AD78AD7////////////////////////////////8AD78AD7////////////////8AD78AD78AD78AD78AD78AD78AD78AD78AD78AD78AD78AD7////////////////////8AD78AD78AD78AD78AD78AD78AD78AD78AD78AD7////////////////////////////////////////8AD78AD7////////////////////////////////////////////////////8AD7////////8AD7////////////////////////////////////////8AD78AD7////////////////8AD78AD7////////////////////////////////8AD78AD7////////////////8AD78AD7///////////////////////////////////////////////////////////////////////////////////wAA//8AAOAHAADAAwAAz/MAAM/zAADP8wAAz/MAAM/zAADAAwAA4AcAAP5/AAD9vwAA888AAPPPAAD//wAAPCEtLQokKCdib2R5JykuZXEoMCkuY3NzKCd3aWR0aCcpCi0tPgo=
// @grant        none
// @license      MIT
// ==/UserScript==

function throttle (fn, wait) {
  let inThrottle, lastFn, lastTime;
  return function() {
    const context = this,
      args = arguments;
    if (!inThrottle) {
      fn.apply(context, args);
      lastTime = Date.now();
      inThrottle = true;
    } else {
      clearTimeout(lastFn);
      lastFn = setTimeout(function() {
        if (Date.now() - lastTime >= wait) {
          fn.apply(context, args);
          lastTime = Date.now();
        }
      }, Math.max(wait - (Date.now() - lastTime), 0));
    }
  };
};


(function() {
    'use strict';

    var styleEl = document.createElement('style');
    document.head.appendChild(styleEl);
    var styleSheet = styleEl.sheet;

    var rules = [
        ['.UnwatchedEpisodeItem', ['padding: 4px 0 4px 2px'], 'min-width: 1240px'],
        ['.UnwatchedEpisodeItem', ['padding: 3px 0']],
        ['.EpisodeWatchLabel', ['width: 18px', 'height: 18px']],
        ['.Breadcrumbs', ['margin: 12px 0 5px']],
        ['.Col', ['padding: 4px 0']],
        ['.WatchSoon-date', ['max-width: 34px']],
        ['.WatchSoon-date > a:first-child', ['display: flex','justify-content: space-evenly', 'margin-right: 10px']],
        ['.WatchSoon-date div:first-child', ['margin-right: 3px']],
        ['.WatchSoon-date', ['display: flex']],
        ['.WatchSoon-episode', ['margin: 1px 0 0 15px']],
        ['.WatchSoon__title-wrapper', ['display: flex;', 'justify-content: flex-start', 'align-items: center', 'flex-direction: row']],
        ['.UserShowItem_mode_compact', ['padding: 9px 0']],
        ['.UserShowItem_mode_compact .UserShowItem-progress', ['margin: -4px 0 0 0']],
        ['.Feed-group', ['padding: 5px 0']],
        ['.FeedItem:not(:last-child)', ['padding-bottom: 5px', 'margin-bottom: 5px']],
        ['.title__secondary, .title__secondary-s', ['margin: 0 0 5px']],
        ['.ShowRating .Tip', ['display: none']],
    ];

    for (const [sel, rs, med] of rules) {
        const [before, after] = med ? ['@media ('+ med +') {', '}'] : ['', ''];
        for (const r of rs) {
            styleSheet.insertRule(before+ sel + '{' + r + '!important;}' + after, styleSheet.cssRules.length);
        }
    }

    function doStuff() {
        let p;
        for (const ws of document.querySelectorAll('.WatchSoon-date')) {
            if (p && p.innerText === ws.innerText) ws.style.opacity = 0;
            p = ws;
        }
    }
    doStuff();

    new MutationObserver(throttle(doStuff, 500)).observe(document.getElementById('__nuxt'), { childList:true, subtree:true });
})();