steamgifts.com improved game filter

Makes hiding giveaways for specific games much quicker and easier

当前为 2015-06-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        steamgifts.com improved game filter
// @description Makes hiding giveaways for specific games much quicker and easier
// @namespace   Barefoot Monkey
// @include     http://www.steamgifts.com/
// @include     http://www.steamgifts.com/giveaways/search?*
// @version     1.1.2
// @grant       none
// ==/UserScript==

$('<style>')
.text(
	'@keyframes rotate-right-60px {'
	+'	from {'
	+'		background-position: 0px 0;'
	+'	}'
	+'	to {'
	+'		background-position: 300px 0;'
	+'	}'
	+'}'

	+'@keyframes rotate-left-60px {'
	+'	from {'
	+'		background-position: 0px 0;'
	+'	}'
	+'	to {'
	+'		background-position: -300px 0;'
	+'	}'
	+'}'

	+'.giveaway__row-outer-wrap {'
	+'	transition: opacity 1s linear;'
	+'}'

	+'.BarefootMonkey-hidden {'
	+'	opacity: 0.6;'
	+'	background: repeating-linear-gradient(45deg, transparent 0px, transparent 10px, #ccc 10px, #ccc 12px, transparent 12px), repeating-linear-gradient(-45deg, transparent 0px, transparent 10px, #ccc 10px, #ccc 12px, transparent 12px);'
	+'}'

	+'.BarefootMonkey-hiding, .BarefootMonkey-unhiding {'
	+'	opacity: 0.6;'
	+'	animation-duration: 12s;'
	+'	animation-iteration-count: infinite;'
	+'	animation-timing-function: linear;'
	+'}'

	+'.BarefootMonkey-hiding {'
	+'	animation-name: rotate-right-60px;'
	+'	background: repeating-linear-gradient(45deg, transparent 0px, transparent 10px, #ccc 10px, #ccc 12px);'
	+'}'

	+'.BarefootMonkey-unhiding {'
	+'	animation-name: rotate-left-60px;'
	+'	background: repeating-linear-gradient(-45deg, transparent 0px, transparent 10px, #ccc 10px, #ccc 12px);'
	+'}'
)
.appendTo(document.head)

setTimeout(function() {

	function update_filter(id, token, action, url, prior_class, progress_class, complete_class) {
		$('.giveaway__icon.giveaway__hide[data-popup="popup--hide-games"][data-game-id='+id+']')
		.closest('.giveaway__row-outer-wrap')
		.addClass(progress_class)
		.removeClass('BarefootMonkey-error')
		.removeClass(prior_class)

		$.ajax({
			url: url,
			method: 'POST',
			context: {id: id, progress_class: progress_class, complete_class: complete_class},
			data: {
				'xsrf_token':token,
				'game_id':id,
				'do': action
			},
			'error': function() {
				$('.giveaway__icon.giveaway__hide[data-popup="popup--hide-games"][data-game-id='+this.id+']')
				.closest('.giveaway__row-outer-wrap')
				.removeClass(this.progress_class)
				.addClass('BarefootMonkey-error')
			},
			'success': function() {
				$('.giveaway__icon.giveaway__hide[data-popup="popup--hide-games"][data-game-id='+this.id+']')
				.closest('.giveaway__row-outer-wrap')
				.removeClass(this.progress_class)
				.addClass(this.complete_class)
			}
		})
	}

	$('.giveaway__icon.giveaway__hide')
	.off()
	.click(function(event) {

		// get id and token
		var id = $(this).data('game-id')
		var token = $('.popup--hide-games form input[name="xsrf_token"]').val()

		// hide or unhide the game
		if (id && token) {
			var closest = $(this).closest('.giveaway__row-outer-wrap')
			if (closest.hasClass('BarefootMonkey-hidden')) {
				update_filter(id, token, 'remove_filter', '/ajax.php', 'BarefootMonkey-hidden', 'BarefootMonkey-unhiding', null)
			} else if (!closest.hasClass('BarefootMonkey-unhiding') && !closest.hasClass('BarefootMonkey-hiding')) {
				update_filter(id, token, 'hide_giveaways_by_game_id', '/', null, 'BarefootMonkey-hiding', 'BarefootMonkey-hidden')
			}
		}

		event.stopPropagation()
	})
}, 1)