tele5 mediathek view

makes the page usable again

当前为 2023-01-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name tele5 mediathek view
// @namespace Violentmonkey Scripts
// @match https://tele5.de/mediathek/
// @description makes the page usable again
// @version 0.0.1.20230103180049
// ==/UserScript==

// adjust this to your needs:
// 3: default, for smaller resolutions
// 4: 1920x1080/full screen
var columns = 3;
// 

var debug = 0;
if (debug != 1) {
  console.log = function() {};
  console.warn = function() {};
  console.err = function() {};
}

if (pages)(function() {

  document.getElementsByTagName("body")[0].style.display = "none";

  Date.prototype.addDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() + days);
    return date;
  }
  
  Date.prototype.cutDays = function(days) {
    var date = new Date(this.valueOf());
    date.setDate(date.getDate() - days);
    return date;
  }
  
  function addMonths(date, months) {
      var d = date.getDate();
      date.setMonth(date.getMonth() + +months);
      if (date.getDate() != d) {
        date.setDate(0);
      }
      return date;
  }

  function unique(a) {
    var r = new Array();
    o: for (var i = 0, n = a.length; i < n; i++) {
      for (var x = i + 1; x < n; x++) {
        if (a[x] == a[i]) continue o;
      }
      r[r.length] = a[i];
    }
    return r;
  }
  
  function makestartdate(whichdate) {
    whichdate = whichdate.replace(/.*\-/g, "");
    var subtfix = whichdate.split(".");
    whichdate = fullyear + "-" + subtfix[1] + "-" + subtfix[0];
    var enddate = whichdate;
    var mynewstartdate = new Date(whichdate);
    mynewstartdate = mynewstartdate.cutDays(15).toISOString().split('T')[0];
    var meingotta = mynewstartdate.split("-");
    var meingottb = enddate.split("-");
    whichdate = meingotta[2] + "." + meingotta[1] + "-" + meingottb[2] + "." + meingottb[1];
    whichdate = whichdate.replace(/^0/g, "");
    return whichdate;
  }

  function makedate(str) {
console.log("makedate: "+str);
    str = str.replace(/.*Online:? /g, "");
    str = str.replace(fullyear, "");
    str = str.replace(fullyear - 1, "");
    str = str.replace(fullyear + 1, "");
    str = str.replace(/ /g, "");
    str = str.replace(/-0/g, "-");
    str = str.replace(/\/([0-9]+)\./g, ""); 
    str = str.replace(/\.$/g, "");
    str = str.replace(/\.-/g, "-");
    str = str.replace(/-0([0-9+])/g, "-");
    str = str.replace(/^0([0-9+])/g, "");
    str = str.replace(/\.0([0-9+])/g, "\.");
    str = str.replace(/[^0-9.-]/gim, "");
    console.log("makedate: "+str);

    if ((str.split(".").length - 1) != 2) {
      console.log(str + " MIGHT NOT BE A DATE");
      var fixing = "";
      if ((str.split(".").length - 1) < 2) {
        var subtfix = "1." + (d.getFullMonth() - 1).toString();
        if (str.indexOf("-") == -1) {
          fixing = ", FIXED START DATE MISSING"; // bis 29.11
          str = makestartdate(str);

        } else {
          fixing = ", FIXED START MONTH MISSING"; // 4-11.10
          if ((str.split("-").length - 1) > 1) {
          str = str.replace(/.*-/g, ""); // 23-0-30.10 - thanks tele5 intern for nothing!
          str = makestartdate(str);
            
          } else {
          var subtfix = str.split("-");
          var montfix = subtfix[1].split(".");
          str = subtfix[0].toString() + "." + montfix[1].toString() + "-" + subtfix[1];            
          }

        }
      } else if ((str.split(".").length - 1) > 2) {
                console.log("we are here: "+ str) // 6.11-5-1.23
        fixing = ", FIXED DOT"; // JS encoding problem resulting in converting dash to dot
        if (str.indexOf(".23") != -1) { // later replace w/ two digit for current year
          str = str.replace(/-.*/g, "-31.12"); // 23-0-30.10 - thanks tele5 intern for nothing!
        } else {
          var subtfix = str.split(".");
          str = subtfix[0] + "." + subtfix[1] + "-" + subtfix[2] + "." + subtfix[3];
        }

      } 
      console.log("ALERT! MALFORMED DATE" + fixing + " " + str);
    } 
    return str.trim();
  }

  function formatdate(datestring, formtil) {
    var mydate = datestring.split(".");
    var myday = mydate[0];
    var mymonth = mydate[1];
    var myyear = fullyear;

    if (myday < 10) {
      myday = "0" + myday
    }
    if (mymonth < 10) {
      mymonth = "0" + mymonth
    }

    return myyear + "-" + mymonth + "-" + myday;
  }

  function writetable(which, how) {
    var allrows = "";
    for (var i = 0, l = which.length - 1; i < l; ++i) {
      if ((which[i] != undefined) && (which[i] != "undefined"))
        var filmset = which[i].split("|");
      if (how == 0) {
        var ab = filmset[1];
        var wann = filmset[0];
      } else {
        var ab = filmset[0];
        var wann = filmset[1];
      }
      var was = filmset[2];
      var wo = filmset[3];
      var wie = filmset[4];
      var regexpd = new RegExp(" - .*", "gi");
      was = was.replace(regexpd, "");
      var regexpe = new RegExp(": .*", "gi");
      was = was.replace(regexpe, "");
      var x = "";
      if (how == 0) {
        x = "jetzt";
      } else {
        x = "bald";
      }
      var link = '<a href="' + wo + '">';
      var tablerow = '<div class="box">' + link + '<img class="' + x + '" src="' + wie + '" /></a><br />' + link + was + '</a><br />' + ab + ' - <br />' + wann + '</div>' + "\n";
      if (how == 0) {
        if (!(new Date(wann) - d <= 0)) {
          allrows += tablerow;
        } 
      } else {
        allrows += tablerow;
      }
    }
    return allrows;
  }

  var d = new Date();
  var fullyear = d.getFullYear();
  var fullday = d.getDate();

  Date.prototype.getFullMonth = function() {
    const month = this.getMonth() + 1
    return month
  }

  var fullmonth = d.getFullMonth();

  var filmsa = new Array();
  var filmsb = new Array();
  
  if (debug != 0) {  var skip = 0; }
  
  for (var i = 0, l = pages.length; i < l; ++i) {
    var filmtitle = pages[i].title;
    if ((filmtitle != undefined) && (filmtitle != "undefined") && (filmtitle != "") && (pages[i].subtitle.indexOf(" Online") != -1)) {
      
      /////////////////////////////////////////////////////////////////////////////////////////////

      var splitdate = makedate(pages[i].subtitle).split("-");

      /////////////////////////////////////////////////////////////////////////////////////////////
      var onlinefrof, onlinetilf = "";
      onlinefrof = formatdate(splitdate[0]);
      onlinetilf = formatdate(splitdate[1], true);
      if (new Date(onlinetilf) < new Date(onlinefrof)) {
        if (fullmonth == 11 || fullmonth == 12) {
          onlinetilf = onlinetilf.replace(fullyear,fullyear+1);
        } else if (fullmonth == 1 || fullmonth == 2) {
          onlinefrof = onlinefrof.replace(fullyear,fullyear-1);
        } else {
          console.log(onlinefrof+" - "+onlinetilf+": end date is before start date, adding a month");
          onlinefrof = addMonths(new Date(onlinefrof),-1).toISOString().split('T')[0];          
        }

      }
      
      if (fullmonth == 1 || fullmonth == 2) {
        // assume that releases with expiry in June-December of the past year are db zombie entries:
          if (onlinefrof.match(fullyear+"-1.-") || onlinefrof.match(fullyear+"-09-") || onlinefrof.match(fullyear+"-08-") || onlinefrof.match(fullyear+"-08-") || onlinefrof.match(fullyear+"-06-")) {
          console.log("past: "+filmtitle);
          onlinefrof = onlinefrof.replace(fullyear,fullyear-1);
          onlinetilf = onlinetilf.replace(fullyear,fullyear-1);
          }
        
      }
      
      var linesuf = "|" + filmtitle + "|" + pages[i].url + "|" + pages[i].image;
      if (!(new Date(onlinefrof) - d >= 0)) {
        // jetzt
        filmsa[i] = onlinetilf + "|" + onlinefrof + linesuf;
      } else if (new Date(onlinefrof) - d >= 0) {
        // bald
        // add one day
        // var date = new Date(onlinefrof);
        // onlinefrof = date.addDays(1).toISOString().split('T')[0];
        filmsb[i] = onlinefrof + "|" + onlinetilf + linesuf;
      }
    } else if ((filmtitle != undefined) && (filmtitle != "undefined") && (filmtitle != "")) {
      if (debug != 0) {
        console.log("skipping "+filmtitle);
        ++skip;
      }
      
    }
  }
  
  if (debug != 0) {console.log("skipped: "+skip)}

  filmsa = unique(filmsa).sort();
  // filmsa = filmsa.sort();
  filmsb = unique(filmsb).sort();
  // filmsb = filmsb.sort();

  var screenwidth = window.innerWidth;
  var imgsize = Math.floor(screenwidth / 3 - 250);
  var cssimg = imgsize.toString();
  var padcss = Math.floor(imgsize / 3).toString();
  var marcss = Math.floor(imgsize).toString();
  var mediathek, dvdx, colcount = "";
  var dvdr = '<div class="box"></div>\n';
  if (columns == 4) {
    colcount = "25% 25% 25% 25";
    dvdx = dvdr;
  } else {
    colcount = "33% 33% 33";
  }

  mediathek += '<html><head><title>tele5 mediathek view</title><base href="https://tele5.de/mediathek/"><meta charset="utf-8">\n';
  mediathek += '<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png" />\n';
  mediathek += '<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png" />\n';
  mediathek += '<style>body { margin: 40px; font-family: Arial; overflow-x: hidden; display: none; } img {width: ' + cssimg + 'px; text-decoration:none;border:none;}\n';
  mediathek += '.wrapper { display: grid; grid-gap: 15px; grid-template-columns: ' + colcount + '%; background-color: #fff; color: #444; }\n';
  mediathek += '.box { background-color: #444; color: #fff; border-radius: 5px; padding: 20px; font-size: 100%; }\n';
  mediathek += '.bottom {margin-top: ' + marcss + 'px;margin-bottom: ' + padcss + 'px;}  .top {margin-top: ' + padcss + 'px;} </style>\n</head><body>\n';
  mediathek += '<div class="wrapper top"><div class="box"><a name="jetzt"></a></div>' + dvdr + dvdr + dvdx;
  if (filmsb.length > 0) {
        mediathek += '<div class="box">jetzt:</div><div class="box"><a href="#bald">bald</a></div>' + dvdr + dvdx + '\n';
  }
  mediathek += writetable(filmsa, 0);
  if (filmsb.length > 0) {
        mediathek += '</div><div class="wrapper bottom"><div class="box"><a name="bald"></a></div>' + dvdr + dvdr + dvdx;
        mediathek += '<div class="box"><a href="#jetzt">jetzt</a></div><div class="box">bald:</div>' + dvdr + dvdx + '\n';
        mediathek += writetable(filmsb, 1);
        mediathek += '</div>';
  } else {
        mediathek += '</div>';
  }

  // fix for some weird throw of undefined in the generated markup
  document.write(mediathek.replace(/undefined/g, ""));

  setTimeout("document.getElementsByTagName('body')[0].style.display = 'block'", 500);
  setTimeout("window.location.hash = '#jetzt'", 510);

})();