draggable_DC

Make DC's windows draggable

От 03.06.2014. Виж последната версия.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey, Greasemonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да инсталирате разширение, като например Tampermonkey .

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Violentmonkey.

За да инсталирате този скрипт, трябва да имате инсталирано разширение като Tampermonkey или Userscripts.

За да инсталирате скрипта, трябва да инсталирате разширение като Tampermonkey.

За да инсталирате този скрипт, трябва да имате инсталиран скриптов мениджър.

(Вече имам скриптов мениджър, искам да го инсталирам!)

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да инсталирате разширение като Stylus.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

За да инсталирате този стил, трябва да имате инсталиран мениджър на потребителски стилове.

(Вече имам инсталиран мениджър на стиловете, искам да го инсталирам!)

// ==UserScript==
// @name		draggable_DC
// @author		Ladoria
// @version		0.17
// @grant       none
// @description	Make DC's windows draggable
// @match		http://www.dreadcast.net/Main
// @require     http://code.jquery.com/jquery-latest.min.js
// @copyright	2012+, Ladoria
// @namespace GTFO
// ==/UserScript==

// DEBUG Don't touch those damn things!
var global_debug = false;
// /DEBUG

jQuery.noConflict();

$(document).ready( function() {
	 // need that to let the javascript display all element after the 'ready' state of the DOM
	setTimeout( function() {
		// initials values saving
		zone_gauche_initiale_offset = $('#zone_gauche').offset();
		zone_droite_initiale_offset = $('#zone_droite').offset();
		db_combat_initiale_offset = $('#db_combat').offset();
		
		zone_gauche_initial_bacgroundColor = $('#zone_gauche').css('backgroundColor');
		zone_droite_initial_bacgroundColor = $('#zone_droite').css('backgroundColor');
		zone_informations_lieu_initial_bacgroundColor = $('#zone_information').css('backgroundColor');
		zone_informations_combat_initial_bacgroundColor = $('#zone_informations_combat').css('backgroundColor');
		db_combat_initial_bacgroundColor = $('#db_combat').css('backgroundColor');
		
		$('#zone_gauche').addClass("DC_draggable");
		$('#zone_centre').addClass("DC_draggable");
		$('#zone_droite').addClass("DC_draggable");
		$('#zone_informations_lieu').addClass("DC_draggable");
		$('#zone_informations_combat').addClass("DC_draggable");
		$('#db_combat').addClass("DC_draggable");
		
		// ugly selectors
		$('#zone_gauche div').first().before('<div style="height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_gauche" class="DC_draggable"></div>');
		
		$('#zone_droite div').first().before('<div style="height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_droite" class="DC_draggable"></div>');
		
		$('#zone_informations_lieu div').first().before('<div style="top:-11px;left:-15px;height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_informations_lieu" class="DC_draggable"></div>');
		
		$('#zone_informations_combat div').first().before('<div style="top:-11px;left:-15px;height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="zone_informations_combat" class="DC_draggable"></div>');
		
		$('#db_combat #combat_equipes').first().before('<div style="top:-71px;left:-10px;height:0px;width:0px;margin-right:-13px;z-index:999999;"><input type="checkbox" name="db_combat" class="DC_draggable"></div>');
		
		var zIndex = 310000;
		var dragging = false;
		
		var backgroundColor = new Array();
		backgroundColor['zone_gauche'] = $('#zone_gauche').css('backgroundColor');
		backgroundColor['zone_droite'] = $('#zone_droite').css('backgroundColor');
		backgroundColor['zone_informations_lieu'] = $('#zone_information').css('backgroundColor');
		backgroundColor['zone_informations_combat'] = $('#zone_informations_combat').css('backgroundColor');
		backgroundColor['db_combat'] = $('#db_combat').css('backgroundColor');
		
		var isDraggable = new Array();
		isDraggable['zone_gauche'] = false;
		isDraggable['zone_droite'] = false;
		isDraggable['zone_centre'] = false; //desactivated 'cause no checkbox
		isDraggable['zone_informations_lieu'] = false;
		isDraggable['zone_informations_combat'] = false;
		isDraggable['db_combat'] = false;
		
		var zone_droite_draggable = false;
		var zone_informations_lieu_draggable = false;

		function enableDrag(id) {
			$('#' + id).draggable();
			$('#' + id).css('cursor','move');
			isDraggable[id] = true;
		}
		function disableDrag(id) {
			$('#' + id).draggable("destroy");
			$('#' + id).addClass("");
			$('#' + id).css('cursor','auto');
			isDraggable[id] = false;
		}

		$('input[type=checkbox].DC_draggable').click( function() {
			if($(this).is(':checked'))
				enableDrag($(this).attr('name'));
			else
				disableDrag($(this).attr('name'));
		});

		$('.DC_draggable:not(input[type=checkbox])').dblclick( function() {
			if(isDraggable[$(this).attr('id')]) {
				switch($(this).attr('id')) {
					case 'zone_gauche' :
						$('#zone_gauche').offset(zone_gauche_initiale_offset);
						break;
					case 'zone_droite' :
						$('#zone_droite').offset(zone_droite_initiale_offset);
						break;
					case 'db_combat' :
						$('#db_combat').offset(db_combat_initiale_offset);
						break;
					case 'zone_informations_lieu' :
						$('#zone_informations_lieu').css('top','auto');
						$('#zone_informations_lieu').css('bottom','10px');
						$('#zone_informations_lieu').css('left','10px');
						break;
					case 'zone_informations_combat' :
						$('#zone_informations_combat').css('top','auto');
						$('#zone_informations_combat').css('bottom','10px');
						$('#zone_informations_combat').css('left','10px');
						break;
					default: break;
				}
			}
		});

		$('.DC_draggable:not(input[type=checkbox])').mousedown( function() {
			zIndex++;
			$('#' + $(this).attr('id')).zIndex(zIndex);
		});

		$('.DC_draggable:not(input[type=checkbox])').mouseup( function() {
			if(dragging) {
				dragging = false;
				
				$('#' + $(this).attr('id')).css('backgroundColor', backgroundColor[$(this).attr('id')]);
			}
		});

		$('.DC_draggable:not(input[type=checkbox])').bind('drag', function(event) {
			if(isDraggable[$(this).attr('id')]) {
				dragging = true;
				$('#' + $(this).attr('id')).css('backgroundColor','rgba(172, 0, 0, 0.6)');
				
				if('zone_informations_lieu' == $(this).attr('id')) {
					$('#zone_informations_lieu').css('position','absolute');
					$('#zone_informations_lieu').css('bottom','auto');
				}
				if('zone_informations_combat' == $(this).attr('id')) {
					$('#zone_informations_combat').css('position','absolute');
					$('#zone_informations_combat').css('bottom','auto');
				}
			}
		});
	}, 1000);
});