Bierdopje Billboard Randomizer

Randomizes the billboard on the homepage.

当前为 2016-11-03 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Bierdopje Billboard Randomizer
// @namespace    http://www.bierdopje.com
// @version      1.1
// @description  Randomizes the billboard on the homepage.
// @match        http://*.bierdopje.com/
// @run-at       document-start
// @grant        unsafeWindow
// @require      http://code.jquery.com/jquery-1.10.2.js
// @author       Tom
// @copyright    2016+, Tom
// ==/UserScript==
/* jshint -W097 */
/* global $, console */
'use strict';

console.log("Bierdopje billboard randomizer ready to rock and roll");

var ROTATION_SPEED = 7500; // ms. Default value: 7500. Recommended: 4000 ~ 10000
var TOTAL_BOARDS = $("#billboard div").size();

$(function() {
	preInit();
	
	function preInit() {
		stopDefaultBillboardBehavior();
		hideDefaultBillboard();
		setInitialBillboard();
	}
	
	function stopDefaultBillboardBehavior() {
		for (var i = 1; i <= 10; i++) {
			window.clearInterval(i);
		}
	}
	
	function hideDefaultBillboard() {
		$("#billboard div:eq(0)").hide();
		$("#billboardtext div:eq(0)").hide();
	}
	
	function setInitialBillboard() {
		var random = Math.floor(Math.random() * TOTAL_BOARDS);
		
		$("#billboard div:eq(" + random + ")").show();
		$("#billboardtext div:eq(" + random + ")").show();
	}
});

$(window).load(function() {
	postInit();
	
	function postInit() {
		setInterval(showNextItemOnBillboard, ROTATION_SPEED);
	}

	function showNextItemOnBillboard() {
		var currentBoardImage = $("#billboard div:visible");
		var currentBoardText = $("#billboardtext div:visible");
		var nextRandomBoard = Math.floor(Math.random() * TOTAL_BOARDS);

		currentBoardText.slideUp("slow", function() {
			$("#billboard div:eq(" + nextRandomBoard + ")").animate({
				width: 'show'
			}, 'slow', function() {
				currentBoardImage.fadeOut("slow", function() {
					$("#billboardtext div:eq(" + nextRandomBoard + ")").slideDown("slow");
				});
			});
		});
	}
});