Last active
November 5, 2018 15:43
-
-
Save vladimirmyshkovski/1bef0fc5de39b189db6dbda72fe860ba to your computer and use it in GitHub Desktop.
Стадный инстинкт :)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cScriptLoader = (function () { | |
function cScriptLoader(files) { | |
var _this = this; | |
this.log = function (t) { | |
console.log("ScriptLoader: " + t); | |
}; | |
this.withNoCache = function (filename) { | |
if (filename.indexOf("?") === -1) | |
filename += "?no_cache=" + new Date().getTime(); | |
else | |
filename += "&no_cache=" + new Date().getTime(); | |
return filename; | |
}; | |
this.loadStyle = function (filename) { | |
// HTMLLinkElement | |
var link = document.createElement("link"); | |
link.rel = "stylesheet"; | |
link.type = "text/css"; | |
link.href = _this.withNoCache(filename); | |
_this.log('Loading style ' + filename); | |
link.onload = function () { | |
_this.log('Loaded style "' + filename + '".'); | |
}; | |
link.onerror = function () { | |
_this.log('Error loading style "' + filename + '".'); | |
}; | |
_this.m_head.appendChild(link); | |
}; | |
this.loadScript = function (i) { | |
var script = document.createElement('script'); | |
script.type = 'text/javascript'; | |
script.src = _this.withNoCache(_this.m_js_files[i]); | |
var loadNextScript = function () { | |
if (i + 1 < _this.m_js_files.length) { | |
_this.loadScript(i + 1); | |
} | |
}; | |
script.onload = function () { | |
_this.log('Loaded script "' + _this.m_js_files[i] + '".'); | |
loadNextScript(); | |
}; | |
script.onerror = function () { | |
_this.log('Error loading script "' + _this.m_js_files[i] + '".'); | |
loadNextScript(); | |
}; | |
_this.log('Loading script "' + _this.m_js_files[i] + '".'); | |
_this.m_head.appendChild(script); | |
}; | |
this.loadFiles = function () { | |
// this.log(this.m_css_files); | |
// this.log(this.m_js_files); | |
for (var i = 0; i < _this.m_css_files.length; ++i) | |
_this.loadStyle(_this.m_css_files[i]); | |
_this.loadScript(0); | |
}; | |
this.m_js_files = []; | |
this.m_css_files = []; | |
this.m_head = document.getElementsByTagName("head")[0]; | |
// this.m_head = document.head; // IE9+ only | |
function endsWith(str, suffix) { | |
if (str === null || suffix === null) | |
return false; | |
return str.indexOf(suffix, str.length - suffix.length) !== -1; | |
} | |
for (var i = 0; i < files.length; ++i) { | |
if (endsWith(files[i], ".css")) { | |
this.m_css_files.push(files[i]); | |
} else if (endsWith(files[i], ".js")) { | |
this.m_js_files.push(files[i]); | |
} else | |
this.log('Error unknown filetype "' + files[i] + '".'); | |
} | |
} | |
return cScriptLoader; | |
})(); | |
var maleNamesArray = ['Никита', 'Константин', 'Алексей']; | |
var femaleNamesArray = ['Ольга', 'Илона', 'Евгения']; | |
var namesArray = maleNamesArray.concat(femaleNamesArray); | |
function getArrayRandomElement(arr) { | |
if (arr && arr.length) { | |
return arr[Math.floor(Math.random() * arr.length)]; | |
} | |
// The undefined will be returned if the empty array was passed | |
} | |
function getRandomName() { | |
return getArrayRandomElement(namesArray); | |
} | |
function getRandomArbitrary(min, max) { | |
return Math.random() * (max - min) + min; | |
} | |
function setZIndex() { | |
elements = document.getElementsByClassName("toastify"); | |
for (var i = 0; i < elements.length; i++) { | |
elements[i].style.zIndex = "999"; | |
} | |
} | |
function showTooltip() { | |
var randomName = getRandomName(); | |
Toastify({ | |
text: randomName + " купил(а) программу", | |
duration: 3000, | |
// destination: "", | |
newWindow: true, | |
close: true, | |
gravity: "bottom", // `top` or `bottom` | |
positionLeft: false, // `true` or `false` | |
backgroundColor: "linear-gradient(to right, #00b09b, #96c93d)", | |
}).showToast(); | |
} | |
(function loop() { | |
// var rand = Math.round(Math.random() * (3000 - 500)) + 500; | |
var randomInt = getRandomArbitrary(3000, 6000) | |
setTimeout(function () { | |
showTooltip(); | |
setZIndex(); | |
loop(); | |
}, randomInt); | |
}()); | |
var ScriptLoader = new cScriptLoader([ | |
"https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css", | |
"https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.js" | |
]); | |
ScriptLoader.loadFiles(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment