randomizeFCs

randomize names and FCs for planets.nu and replaces the builtin random generator

2016-03-13 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name          randomizeFCs
//
// @description   randomize names and FCs for planets.nu and replaces the builtin random generator
// 				  to eliminate command codes it only replaces FCs in the format 0a0.
// 				  ship names get changed only if they contain capital letters.
//
// @include       http://play.planets.nu/*
// @include 	  http://test.planets.nu/*
// @include 	  http://planets.nu/*
// @version       3.0.0
// @namespace     https://greasyfork.org/en/users/32642-stephen-piper
// ==/UserScript==

function wrapper() {

	function setRandom() {
	}
	setRandom.prototype = {

		loadControls : function() {
			// debugger;

			vgapMap.prototype.spMenuItem("Random FCs", "randomFC", function() {
				setRandom.prototype.setRandomFC();
			});

			vgapMap.prototype.spMenuItem("Random Ship Names", "randomShipName",
					function() {
						setRandom.prototype.setRandomShipNames();
					});
		},

		setRandomFC : function() {
			for (var i = 0; i < vgap.planets.length; ++i) {
				var planet = vgap.planets[i];
				if (vgap.player.id == planet.ownerid && planet.readystatus == 0) {
					if (planet.friendlycode == /[0-9][a-zA-Z][0-9]/) {
						planet.friendlycode = vgaPlanets.randomFC();
						planet.changed = true;
					}
				}
				;
			}
			for (var i = 0; i < vgap.ships.length; ++i) {
				var ship = vgap.ships[i];
				if (vgap.player.id == ship.ownerid && ship.readystatus == 0) {
					if (ship.friendlycode == /[0-9][a-zA-Z][0-9]/) {
						ship.friendlycode = vgaPlanets.randomFC();
						ship.changed = true;
					}
				}
				;
			}

			vgap.indicator.text("done");
			vgap.indicateOn();
		},

		setRandomShipNames : function() {
			var url = "http://api.wordnik.com:80/v4/words.json/randomWord";
			var data = {
				"hasDictionaryDef" : "true",
				"includePartOfSpeech" : "verb-intransitive",
				"minLength" : "5",
				"maxLength" : "16",
				"limit" : "1",
				"api_key" : "a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5",
			};
			var pat = /.*?[A-Z]/;

			for (var i = 0; i < vgap.ships.length; ++i) {
				var ship = vgap.ships[i];
				if (vgap.player.id == ship.ownerid && pat.test(ship.name)) {
					$.ajax({
						async : false,
						type : 'GET',
						url : url,
						data : data,
						success : function(data) {
							ship.name = data.word;
							ship.changed = 1;
						}
					});
				}
			}

			vgap.indicator.text("done");
			vgap.indicateOn();
		},

	};

	var oldRandomFC = vgaPlanets.prototype.randomFC;
	vgaPlanets.prototype.randomFC = function() {
		var c = "";
		c += Math.floor(Math.random() * 9);

		var b = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
		c += b.charAt(Math.floor(Math.random() * b.length)) // vgap generator
															// can generate
															// commands

		c += Math.floor(Math.random() * 9);

		return c
	};

	var oldLoadControls = vgapMap.prototype.loadControls;
	vgapMap.prototype.loadControls = function() {
		oldLoadControls.apply(this, arguments);

		setRandom.prototype.loadControls();
	};
};

var script = document.createElement("script");
script.type = "application/javascript";
script.textContent = "(" + wrapper + ")();";

document.body.appendChild(script);