Fix Dark Text on AvistaZ Network Forums

Fix dark text on AvistaZ Network forum pages and within torrent descriptions when using the Dark theme.

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.

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        Fix Dark Text on AvistaZ Network Forums
// @namespace   https://avistaz.to/profile/dryeyes
// @description Fix dark text on AvistaZ Network forum pages and within torrent descriptions when using the Dark theme.
// @match       *://*.cinemaz.to/*
// @match       *://*.avistaz.to/*
// @match       *://*.privatehd.to/*
// @version     0.1.0
// @grant       none
// @locale      English (en)
// ==/UserScript==
(function(){
  'use strict';

  let cleanedUrl = window.location.href.replace(/(#.*)$/, '');
  let usingDarkTheme;

	function addGlobalStyle(css) {
		try {
			let elmHead, elmStyle;
			elmHead = document.getElementsByTagName('head')[0];
			elmStyle = document.createElement('style');
			elmStyle.type = 'text/css';
			elmHead.appendChild(elmStyle);
			elmStyle.innerHTML = css;
		} catch (e) {
			if (!document.styleSheets.length) {
				document.createStyleSheet();
			}
			document.styleSheets[0].cssText += css;
		}
	}

  function changeDarkSpansToWhite() {
    let spans = document.querySelectorAll(`span[style*="#0000ff;"],span[style*="rgb(51,0,255)"],
                                          span[style*="#000000;"]`);
      Array.prototype.forEach.call(spans, elm => { elm.style.color = "rgb(204,204,204)"; } );
    }

  function onLoadHandler() {
    console.log("FixForumDarkText Load event occurred:", cleanedUrl);

    let bodyStyle = window.getComputedStyle(document.body);
    let backgroundColor = bodyStyle.backgroundColor.trim();
    console.log("body background.color", backgroundColor);
    usingDarkTheme = (backgroundColor === "rgba(0, 0, 0, 0)" ||
                      backgroundColor === "rgb(34, 34, 34)");
    console.log("usingDarkTheme:", usingDarkTheme);

    if (usingDarkTheme) {
      changeDarkSpansToWhite();
      addGlobalStyle(`.ipsStreamItem_snippet .ipsType_richText {
        color: #ffffff;
      }`);
    }
  }
  console.log("UserScript running");

  window.addEventListener('load', onLoadHandler, false);
})();