ficbook.net old top notifications

Возвращает иконки обновлений в заголовок, больше не требуется лишнего клика по "колокольчику".

目前為 2022-09-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name         ficbook.net old top notifications
// @description  Возвращает иконки обновлений в заголовок, больше не требуется лишнего клика по "колокольчику".
// @namespace    http://tampermonkey.net/
// @version      0.5
// @author       AjiTae
// @match        *://ficbook.net/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=ficbook.net
// @grant        none
// @run-at       document-start
// ==/UserScript==
{
  const showNews = true; // показывать новости сайта

  const { decodeHTMLEntities, encodeHTMLEntities } = ((textarea) => ({
    decodeHTMLEntities(text) {
      textarea.innerHTML = text;
      const { value } = textarea;
      textarea.innerHTML = '';
      return value;
    },
    encodeHTMLEntities(text) {
      textarea.setAttribute('encode', text);
      const value = textarea.outerHTML.match(/encode="(.*?)"/)[1];
      textarea.setAttribute('encode', '');
      return value;
    }
  }))(document.createElement("textarea"));

  const parse = (value) => JSON.parse(decodeHTMLEntities(value));
  const stringify = (value) => encodeHTMLEntities(JSON.stringify(value));

  const patchNotifications = (config) => {
    const [ , notifications, news ] = config.template.match(/:notification-?counts="(.*?)".*?:new-?news="(.*?)"/i);

    const importantCounts = stringify(parse(notifications).important);
    const siteNewsCount = showNews ? news : 0;

    config.components.TopNotifications = config.components.notifications.components.TopNotifications;
    config.template = `<div class="notifications-fixed">
      <top-notifications class="top-notifications-fixed" :important-counts="${importantCounts}" :site-news-count="${siteNewsCount}"></top-notifications>
      ${config.template.replace(/(:new-?news=")[^"]+(?=")/i, '$10')}
    </div>`;

    console.log(config.template, config.components.TopNotifications)
  }

  document.documentElement.insertAdjacentHTML('beforeend', `<style>
    .notifications-fixed {
      align-items: center;
      display: flex;
    }

    .top-notifications-fixed {
      display: flex;
      align-items: center;
      list-style-type: none;
      margin-bottom: 0;
      padding: 3px;
    }

    .top-notifications-fixed .important-link {
      align-items: center;
      border-radius: 3px;
      display: flex;
      font-size: 16px;
      font-weight: 700;
      margin: 4px;
      padding: 5px;
      text-decoration: none;
    }

    .top-notifications-fixed .icon {
      margin-bottom: 0;
      margin-right: 7px;
    }

    .top-notifications:empty {
      display: none;
    }
  </style>`);

  Object.defineProperty = ((defineProperty) => (obj, key, descriptor) => {
    if (key === 'createApp') {
      descriptor.get = ((get) => function() {
        return ((createApp) => (config, ...args) => {
          if (config?.name === 'notifications-app') {
            patchNotifications(config);
          }

          return createApp(config, ...args);;
        })(get.call(this));
      })(descriptor.get);

      Object.defineProperty = defineProperty;
    }

    return defineProperty(obj, key, descriptor);
  })(Object.defineProperty);
};

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址