Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name New Userscript
- // @namespace http://tampermonkey.net/
- // @version 0.1
- // @description try to take over the world!
- // @author You
- // @match https://www.nextinpact.com/
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- //###########
- var addStyle =function(){
- /*
- add new style to document head
- */
- var cssTodaySubtitle='.TodaySubtitle{color:#ea7e19}';
- var head=document.head;
- var style=document.createElement('style');
- head.appendChild(style);
- }
- var today = new Date();
- // todayStr fomat : "dd/mm/yyyy -"
- var todayStr=(today.toLocaleString('fr-FR', { timeZone: 'UTC' })).substring(0,10)+ " -"
- var isToday=function(dateStr){
- /*
- return if dateStr correspond to today date
- */
- return dateStr==todayStr;
- }
- var applyTodayModif=function(sbtDateElem){
- /*
- apply modification on sbtDateElem elem.
- */
- sbtDateElem.innerHTML='<span class="TodaySubtitle">Aujourd\'hui -';
- }
- var modifTodayDate=function(sbtDateElem){
- /*
- apply modification on sbtDateElem elem if sbtDateElem correspond to today date.
- */
- var dateStr=sbtDateElem.innerHTML;
- if(isToday(dateStr)){
- applyTodayModif(sbtDateElem);
- }
- }
- //###########
- //add style to document
- addStyle()
- //add obserder to modify date as soon as document is modify
- var observed=document;
- var observeOpt={childList: true, substree: true};
- var observerFunc=function(mutations){
- /*
- find all subtitle dates elem in document and apply modification if this elem correspond to today date
- */
- var subtitleDates=document.querySelectorAll(".subtitle span");
- for(let i=0; i<subtitleDates.length; i++){
- modifTodayDate(subtitleDates[i])
- }
- }
- //apply a first the the observFunc if page is already load.
- // XXX : because JavaScript is monothread, this should be directly followed by the observer.
- observerFunc(null);
- //look for modification in observed to change if necessary
- //FIXME : may be launched 2 times in a row, because the modification may be also observed
- var mutationObs1=new MutationObserver(observerFunc).observe(observed, observeOpt);
- })();
Add Comment
Please, Sign In to add comment