Greasy Fork is available in English.
Speed up process sending skype credit: removed animation and remembering settings for each person.
当前为
// ==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.2.3
// @license MIT
// @grant none
// ==/UserScript==
var log = console.log.bind(console),
listDefault = [2, 1],
list = {},
prevId,
noAuto,
running,
observer = new MutationObserver(function(mutations, observer)
{
if (running || noAuto)
return;
running = true;
let f,i = 1;
for(let f in func)
{
func[f]();
}
prevId = list.n;
running = false;
}),
func = {
//input username
func1: function func1()
{
let qf = $$("quickFilterInput"),
oe = $$("searchOptions"),
ih = document.querySelector("div.input-holder"),
bh = $$("clearFilterInput");
function click(e)
{
if (!e.isTrusted)
return;
noAuto = true;
if (e.target.id == "clearFilterInput" || e.target.parentNode.id == "clearFilterInput")
{
list.n = "";
save();
}
}
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();
save();
prevId = null;
noAuto = false;
}, true);
oe._inited = true;
}
if (ih && !ih._inited)
{
ih.addEventListener("click", click, true);
ih._inited = true;
}
if (bh && !bh._inited)
{
bh.addEventListener("click", click, true);
bh._inited = true;
}
if (qf && !qf._inited)
{
if (!noAuto && qf.value == "")
{
qf.value = list.n;
qf.dispatchEvent(new KeyboardEvent('keydown',{'key':'Shift'}));
}
qf._inited = true;
}
},//func1()
//pick user from list
func2: function func2()
{
let obj = $$("contactListId-" + list.n);
if (!obj || !list[list.n])
return;
obj.dispatchEvent(new MouseEvent('mousedown',{'button':0}));
},//func2()
//select amount
func3: function func3()
{
let obj = $$("offer-selection");
if (!obj || obj._inited || !obj.children.length || !list[list.n])
return;
if (list[list.n][0] < 0 || list[list.n][0] > obj.children.length - 1)
list[list.n][0] = obj.children.length - 1;
//log(list[list.n]);
try
{
obj.children[list[list.n][0]].click();
}
catch(e)
{
console.error(e);
log(list[list.n]);
}
obj.addEventListener("click", function(e)
{
if (!e.isTrusted)
return;
let c = findParent(e.target, obj),
i = -1;
if (c === null)
return;
while(obj.children[++i] != c);
if (!list[list.n])
return;
list[list.n][0] = i;
save();
}, true);
obj._inited = true;
},//func3()
//select design
func4: function func4()
{
let obj = document.querySelector(".form-area.gift-card-holder");
if (!obj || !list[list.n] || !obj.children.length)
return;
if (!obj._inited)
{
let cb = document.createElement("input"),
box = document.createElement("label"),
r, //previous random index
p = {
get s(){return list[list.n]},
get m(){return obj.children.length - 1},
get i(){return Math.min(this.m, Math.max((this.s[1] >> 1) - 1, 0))},
set i(d){this.s[1] = (this.s[1] & 1) | (++d << 1)},
get r(){return this.s[1] & 1 ? true : false},
set r(d)
{
if (d)
this.s[1] |= 1;
else
this.s[1] &= ~1;
}
},
//s = true: don't all current index get selected again
sel = function (s)
{
let i = p.i;
if (cb.checked)
{
let n = i;
if (!s)
n = r;
while((i = rand(0, p.m)) == n || i == r);
r = i;
// i = rand(0, p.m);
}
if (obj.children[i])
obj.children[i].click();
};
cb.type = "checkbox";
cb.checked = p.r;
cb.addEventListener("change", function(e)
{
p.r = cb.checked;
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)
{
p.r = true;
}
else
{
let c = findParent(e.target, obj),
i = -1;
if (c === null)
return;
while(obj.children[++i] != c);
p.i = i;
p.r = cb.checked = false;
}
save();
}, true);
obj._inited = true;
}
},//func4()
//click confirm
func5: function func5()
{
let obj = $$("send-money");
if (!obj)
return;
if (!obj._inited || prevId != list.n)
{
setTimeout(function()
{
obj.scrollIntoView(false);
}, 300);
obj._inited = true;
}
// obj.click();
}//func5()
};//func
function $$(o)
{
return document.getElementById(o);
}
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;
}
function load()
{
let l = ls("last"),
r = listDefault.clone();
if (!l || typeof(l) != "object")
l = {};
if (!l.n)
l.n = "";
if (!l[l.n])
return l;
for (let m in l)
{
if (m == "n")
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-", "");
}
function findParent(obj, parent)
{
if (!obj || !parent || obj == parent)
return null;
if (obj.parentNode == parent)
return obj;
return findParent(obj.parentNode, parent);
}
!function init()
{
Object.defineProperty(Object.prototype, "clone", {
value: function()
{
return Object.assign({}, this);
}
});
Object.defineProperty(Array.prototype, "clone", {
value: function()
{
return Object.assign([], this);
}
});
if ($ && $.fn)
{
$.fn.animate = function(){};
}
list = load();
observer.observe($$("container"), {
subtree: true,
childList: true
});
return true;
}()
//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;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
#design-selector > label,
#design-selector > label > input
{
cursor: pointer;
}
#design-selector > label > input
{
-webkit-appearance: checkbox;
}
`;
document.head.appendChild(css);