-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvr.js
81 lines (73 loc) · 2.62 KB
/
vr.js
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
const V = "https://www.youtube.com/watch?v=oHg5SJYRHA0";
const VD = 1;
const VM = 4;
if(Storage && window.localStorage && window.localStorage instanceof Storage) {
// Check if it's 1st of April
var date = new Date();
// Note that months are zero indexed
if(date.getDate() == VD && date.getMonth() == VM-1) {
// If local storage does not work, rickroll will simply never occur
// this is a safety measure to prevent people being rickrolled forever
localStorage.LOCAL_STORAGE_WORKS = true;
// This will be called as an on click handler for anchor elements
function rickroller(event) {
//console.info("Rickrolling!");
if(localStorage.VAt) {
//console.warn("Rickrolling canceled!");
return true;
}
// Remember that user was rickrolled
localStorage.VAt = new Date().getTime();
event.preventDefault();
// New tab links go to a new tab
if(this.target=="_blank") {
window.open(V);
}
else
window.location.href = V;
return false;
}
if(localStorage.LOCAL_STORAGE_WORKS && !localStorage.VAt) {
var ar=[];
//console.info("Initiating rickroll!");
// Get all links as an array
ar.push.apply(ar, document.querySelectorAll("a"));
ar.forEach((link)=>{
// Skip links that do not lead outside
if(link.href.indexOf("http")!=0&&link.href.indexOf("//")!=0) {
//console.log(link.href, link.href.indexOf("http"), link.href.indexOf("//"));
return;
}
link.addEventListener("click", rickroller);
});
}
else {
//console.info("Já foi rickrolled hoje, perdeu a graça!");
}
}
else {
// console.info("Não é primeiro de abril :(", date.getDate(),date.getMonth());
}
}
else {
//console.warn("Local storage === false");
}
// Alternative RR
var pattern = ['r', 'i', 'c', 'k'];
var current = 0;
var keyHandler = function (event) {
// If the key isn't in the pattern, or isn't the current key in the pattern, reset
if (pattern.indexOf(event.key) < 0 || event.key !== pattern[current]) {
current = 0;
return;
}
// Update how much of the pattern is complete
current++;
// If complete, alert and reset
if (pattern.length === current) {
current = 0;
window.location.href = V
}
};
// Listen for keydown events
document.addEventListener('keydown', keyHandler, false);