Guest User

Untitled

a guest
Aug 13th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         New Userscript
  3. // @namespace    http://tampermonkey.net/
  4. // @version      0.1
  5. // @description  try to take over the world!
  6. // @author       You
  7. // @match        https://www.nextinpact.com/
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.     'use strict';
  13.  
  14.     //###########
  15.  
  16.     var addStyle =function(){
  17.         /*
  18.         add new style to document head
  19.         */
  20.         var cssTodaySubtitle='.TodaySubtitle{color:#ea7e19}';
  21.         var head=document.head;
  22.         var style=document.createElement('style');
  23.         head.appendChild(style);
  24.     }
  25.  
  26.     var today = new Date();
  27.     // todayStr fomat : "dd/mm/yyyy -"
  28.     var todayStr=(today.toLocaleString('fr-FR', { timeZone: 'UTC' })).substring(0,10)+ " -"
  29.  
  30.     var isToday=function(dateStr){
  31.         /*
  32.         return if dateStr correspond to today date
  33.         */
  34.         return dateStr==todayStr;
  35.     }
  36.  
  37.     var applyTodayModif=function(sbtDateElem){
  38.         /*
  39.         apply modification on sbtDateElem elem.
  40.         */
  41.         sbtDateElem.innerHTML='<span class="TodaySubtitle">Aujourd\'hui -';
  42.     }
  43.  
  44.     var modifTodayDate=function(sbtDateElem){
  45.         /*
  46.         apply modification on sbtDateElem elem if sbtDateElem correspond to today date.
  47.         */
  48.         var dateStr=sbtDateElem.innerHTML;
  49.         if(isToday(dateStr)){
  50.             applyTodayModif(sbtDateElem);
  51.         }
  52.     }
  53.  
  54.     //###########
  55.  
  56.     //add style to document
  57.     addStyle()
  58.     //add obserder to modify date as soon as document is modify
  59.     var observed=document;
  60.     var observeOpt={childList: true, substree: true};
  61.     var observerFunc=function(mutations){
  62.         /*
  63.         find all subtitle dates elem in document and apply modification if this elem correspond to today date
  64.         */
  65.         var subtitleDates=document.querySelectorAll(".subtitle span");
  66.         for(let i=0; i<subtitleDates.length; i++){
  67.             modifTodayDate(subtitleDates[i])
  68.         }
  69.     }
  70.     //apply a first the the observFunc if page is already load.
  71.     // XXX : because JavaScript is monothread, this should be directly followed by the observer.
  72.     observerFunc(null);
  73.     //look for modification in observed to change if necessary
  74.     //FIXME : may be launched 2 times in a row, because the modification may be also observed
  75.     var mutationObs1=new MutationObserver(observerFunc).observe(observed, observeOpt);
  76. })();
  77.  
Add Comment
Please, Sign In to add comment