Skip to content

Commit

Permalink
Improve easter egg
Browse files Browse the repository at this point in the history
  • Loading branch information
ganlvtech committed May 14, 2019
1 parent e93cc36 commit eb87695
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 40 deletions.
65 changes: 28 additions & 37 deletions src/easter-eggs/halloween.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,57 @@
import toastr from 'toastr';

const STYLESHEET = {
0: `
transition: `
body, body * {
transition: color 2s, background-color 2s, border-color 2s;
-moz-transition: color 2s, background-color 2s, border-color 2s;
-webkit-transition: color 2s, background-color 2s, border-color 2s;
-o-transition: color 2s, background-color 2s, border-color 2s;
}`,

1000: `
}
`,
bodyBlack: `
body {
background-color: #000;
}`,

2000: `
allBlack: `
body * {
background-color: transparent !important;
color: #fff !important;
border-color: #fff !important;
}
.breadcrumb {
box-shadow: inset 0 0 0px 1px;
}`
}
};

function addStyle(css) {
let style = document.createElement('style');
style.type = 'text/css';

if (style.styleSheet) { // IE
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}

style.appendChild(document.createTextNode(css));
document.getElementsByTagName('head')[0].appendChild(style);

return style;
}

export function init() {
setTimeout(function() {
addStyle(STYLESHEET[0]);
function enableTransition() {
addStyle(STYLESHEET.transition);
}

setTimeout(function() {
let style = addStyle(STYLESHEET[1000]);
let bodyBlackStyleElement;

let loop = function() {
style.remove();
function setBodyBlack() {
bodyBlackStyleElement = addStyle(STYLESHEET.bodyBlack);
}

setTimeout(function() {
style = addStyle(STYLESHEET[1000]);
function setAllBlack() {
addStyle(STYLESHEET.allBlack);
}

setTimeout(loop, 10000);
}, 2000);
};
setTimeout(loop, 10000);
function toast() {
toastr.info('Happy Halloween!');
}

setTimeout(function() {
addStyle(STYLESHEET[2000]);
setTimeout(function() {
toastr.info('Happy Halloween!');
}, 1000);
}, 2000);
}, 2000);
}, 0);
export function init() {
enableTransition();
setTimeout(setBodyBlack, 2000);
setTimeout(setAllBlack, 4000);
setTimeout(toast, 5000);
}
6 changes: 3 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ require('bootstrap');

window.Down52PojieCn = Down52PojieCn;

(function() {
(function () {
const moment = require('moment');
let date = moment().format("MMDD")
if (date === '1030' || date === '1031' || date === '1101') {
let date = moment().format('MMDD');
if (date === '0401' || date === '1030' || date === '1031' || date === '1101') {
const halloween = require('./easter-eggs/halloween');
halloween.init();
}
Expand Down

0 comments on commit eb87695

Please sign in to comment.