Verfallsmelder

Markiert verfallende Missionen

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

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.

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

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

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

// ==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();
  }
})();