Send Skype Credit+

Speed up process sending skype credit: removed animation and remembering settings for each person.

目前為 2020-05-26 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Send Skype Credit+
// @namespace   V@no
// @author      V@no
// @description Speed up process sending skype credit: removed animation and remembering settings for each person.
// @include     https://secure.skype.com/send-credit
// @version     1.0
// @license     MIT
// @grant       none
// ==/UserScript==

function $$(o)
{
	return document.getElementById(o);
}

function pref(id, data)
{
	if (typeof(data) == "undefined")
	{
		return prefs[id];
	}
	prefs[id] = data;
	pref.save();
}

pref.load = function()
{
	let p = ls("pref");
			r = _prefs.clone();

	if (!p || typeof(p) != "object")
		p = r;

	for(let i in r)
	{
		if (typeof(r[i]) == typeof(p[i]))
			r[i] = p[i];
	}
	return r;
}

pref.save = function()
{
	ls("pref", prefs);
}

function ls(id, data, stringify)
{
	let r;
	if (typeof(data) == "undefined")
	{
		r = localStorage.getItem(id);
		try
		{
			r = JSON.parse(r);
		}
		catch(e)
		{
			log(e);
			log([id, data, r]);
		}
		return r;
	}

	if (typeof(stringify) == "undefined" || stringify)
		data = JSON.stringify(data);

	r = localStorage.setItem(id, data);
	return r;
}

function rand(min, max)
{
	return Math.floor(Math.random() * (max - min + 1)) + min;
}

Object.prototype.clone = function()
{
	return Object.assign({}, this);
}

Array.prototype.clone = function()
{
	return Object.assign([], this);
}

function load()
{
	let l = ls("last"),
			r = listDefault.clone();

	if (!l || typeof(l) != "object")
		l = {};

	if (!l.n)
		l.n = "";

	if (!l[l.n])
		l[l.n] = r;

	for (let m in l)
	{
		if (["n", "clone"].indexOf(m) != -1)
			continue;

		let d = l[m];
		if (Array.isArray(d))
		{
			for(let i = 0; i < r.length; i++)
			{
				if (typeof(d[i]) == typeof(r[i]))
					r[i] = d[i];
			}
			l[m] = d;
		}
		else
			l[m] = r;
	}
	return l;
}

function save()
{
	ls("last", list);
}

function getId(o)
{
	if (!o)
		return;

	if(!o.id || !o.id.match("contactListId-"))
		return getId(o.parentNode);

	return o.id.replace("contactListId-", "");
}

let log = console.log.bind(console),
		listDefault = [2, 0],
		_prefs = {},
		prefs = pref.load(),
		list = load(),
		prevId,
		scope = this,
		func = loop1,
		o = {};


if ($ && $.fn)
{
	$.fn.animate = function(){};
}

//type username
function loop1()
{
	let obj = $$("quickFilterInput"),
			oe = $$("searchOptions"),
			f = arguments.callee,
			n = f.name;

	function c()
	{
		let f,i = 2;

		while(typeof(f=scope["loop"+i++]) == "function")
		{
			f();
		}
		prevId = list.n;
	}

	if (oe && !oe._inited)
	{
		oe.addEventListener("mousedown", function(e)
		{
			if (!e.isTrusted)
				return;

			let id = getId(e.target);
			if (!id)
				return;

			list.n = id;
			if (!list[id])
				list[id] = listDefault.clone();

			delete list[""];
			save();
			prevId = null;
			func = f;
		}, true);
		oe._inited = true;
	}

	if (!obj)
		return c();

	if (obj.value == "" && !o[n])
	{
		obj.value = list.n;
		obj.dispatchEvent(new KeyboardEvent('keydown',{'key':'Shift'}));
		o[n] = obj;
	}
	c();
}

//pick user from list
function loop2()
{
	let f = arguments.callee,
			n = f.name,
			obj = $$("contactListId-" + list.n) || o[n];

	if (!obj)
		return;

	o[n] = obj;
	if (list[list.n])
		obj.dispatchEvent(new MouseEvent('mousedown',{'button':0}));
}

function findChild(obj, parent)
{
	if (!obj || !parent || obj == parent)
		return null;

	if (obj.parentNode == parent)
		return obj;

	return findChild(obj.parentNode, parent);
}
//select amount
function loop3()
{
	let f = arguments.callee,
			n = f.name,
			obj = $$("offer-selection");

	if (!obj)
		return;

	if (!obj._inited)
	{
		if (list[list.n][0] < 0 || list[list.n][0] > obj.children.length - 1)
			list[list.n][0] = obj.children - 1;

		obj.children[list[list.n][0]].click();
		obj.addEventListener("click", function(e)
		{
			if (!e.isTrusted)
				return;

			let c = findChild(e.target, obj),
					i = -1;

			if (c === null)
				return;

			while(obj.children[++i] != c);
			list[list.n][0] = i;
			save();
		}, true);
		obj._inited = true;
	}
	o[n] = obj;
}

//select design
function loop4()
{
	let f = arguments.callee,
			n = f.name,
			obj = document.querySelector(".form-area.gift-card-holder") || o[n];

	if (!obj)
		return;

	if (!obj._inited)
	{
		let cb = document.createElement("input"),
				box = document.createElement("label"),
				index = 0;

		if (list[list.n][1] < 0 || list[list.n][1] > obj.children.length)
			list[list.n][1] = 0;

		function sel()
		{
			if (cb.checked)
			{
				let i;
				while((i=rand(0, obj.children.length-1)) == index);
				index = i;
			}
			else
				index = list[list.n][1]-1;

			obj.children[index].click();
		}

		cb.type = "checkbox";
		cb.checked = list[list.n][1] ? false : true;
		cb.addEventListener("input", function(e)
		{
			if (!cb.checked)
				list[list.n][1] = index + 1;

			sel();
		}, false);
		sel();
		box.appendChild(cb);
		box.appendChild(document.createTextNode("Random"));
		obj.parentNode.insertBefore(box, obj);
		obj.addEventListener("click", function(e)
		{
			if (!e.isTrusted && cb.checked)
			{
				list[list.n][1] = 0;
			}
			else
			{
				let c = findChild(e.target, obj),
						i = -1;

				if (c === null)
					return;

				while(obj.children[++i] != c);

				list[list.n][1] = i + 1;
				index = i;
			}
			if (e.isTrusted)
				cb.checked = list[list.n][1] ? false : true;

			save();
		}, true);
		obj._inited = true;
	}
	o[n] = obj;
}

//click confirm
function loop5()
{
	let f = arguments.callee,
			n = f.name,
			obj = $$("send-money");

	if (!obj)
		return;

	if (!obj._inited || prevId != list.n)
	{
		setTimeout(function()
		{
			obj.scrollIntoView(false);
			func = null;
		}, 500);
		obj._inited = true;
	}
	o[n] = obj;
//	obj.click();
}

//css
let css = document.createElement("style");
css.innerHTML = `
.offer-item
{
	height: unset;
	padding-top: 5px;
	padding-bottom: 5px;
}
.gift-card-span
{
	max-width: 22%;
	left: unset !important;
	right: unset !important;
	margin-top: unset;
}
.offers-footer,
.content-wrapper,
#amount-selector > div.row
{
	padding: 10px;
}
.gift-card-holder
{
	margin-top: 0.2em;
}

#design-selector > h3
{
	display: inline-block;
}
#design-selector > label
{
	float: right;
	line-height: initial;
	margin: 0;
	padding: 0;
	color: initial;
	font-weight: initial;
	width: initial;
}
#design-selector > label,
#design-selector > label > input
{
	cursor: pointer;
}
`;
document.head.appendChild(css);

//main loop
!function loop()
{
	if (func)
	{
//log(func && func.name);
		func();
	}
	setTimeout(loop, rand(0, 1000));
}();