Advertisement
Guest User

DresdenBacklight

a guest
Jul 18th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name DresdenBacklight
  3. // @namespace Violentmonkey Scripts
  4. // @grant none
  5. // ==/UserScript==
  6.  
  7. const whiteColor = '#ffffff'
  8.  
  9. function findPlace() {
  10.  
  11.     let currentPlace = document.getElementsByName('freeTimeContainer:free_time.place')[0];
  12.  
  13.     if (typeof(currentPlace) !== 'undefined') {
  14.  
  15.         currentPlace = currentPlace.selectedIndex;
  16.  
  17.         for (let obj in arrayForPlaces) {
  18.             if (currentPlace === arrayForPlaces[obj].idPlace) {
  19.                 backlighting(arrayForPlaces[obj].timeTOPlay, arrayForPlaces[obj].color);
  20.             }
  21.         }
  22.     }
  23. }
  24.  
  25. function backlighting(userWord, color) {
  26.  
  27.     let word = userWord;
  28.     let queue = [document.body];
  29.     let curr;
  30.     while (curr = queue.pop()) {
  31.         if (!curr.textContent.match(word)) continue;
  32.         for (let i = 0; i < curr.childNodes.length; ++i) {
  33.             switch (curr.childNodes[i].nodeType) {
  34.                 case Node.TEXT_NODE : // 3
  35.                     if (curr.childNodes[i].textContent.match(word)) {
  36.                         console.log("Found!");
  37.                         console.log(curr);
  38.                         curr.style.background = color;
  39.                     }
  40.                     break;
  41.                 case Node.ELEMENT_NODE : // 1
  42.                     queue.push(curr.childNodes[i]);
  43.                     break;
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49. let arrayForPlaces = [{
  50.     idPlace: 14,
  51.     timeTOPlay: '19:30 - 20:00',
  52.     color: whiteColor
  53. },
  54.     {
  55.         idPlace: 15,
  56.         timeTOPlay: '20:30 - 21:00',
  57.         color: whiteColor
  58.     },
  59.     {
  60.         idPlace: 16,
  61.         timeTOPlay: '21:30 - 22:00',
  62.         color: whiteColor
  63.     }, {
  64.         idPlace: 28,
  65.         timeTOPlay: '18:30 - 19:00',
  66.         color: whiteColor
  67.     }];
  68.  
  69. findPlace();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement