/*
* @title <marquee> scramble
* @description イメージ→ https://www.google.co.jp/maps/@35.659457,139.70051,3a,75y,135.41h,84.12t/data=!3m4!1e1!3m2!1sdJ-QZu5MLMbtAfqyoN4ShQ!2e0
* @include http://*
* @license MIT License
* @javascript_url
*/
(function() {
function randomDirection() {
var directions = ['left', 'right', 'up', 'down'];
return directions[Math.floor(Math.random() * 4)];
}
function randomBehavior(direction) {
if (direction == 'up' || direction == 'down') {
return 'scroll';
} else {
var behaviors = ['alternate', 'scroll'];
return behaviors[Math.floor(Math.random() * 2)];
}
}
function marquee(tagName) {
var elements = document.getElementsByTagName(tagName);
for (var i = 0,length = elements.length; i < length; i++) {
var children = elements[i].querySelectorAll(tagName);
if (!elements[i].hasAttribute('data-marquished') && (children == null || children.length == 0)) {
var parent = elements[i].parentNode;
var marquee = document.createElement('marquee');
var direction = randomDirection();
marquee.setAttribute('scrollamount', '15');
marquee.setAttribute('direction', direction);
marquee.setAttribute('behavior', randomBehavior(direction));
parent.insertBefore(marquee, elements[i]);
marquee.appendChild(elements[i]);
elements[i].setAttribute('data-marquished', 'true');
}
}
}
function marqueeScramble() {
var tags = ['div', 'p', 'ul', 'table', 'a', 'iframe', 'dt', 'dd', 'img', 'h1', 'h2', 'h3', 'h4', 'h5', 'span'];
for (var i = 0; i < tags.length; i++) {
marquee(tags[i]);
}
}
marqueeScramble();
var timer = 0;
document.addEventListener('DOMNodeInserted', function() {
if(timer) return;
timer = setTimeout(function() {
marqueeScramble();
timer = 0;
}, 500);
}, false);
}());