Quick debug

Quick inject scripts/style to current page.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         Quick debug
// @run-at       document-start
// @namespace    org.jixun.quick.debug
// @version      1.0.0.2
// @description  Quick inject scripts/style to current page.
// @author       Jixun
// @include      *
// @grant        none
// ==/UserScript==

(function () {

var extend = function (src) {
	if (arguments.length <= 1)
		return src;

	var args = [].slice.call(arguments, 1);
	for (var i = 0; i<args.length; i++) {
		var obj = args[i];

		for (var key in obj) {
			if (!obj.hasOwnProperty (key))
				continue;

			if ('object' == typeof obj[key] && !obj[key].map) {
				if (!src[key]) src[key] = {};

				extend(src[key], obj[key]);
				continue;
			}

			src[key] = obj[key];
		}
	}

	return src;
};

window.QuickDebug = window._QD = function () {
	this._QD.script.jQuery();
};

extend (window._QD, {
	script: function (str) {
		var $src = this.script;

		(	this.isUrl(str)
			? $src.url
			: $src.text
		).apply($src, arguments);
	},

	css: function (str) {
		var $src = this.css;

		(	this.isUrl(str)
			? $src.url
			: $src.text
		).apply($src, arguments);
	},

	isUrl: function (str) {
		return /^(https?\:\/\/|\.|\/)/.test(str);
	}
});

extend(window._QD.script, {
	url: function (url, ver, onload) {
		var s = document.createElement('script');
		url = url.replace('%ver', ver);

		s.src = url;
		s.onload = function () {
			console.info ('Script loaded: %s', url);

			onload && onload();
		};
		document.head.appendChild(s);
	},

	text: function (text) {
		var s = document.createElement('script');
		s.textContent = text;
		document.head.appendChild(s);
	},

	jQuery: function (ver) {
		this.url ('https://code.jquery.com/jquery-%ver.js', ver || 'latest');
	},

	vue: function (ver) {
		this.url ('https://cdnjs.cloudflare.com/ajax/libs/vue/%ver/vue.js', ver || '0.11.4');
	},

	bootstrap: function (ver) {
		if (!window.jQuery) this.jQuery();

		this.url ('https://maxcdn.bootstrapcdn.com/bootstrap/%ver/css/bootstrap.min.css', ver || '3.3.1');
	},

	mathJax: function (config) {
		this.url ('https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=%ver',
			config || 'TeX-AMS-MML_HTMLorMML');
	}
});

extend(window._QD.css, {
	url: function (url, ver, onload) {
		var s = document.createElement('link');
		url = url.replace('%ver', ver);

		s.rel = 'stylesheet';
		s.href = url;
		s.onload = function () {
			console.info ('Style loaded: %s', url);

			onload && onload();
		};
		document.head.appendChild(s);
	},

	text: function (text) {
		var s = document.createElement('style');
		s.textContent = text;
		document.head.appendChild(s);
	},

	bootstrap: function (ver) {
		this.url ('https://maxcdn.bootstrapcdn.com/bootstrap/%ver/css/bootstrap.min.css', ver || '3.3.1');
	}
});


})();