Verfallsmelder

Markiert verfallende Missionen

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name        Verfallsmelder
// @namespace   leeSalami.lss
// @version     1.0.2
// @description Markiert verfallende Missionen
// @license     MIT
// @author      leeSalami
// @match       https://*.leitstellenspiel.de
// @match       https://*.meldkamerspel.com
// ==/UserScript==

(function() {
  'use strict';

  const LAST_2AM_TIMESTAMP = getLastUtc2Am() / 1000;
  const TIMESTAMP_REGEX = /"created_at":\s*(\d+)/;
  const HEADING_SEARCH = "class='panel-heading'>";

  const missionMarkerAddOrig = missionMarkerAdd;
  missionMarkerAdd = (mission) => {
    missionMarkerAddOrig(mission);

    if (mission.created_at * 1000 < getLastUtc2Am() && !document.getElementById(`old_mission_marker_${mission.id}`)) {
      const missionPanelHeading = document.getElementById(`mission_panel_heading_${mission.id}`);

      if (missionPanelHeading) {
        const alertText = document.createElement('span');
        alertText.id = 'old_mission_marker_' + mission.id;
        alertText.textContent = '‼️';
        alertText.style.float = 'right';
        missionPanelHeading.appendChild(alertText);
      }
    }
  }

  const processMissionElementFromWorkerOrig = processMissionElementFromWorker
  processMissionElementFromWorker = (e, t, i) => {
    const timestampMatch = e.el.match(TIMESTAMP_REGEX);

    if (timestampMatch && timestampMatch[1]) {
      const createdAt = parseInt(timestampMatch[1], 10);

      if (createdAt < LAST_2AM_TIMESTAMP) {
        e.el = e.el.replace(HEADING_SEARCH, `${HEADING_SEARCH}<span style="float:right" id="old_mission_marker_${e.id}">‼️</span>`);
      }
    }

    processMissionElementFromWorkerOrig(e, t, i);
  }

  function getLastUtc2Am() {
    const lastUTC2am = new Date();
    lastUTC2am.setUTCHours(2, 0, 0, 0);

    if (lastUTC2am.getTime() > Date.now()) {
      lastUTC2am.setDate(lastUTC2am.getDate() - 1);
    }

    return lastUTC2am.getTime();
  }
})();