Advertisement
wagner-cipriano

NBA Calendar - Games of the day

Feb 17th, 2023 (edited)
1,189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         NBA Day Calendar
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://jumperbrasil.lance.com.br/calendario-transmissoes-nba-brasil/
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=lance.com.br
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. const removeElements = function() {
  13.     let ad_container = document.querySelectorAll('.pp-paywall__container')[0];
  14.     let ad_backgroun = document.querySelectorAll('.pp-paywall__background')[0];
  15.     if(ad_container) ad_container.parentElement?.removeChild(ad_container);
  16.     if(ad_backgroun) ad_backgroun.parentElement?.removeChild(ad_backgroun);
  17. }
  18.  
  19. const setDateFunctions = function() {
  20.     Date.prototype.getMonthName = function() {
  21.         var monthNames = [ "Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho",
  22.                           "Julho", "Agosto", "Setembro", "Outubro", "Novembro", "Dezembro" ];
  23.         return monthNames[this.getMonth()];
  24.     }
  25.     Date.prototype.getDateBr = function() {
  26.         const dia = this.getDate().toString();
  27.         const diaF = (dia.length == 1) ? '0'+dia : dia;
  28.         const mes = (this.getMonth()+1).toString();
  29.         const mesF = (mes.length == 1) ? '0'+mes : mes;
  30.         const anoF = this.getFullYear().toString().substr(2,2);
  31.         return diaF+"/"+mesF+"/"+anoF;
  32.     }
  33. }
  34.  
  35. const getDateContent = function(datebr) {
  36.     let dcontent = null;
  37.     var dTags = document.getElementsByTagName("p");
  38.     for (var i = 0; i < dTags.length; i++) {
  39.         if (dTags[i].textContent.indexOf(datebr) != -1) {
  40.             dcontent = dTags[i];
  41.             break;
  42.         }
  43.     }
  44.     return dcontent;
  45. }
  46.  
  47. const getDayCalendar = function(dcontent, datebr) {
  48.     let day_calendar = null;
  49.     let day_anchor = null;
  50.     if(dcontent) {
  51.         console.log(dcontent);
  52.         dcontent.scrollIntoView();
  53.  
  54.         for (var i = 0; i < dcontent.childNodes.length; i++) {
  55.             if(dcontent.childNodes[i].data && dcontent.childNodes[i].data.indexOf(datebr) != -1) {
  56.                 day_calendar = dcontent.childNodes[i];
  57.                 break;
  58.             } else if (dcontent.childNodes[i].tagName?.toUpperCase() == 'BR') {
  59.                 day_anchor?.scrollIntoView();
  60.                 day_anchor = dcontent.childNodes[i];
  61.             }
  62.         }
  63.         console.log(day_calendar);
  64.     }
  65.     return day_calendar;
  66. }
  67.  
  68. const setHighlightContent = function(day_calendar) {
  69.     let div = document.createElement('DIV');
  70.     div.style = "color:white;background-color:#ed3833";
  71.     div.innerHTML = day_calendar.textContent;
  72.     day_calendar.previousSibling.insertAdjacentElement('afterend', div);
  73.     day_calendar.parentElement.removeChild(day_calendar)
  74. };
  75.  
  76. const letsgo = function(){
  77.     console.log('Onload disparado');
  78.     //Get Date Now
  79.     setDateFunctions();
  80.     const date = new Date();
  81.     let month = date.getMonthName();
  82.     let datebr = date.getDateBr();
  83.     console.log('NBA Day Calendar --> Date:', month, datebr);
  84.  
  85.     //Get Date content
  86.     let dcontent = getDateContent(datebr);
  87.     if (!dcontent) {
  88.         window.alert('Nao temos jogos nesta data: (' + datebr + ').\nVai trabalhar ou estudar meu caro!');
  89.         return false;
  90.     }
  91.     console.log('NBA Day Calendar --> DateContent: ', dcontent);
  92.  
  93.     //Get Day Calendar
  94.     let day_calendar = getDayCalendar(dcontent, datebr);
  95.     console.log('NBA Day Calendar --> DayCalendar: ', day_calendar);
  96.  
  97.     //Destak content
  98.     setHighlightContent(day_calendar);
  99.  
  100.     //Remove Elements
  101.     setTimeout(function() {
  102.         removeElements();
  103.         console.log('NBA Day Calendar --> removeElements Ok');
  104.     }, 10000);
  105. }
  106.  
  107. letsgo();
Tags: diW
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement