Dramaday.net - better user experience

Linded title

2022-12-09 يوللانغان نەشرى. ئەڭ يېڭى نەشرىنى كۆرۈش.

// ==UserScript==
// @name         Dramaday.net - better user experience
// @namespace    http://tampermonkey.net/
// @version      2022.12.9
// @description  Linded title
// @author       Radim
// @match        https://dramaday.net/*
// @match        https://dramaday.net/page/*
// @run-at       document-idle
// @license MIT
// @grant        GM_addStyle
// @grant        GM_getResourceText
// @grant        GM_xmlhttpRequest
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_deleteValue
// @grant        GM_addValueChangeListener
// ==/UserScript==
/* eslint-disable */

//this.$ = this.jQuery = jQuery.noConflict(true);

const filter = {  /* https://www.base64encode.org/ or https://base64.alanreed.org/ */
   "bad": [
      "TG92ZSBpcyBmb3IgU3Vja2Vycw==",
      "U3VtbWVyIFN0cmlrZQ==",
      "VGhlIFdpdGNoIFN0b3JlIFJlb3BlbnM="
   ],
   "fav": [
      "Reborn Rich"
   ]
}

const addMy_CSS = "#h1link { text-docoration: none !important; color: blue !important; } #h1link:hover { text-decoration: underline !important; text-decoration-color: red !important; -webkit-text-decoration-color: red !important; }";

var addMy_CSS_Src = GM_getResourceText("addMy_CSS");
GM_addStyle(addMy_CSS_Src);

/* https://violentmonkey.github.io/api/gm/ */

let fi = GM_getValue("filter", JSON.stringify(filter));
let f = JSON.parse(fi);
//alert(  fi );
//alert( f.bad + '\n\n' + f.bad.length );
//alert( f.fav + '\n\n' + f.fav.length );

function addCirleBtn(el)  {
  el.css("position","relative");

  var add = "<span class='add_title' style='position:absolute; left:-22px; top:2px; background: #40C940; border-radius: 50%; color: #ffffff; display: inline-block; font-weight: bold;  line-height: 20px; margin-right: 5px; text-align: center; width: 20px; cursor:pointer;'>+</span>";
  el.append(add);

  var rem = "<span class='rem_title' style='position:absolute; right:-25px; top:2px; background: #C64050; border-radius: 50%; color: #ffffff; display: inline-block; font-weight: bold;  line-height: 20px; margin-left: 5px; text-align: center; width: 20px; cursor:pointer;'>-</span>";
  el.append(rem);
}


(function() {
  'use strict';

  jQuery(document).ready(function($) {
    var s = "Fav: <span id='fav_n' style='color: #40C940;'>"+f.fav.length+"</span> <span style='display: inline-block; height: 10px; width: 46px;'></span> Bad: <span id='bad_n' style='color: #C64050;'>"+f.bad.length+"</span><br><input <input type='text' style='width: 250px;' id='ep_title' value=''><br><input id='fav_btn' style='background-color:#407940;' type='button' value='Add to fav'> <input id='bad_btn' style='background-color:#C64050;' type='button' value='Remove'> <input id='rst_btn' style='background-color:#999999;' type='button' value='Reset'> <input id='rst_all_btn' style='background-color:#ffff00;' type='button' value='RST'>";
    $("body").append('<div style="color: #f7f7f7; background: linear-gradient(#8E588E, #533658, #8E588E); border-radius: 7px; font-weight: bold; display: block; position: fixed; top: 140px; left: 10px; width: 300px; padding: 7px;">'+s+'</div>')

    $('#fav_btn').click(function(e) {
      var t = $("#ep_title").val().trim();
      if( t.length > 1 ) {
        if( !f.fav.includes( t ) ) {
           $('header[class="article__header"] h3[class="article__title entry-title"] a:contains("'+t+'")').css( "border-bottom", "4px solid #33ff33" );
           f.fav.push( t );
           //alert( f.fav + '\n\n' + f.fav.length );
           GM_setValue("filter", JSON.stringify( f ));
           $('#fav_n').text(f.fav.length);
        }
      }
    });

    $('#bad_btn').click(function(e) {
      var t = $("#ep_title").val().trim();
      if( t.length > 1 ) {
        if( !f.bad.includes( btoa(t) ) ) {
           $('header[class="article__header"] h3[class="article__title entry-title"] a:contains("'+t+'")').css( "border-bottom", "2px solid red" );
           f.bad.push( btoa(t) );
           //alert( f.bad + '\n\n' + f.bad.length );
           GM_setValue("filter", JSON.stringify( f ));
           $('#bad_n').text(f.bad.length);
        }
      }
    });

    $('#rst_btn').click(function(e) {
      var t = $("#ep_title").val().trim();
      if( t.length > 1 ) {
        $('header[class="article__header"] h3[class="article__title entry-title"] a:contains("'+t+'")').css( "border-bottom", "none" );
        if( f.bad.includes( btoa(t) ) ) {
           f.bad.splice(f.bad.indexOf(btoa(t)), 1);
           GM_setValue("filter", JSON.stringify( f ));
           $('#bad_n').text(f.bad.length);
        } else if( f.fav.includes( t ) ) {
           f.fav.splice(f.fav.indexOf(t), 1);
           GM_setValue("filter", JSON.stringify( f ));
           $('#fav_n').text(f.fav.length);
        }
      }
    });

    $('#rst_all_btn').click(function(e) {
      GM_deleteValue("filter");
/*
      fi = GM_getValue("filter", JSON.stringify(filter));
      f = JSON.parse(fi);

      $('#fav_n').text(f.fav.length);
      $('#bad_n').text(f.bad.length);
*/
      window.location.reload();
    });

    var h1 = $("h1.entry-title").text().trim();
    //alert( h1 );
    $("h1.entry-title").html( '<a href="https://mydramalist.com/search?q='+ h1.replaceAll(' ', '+') +'" target="_blank">'+ h1 +'</a>' );
    $("h1.entry-title").attr('id', 'h1link');

    /* get last Episode No. */
    var lastROW = $("table[id^='supsystic-table-']").find("tr").last();
    $(lastROW).attr('id', 'latest_episode');
    var allTD = $(lastROW).find("td");
    var ep = $(allTD).first().text().trim();
    //alert( ep );
    var t = $(allTD).eq(1).text();
    var hasWEB_DL = t.indexOf("1080p WEB-DL");
    if( hasWEB_DL == -1)
      hasWEB_DL = t.indexOf("1080p Friday");
    //alert( hasWEB_DL );
    var p = $("div.vc_col-sm-9 div.wpb_wrapper p");
    var s = $(p).html();
    $(p).html( s + '<br>Go to latest episode: <a href="#latest_episode">EP'+ ep +'</a> ( <strong>'+(hasWEB_DL !== -1?"WEB DL / HQ":"no yet")+'</strong> )' );

    /* mark fav, hide bad/common */
    var title = $('header[class="article__header"] h3[class="article__title entry-title"] a');
    //alert( title.text() );
    var i = 1;
    $(title).each(function( index ) {
      var s = $( this ).text();

      /* special Unicode chars title cleanup */
      var s1 = s.replace(/’/ig, "'");
      s1 = s1.replace(/–/ig, "-");
      if(s !== s1) $( this ).text( s1 );
      s = s1;
/*
      var p = s.indexOf("Under the Queen");
      if( p != -1 ) {
        alert( s.charCodeAt( "Under the Queen".length ) );
      }
*/
      if( f.bad.includes(btoa(s)) ) {
         $( this ).css( "border-bottom", "2px solid red" );
         $( this ).parents('article').css('opacity','0.1');
      } else if( f.fav.includes(s) ) {
        $( this ).css( "border-bottom", "4px solid #33ff33" );

        var u = $( this ).attr("href");
        //var parts = u.split('/');
        //u = parts.pop() || parts.pop();  // handle potential trailing slash

        var url = u + " table[id^='supsystic-table-'] tr";
        //alert( url );
        var par = $( this ).parents('header.article__header');
        //alert(par.length);
        $(par).css("position","relative");
        var ep_result = 'ep_result'+i;
        /* https://rgbacolorpicker.com/hex-to-rgba */
        $(par).append('<div id="'+ep_result+'" style="position:absolute; right:0px; top:0px; background-color: rgba(64, 201, 64, 0.6); color: #ffffff; font-weight: bold; height: 80px; line-height: 80px; text-align: center; width: 80px; font-size:18pt;">--</div>');

        /* load latest pisode No. */
        //alert( ep_result );
        $( "#"+ep_result ).load( url, function() {
          //alert( "feed have been loaded" );
          //alert( url + "\n\n" + $( this ).attr("id") + "\n\n" + $( this ).text().length + "\n\n" + $( this ).html() );
          var r = $( this ).find("tr").last();
          //alert( $(r).html() );
          var ep = $(r).find("td").first().text().trim();
          if( ep == "" ) {
            ep = $( this ).find("tr").eq( -2 ).find("td").first().text().trim();
          }
          //alert( ep );
          $( this ).html( ep );
        });
      }

      addCirleBtn( $( this ) );
      i++;
    });

    $('.add_title').click(function(e) {
      e.preventDefault();

      var t = $(this).parent().text().slice(0, -2);
      //alert( t );
      if( !f.fav.includes( t ) ) {
         $('header[class="article__header"] h3[class="article__title entry-title"] a:contains("'+t+'")').css( "border-bottom", "4px solid #33ff33" );
         f.fav.push( t );
         GM_setValue("filter", JSON.stringify( f ));
         $('#fav_n').text(f.fav.length);
      }
    });

    $('.rem_title').click(function(e) {
      e.preventDefault();

      var t = $(this).parent().text().slice(0, -2);
      if( !f.bad.includes( btoa(t) ) ) {
         $('header[class="article__header"] h3[class="article__title entry-title"] a:contains("'+t+'")').css( "border-bottom", "2px solid red" );
         f.bad.push( btoa(t) );
         GM_setValue("filter", JSON.stringify( f ));
         $('#bad_n').text(f.bad.length);
      }
    });
  });
})();