Chain Warn

description

Fra 07.08.2018. Se den seneste versjonen.

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 or Violentmonkey 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.

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         Chain Warn
// @namespace    namespace
// @version      0.3
// @description  description
// @author       tos
// @match        *.torn.com/*
// @grant        GM_addStyle
// @run-at       document-end
// ==/UserScript==

const alert_time = 90 //seconds

GM_addStyle(`
.cw_overlay {
  position: fixed;
  pointer-events: none;
  height: 100%;
  width: 100%;
  z-index: 20000;
  will-change: background-color;
}

.cw_warn {
  animation-name: cw_warn;
  animation-duration: 1.5s;
  animation-iteration-count: infinite;
}

@keyframes cw_warn {
  0% {
    background-color: #FF000000;
  }
  50% {
    background-color: #FF000055;
  }
  100 {
    background-color: #FF000000;
  }
}
`)

document.querySelector('body').insertAdjacentHTML('afterbegin', `<div class="cw_overlay"></div>`)
const warn_overlay = document.querySelector('.cw_overlay')

const observer = new MutationObserver((mutations) => {
  for (const mutation of mutations) {
    try {
      if (mutation.target.parentElement.className.includes('bar-timeleft')) {
        const text_t = mutation.target.data.split(':')
        const t = text_t.map(x => parseInt(x))
        const s = t[0] * 60 + t[1]
        if (0 < s && s < alert_time && t.length < 3) warn_overlay.classList.add('cw_warn')
        else warn_overlay.classList.remove('cw_warn')
      }
    } catch (err) { console.log(err) }
  }
})
const chain_bar = document.querySelector('[class^=chain-bar] [class^=bar-stats]')
if (chain_bar) observer.observe(chain_bar, { subtree: true, characterData: true })