summaryrefslogtreecommitdiff
path: root/share/frontend/js/titleScrambler.js
blob: 6948cbffb7e8cd8b50073705a2c33d9897069a53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var titleSwitch = true;
var FillerChars = [ "(",")","|","1","4","\\", "9","_" ];
var titleArray = document.title.split("");
var titleArrayCopy = titleArray.slice(0);
var titleLength = titleArray.length

function marqueeArray(arr){
  var first = arr[0]
  arr.shift()
}

function replaceArray(arr, char){
  arr[randomChoice(arr)] = char
}
var titleUpdateInterval = 300
function randomChoice(arr){
  var rand = Math.random();
  rand *= arr.length;
  rand = Math.floor(rand)
  return rand;
}
var titleUpdate = setInterval(function(){
    if (titleSwitch === true){ 
    marqueeArray(titleArray); 
    document.title = titleArray.join("")
    if (titleArray.length === 1){
      document.title = "";
      titleArray = titleArrayCopy.slice(0);
      document.title = titleArray.join("");
      if (titleSwitch){
        titleSwitch = false;
      }else{
        titleSwitch = true;
        titleUpdateInterval = 100;
      }
    } 
    }else{

    replaceArray(titleArray, FillerChars[randomChoice(FillerChars)]);
    document.title = titleArray.join("")
    if (titleArray[(titleArray.length-1)] in FillerChars){
      console.log("it's in there");
      titleArray = titleArrayCopy.slice(0);
      document.title = titleArray.join("");
      if (titleSwitch){
        titleSwitch = false;
        titleUpdateInterval = 300;
      }else{
        titleSwitch = true;
      }
      
    }
  } 
    
  }, titleUpdateInterval);