Merge branch 'v3' of git://github.com/MayhemYDG/4chan-x into v3
Conflicts: src/features.coffee src/lib/$.coffee
This commit is contained in:
commit
128a5ef40f
@ -299,6 +299,59 @@
|
||||
posts: {}
|
||||
};
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
};
|
||||
|
||||
String.prototype.contains = function(string) {
|
||||
return this.indexOf(string) > -1;
|
||||
};
|
||||
|
||||
Array.prototype.add = function(object, position) {
|
||||
var keep;
|
||||
|
||||
keep = this.slice(position);
|
||||
this.length = position;
|
||||
this.push(object);
|
||||
return this.pushArrays(keep);
|
||||
};
|
||||
|
||||
Array.prototype.contains = function(object) {
|
||||
return this.indexOf(object) > -1;
|
||||
};
|
||||
|
||||
Array.prototype.indexOf = function(object) {
|
||||
var i;
|
||||
|
||||
i = this.length;
|
||||
while (i--) {
|
||||
if (this[i] === object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
Array.prototype.pushArrays = function() {
|
||||
var arg, args, _i, _len;
|
||||
|
||||
args = arguments;
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
this.push.apply(this, arg);
|
||||
}
|
||||
};
|
||||
|
||||
Array.prototype.remove = function(object) {
|
||||
var index;
|
||||
|
||||
if ((index = this.indexOf(object)) > -1) {
|
||||
return this.splice(index, 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
@ -306,15 +359,6 @@
|
||||
return root.querySelector(selector);
|
||||
};
|
||||
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||
|
||||
$$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
}
|
||||
return __slice.call(root.querySelectorAll(selector));
|
||||
};
|
||||
|
||||
$.extend = function(object, properties) {
|
||||
var key, val;
|
||||
|
||||
@ -327,63 +371,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
$.extend(Array.prototype, {
|
||||
add: function(object, position) {
|
||||
var keep;
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||
|
||||
keep = this.slice(position);
|
||||
this.length = position;
|
||||
this.push(object);
|
||||
return this.pushArrays(keep);
|
||||
},
|
||||
contains: function(object) {
|
||||
return this.indexOf(object) > -1;
|
||||
},
|
||||
indexOf: function(object) {
|
||||
var i;
|
||||
|
||||
i = this.length;
|
||||
while (i--) {
|
||||
if (this[i] === object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
},
|
||||
pushArrays: function() {
|
||||
var arg, args, _i, _len;
|
||||
|
||||
args = arguments;
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
this.push.apply(this, arg);
|
||||
}
|
||||
},
|
||||
remove: function(object) {
|
||||
var index;
|
||||
|
||||
if ((index = this.indexOf(object)) > -1) {
|
||||
return this.splice(index, 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.extend(String.prototype, {
|
||||
capitalize: function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
},
|
||||
contains: function(string) {
|
||||
return this.indexOf(string) > -1;
|
||||
}
|
||||
});
|
||||
|
||||
$.extend($, {
|
||||
id: function(id) {
|
||||
$.id = function(id) {
|
||||
return d.getElementById(id);
|
||||
},
|
||||
ready: function(fc) {
|
||||
};
|
||||
|
||||
$.ready = function(fc) {
|
||||
var cb, _ref;
|
||||
|
||||
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
||||
@ -395,8 +389,9 @@
|
||||
return fc();
|
||||
};
|
||||
return $.on(d, 'DOMContentLoaded', cb);
|
||||
},
|
||||
formData: function(form) {
|
||||
};
|
||||
|
||||
$.formData = function(form) {
|
||||
var fd, key, val;
|
||||
|
||||
if (form instanceof HTMLFormElement) {
|
||||
@ -415,8 +410,9 @@
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
},
|
||||
ajax: function(url, callbacks, opts) {
|
||||
};
|
||||
|
||||
$.ajax = function(url, callbacks, opts) {
|
||||
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
||||
|
||||
if (opts == null) {
|
||||
@ -436,8 +432,9 @@
|
||||
r.withCredentials = cred;
|
||||
r.send(form);
|
||||
return r;
|
||||
},
|
||||
cache: (function() {
|
||||
};
|
||||
|
||||
$.cache = (function() {
|
||||
var reqs;
|
||||
|
||||
reqs = {};
|
||||
@ -472,8 +469,9 @@
|
||||
req.callbacks = [cb];
|
||||
return reqs[url] = req;
|
||||
};
|
||||
})(),
|
||||
cb: {
|
||||
})();
|
||||
|
||||
$.cb = {
|
||||
checked: function() {
|
||||
$.set(this.name, this.checked);
|
||||
return Conf[this.name] = this.checked;
|
||||
@ -482,15 +480,17 @@
|
||||
$.set(this.name, this.value.trim());
|
||||
return Conf[this.name] = this.value;
|
||||
}
|
||||
},
|
||||
asap: function(test, cb) {
|
||||
};
|
||||
|
||||
$.asap = function(test, cb) {
|
||||
if (test()) {
|
||||
return cb();
|
||||
} else {
|
||||
return setTimeout($.asap, 25, test, cb);
|
||||
}
|
||||
},
|
||||
addStyle: function(css, id) {
|
||||
};
|
||||
|
||||
$.addStyle = function(css, id) {
|
||||
var style;
|
||||
|
||||
style = $.el('style', {
|
||||
@ -503,28 +503,35 @@
|
||||
return $.add(d.head, style);
|
||||
});
|
||||
return style;
|
||||
},
|
||||
x: function(path, root) {
|
||||
};
|
||||
|
||||
$.x = function(path, root) {
|
||||
root || (root = d.body);
|
||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||
},
|
||||
X: function(path, root) {
|
||||
};
|
||||
|
||||
$.X = function(path, root) {
|
||||
root || (root = d.body);
|
||||
return d.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
},
|
||||
addClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.addClass = function(el, className) {
|
||||
return el.classList.add(className);
|
||||
},
|
||||
rmClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.rmClass = function(el, className) {
|
||||
return el.classList.remove(className);
|
||||
},
|
||||
toggleClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.toggleClass = function(el, className) {
|
||||
return el.classList.toggle(className);
|
||||
},
|
||||
hasClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.hasClass = function(el, className) {
|
||||
return el.classList.contains(className);
|
||||
},
|
||||
rm: (function() {
|
||||
};
|
||||
|
||||
$.rm = (function() {
|
||||
if ('remove' in Element.prototype) {
|
||||
return function(el) {
|
||||
return el.remove();
|
||||
@ -536,21 +543,25 @@
|
||||
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
||||
};
|
||||
}
|
||||
})(),
|
||||
rmAll: function(root) {
|
||||
})();
|
||||
|
||||
$.rmAll = function(root) {
|
||||
var node;
|
||||
|
||||
while (node = root.firstChild) {
|
||||
root.removeChild(node);
|
||||
}
|
||||
},
|
||||
tn: function(s) {
|
||||
};
|
||||
|
||||
$.tn = function(s) {
|
||||
return d.createTextNode(s);
|
||||
},
|
||||
frag: function() {
|
||||
};
|
||||
|
||||
$.frag = function() {
|
||||
return d.createDocumentFragment();
|
||||
},
|
||||
nodes: function(nodes) {
|
||||
};
|
||||
|
||||
$.nodes = function(nodes) {
|
||||
var frag, node, _i, _len;
|
||||
|
||||
if (!(nodes instanceof Array)) {
|
||||
@ -562,23 +573,29 @@
|
||||
frag.appendChild(node);
|
||||
}
|
||||
return frag;
|
||||
},
|
||||
add: function(parent, el) {
|
||||
};
|
||||
|
||||
$.add = function(parent, el) {
|
||||
return parent.appendChild($.nodes(el));
|
||||
},
|
||||
prepend: function(parent, el) {
|
||||
};
|
||||
|
||||
$.prepend = function(parent, el) {
|
||||
return parent.insertBefore($.nodes(el), parent.firstChild);
|
||||
},
|
||||
after: function(root, el) {
|
||||
};
|
||||
|
||||
$.after = function(root, el) {
|
||||
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
||||
},
|
||||
before: function(root, el) {
|
||||
};
|
||||
|
||||
$.before = function(root, el) {
|
||||
return root.parentNode.insertBefore($.nodes(el), root);
|
||||
},
|
||||
replace: function(root, el) {
|
||||
};
|
||||
|
||||
$.replace = function(root, el) {
|
||||
return root.parentNode.replaceChild($.nodes(el), root);
|
||||
},
|
||||
el: function(tag, properties) {
|
||||
};
|
||||
|
||||
$.el = function(tag, properties) {
|
||||
var el;
|
||||
|
||||
el = d.createElement(tag);
|
||||
@ -586,8 +603,9 @@
|
||||
$.extend(el, properties);
|
||||
}
|
||||
return el;
|
||||
},
|
||||
on: function(el, events, handler) {
|
||||
};
|
||||
|
||||
$.on = function(el, events, handler) {
|
||||
var event, _i, _len, _ref;
|
||||
|
||||
_ref = events.split(' ');
|
||||
@ -595,8 +613,9 @@
|
||||
event = _ref[_i];
|
||||
el.addEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
off: function(el, events, handler) {
|
||||
};
|
||||
|
||||
$.off = function(el, events, handler) {
|
||||
var event, _i, _len, _ref;
|
||||
|
||||
_ref = events.split(' ');
|
||||
@ -604,8 +623,9 @@
|
||||
event = _ref[_i];
|
||||
el.removeEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
event: function(event, detail, root) {
|
||||
};
|
||||
|
||||
$.event = function(event, detail, root) {
|
||||
if (root == null) {
|
||||
root = d;
|
||||
}
|
||||
@ -613,8 +633,9 @@
|
||||
bubbles: true,
|
||||
detail: detail
|
||||
}));
|
||||
},
|
||||
open: (function() {
|
||||
};
|
||||
|
||||
$.open = (function() {
|
||||
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
||||
return function(URL) {
|
||||
var a;
|
||||
@ -629,8 +650,9 @@
|
||||
return window.open(URL, '_blank');
|
||||
};
|
||||
}
|
||||
})(),
|
||||
debounce: function(wait, fn) {
|
||||
})();
|
||||
|
||||
$.debounce = function(wait, fn) {
|
||||
var args, exec, that, timeout;
|
||||
|
||||
timeout = null;
|
||||
@ -650,8 +672,9 @@
|
||||
}
|
||||
return timeout = setTimeout(exec, wait);
|
||||
};
|
||||
},
|
||||
queueTask: (function() {
|
||||
};
|
||||
|
||||
$.queueTask = (function() {
|
||||
var execTask, taskChannel, taskQueue;
|
||||
|
||||
taskQueue = [];
|
||||
@ -676,8 +699,9 @@
|
||||
return setTimeout(execTask, 0);
|
||||
};
|
||||
}
|
||||
})(),
|
||||
globalEval: function(code) {
|
||||
})();
|
||||
|
||||
$.globalEval = function(code) {
|
||||
var script;
|
||||
|
||||
script = $.el('script', {
|
||||
@ -685,8 +709,9 @@
|
||||
});
|
||||
$.add(d.head || doc, script);
|
||||
return $.rm(script);
|
||||
},
|
||||
bytesToString: function(size) {
|
||||
};
|
||||
|
||||
$.bytesToString = function(size) {
|
||||
var unit;
|
||||
|
||||
unit = 0;
|
||||
@ -696,12 +721,15 @@
|
||||
}
|
||||
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
||||
return "" + size + " " + ['B', 'KB', 'MB', 'GB'][unit];
|
||||
},
|
||||
minmax: function(value, min, max) {
|
||||
};
|
||||
|
||||
$.minmax = function(value, min, max) {
|
||||
return (value < min ? min : value > max ? max : value);
|
||||
},
|
||||
syncing: {},
|
||||
sync: (function() {
|
||||
};
|
||||
|
||||
$.syncing = {};
|
||||
|
||||
$.sync = (function() {
|
||||
window.addEventListener('storage', function(e) {
|
||||
var cb;
|
||||
|
||||
@ -712,23 +740,21 @@
|
||||
return function(key, cb) {
|
||||
return $.syncing[g.NAMESPACE + key] = cb;
|
||||
};
|
||||
})(),
|
||||
item: function(key, val) {
|
||||
})();
|
||||
|
||||
$.item = function(key, val) {
|
||||
var item;
|
||||
|
||||
item = {};
|
||||
item[key] = val;
|
||||
return item;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
(function() {
|
||||
var scriptStorage;
|
||||
var cb, items, key, keys, scriptStorage, _i, _len;
|
||||
|
||||
scriptStorage = opera.scriptStorage;
|
||||
$["delete"] = function(keys) {
|
||||
var key, _i, _len;
|
||||
|
||||
$["delete"] = function(keys) {};
|
||||
if (!(keys instanceof Array)) {
|
||||
keys = [keys];
|
||||
}
|
||||
@ -738,10 +764,8 @@
|
||||
localStorage.removeItem(key);
|
||||
delete scriptStorage[key];
|
||||
}
|
||||
};
|
||||
$.get = function(key, val, cb) {
|
||||
var items;
|
||||
|
||||
return;
|
||||
$.get = function(key, val, cb) {};
|
||||
if (typeof cb === 'function') {
|
||||
items = $.item(key, val);
|
||||
} else {
|
||||
@ -749,6 +773,8 @@
|
||||
cb = val;
|
||||
}
|
||||
return $.queueTask(function() {
|
||||
var val;
|
||||
|
||||
for (key in items) {
|
||||
if (val = scriptStorage[g.NAMESPACE + key]) {
|
||||
items[key] = JSON.parse(val);
|
||||
@ -756,8 +782,9 @@
|
||||
}
|
||||
return cb(items);
|
||||
});
|
||||
};
|
||||
return $.set = (function() {
|
||||
})();
|
||||
|
||||
$.set = (function() {
|
||||
var set;
|
||||
|
||||
set = function(key, val) {
|
||||
@ -781,7 +808,13 @@
|
||||
}
|
||||
};
|
||||
})();
|
||||
})();
|
||||
|
||||
$$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
}
|
||||
return __slice.call(root.querySelectorAll(selector));
|
||||
};
|
||||
|
||||
Build = {
|
||||
spoilerRange: {},
|
||||
|
||||
@ -296,6 +296,59 @@
|
||||
posts: {}
|
||||
};
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
};
|
||||
|
||||
String.prototype.contains = function(string) {
|
||||
return this.indexOf(string) > -1;
|
||||
};
|
||||
|
||||
Array.prototype.add = function(object, position) {
|
||||
var keep;
|
||||
|
||||
keep = this.slice(position);
|
||||
this.length = position;
|
||||
this.push(object);
|
||||
return this.pushArrays(keep);
|
||||
};
|
||||
|
||||
Array.prototype.contains = function(object) {
|
||||
return this.indexOf(object) > -1;
|
||||
};
|
||||
|
||||
Array.prototype.indexOf = function(object) {
|
||||
var i;
|
||||
|
||||
i = this.length;
|
||||
while (i--) {
|
||||
if (this[i] === object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
Array.prototype.pushArrays = function() {
|
||||
var arg, args, _i, _len;
|
||||
|
||||
args = arguments;
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
this.push.apply(this, arg);
|
||||
}
|
||||
};
|
||||
|
||||
Array.prototype.remove = function(object) {
|
||||
var index;
|
||||
|
||||
if ((index = this.indexOf(object)) > -1) {
|
||||
return this.splice(index, 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
@ -303,15 +356,6 @@
|
||||
return root.querySelector(selector);
|
||||
};
|
||||
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||
|
||||
$$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
}
|
||||
return __slice.call(root.querySelectorAll(selector));
|
||||
};
|
||||
|
||||
$.extend = function(object, properties) {
|
||||
var key, val;
|
||||
|
||||
@ -324,63 +368,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
$.extend(Array.prototype, {
|
||||
add: function(object, position) {
|
||||
var keep;
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||
|
||||
keep = this.slice(position);
|
||||
this.length = position;
|
||||
this.push(object);
|
||||
return this.pushArrays(keep);
|
||||
},
|
||||
contains: function(object) {
|
||||
return this.indexOf(object) > -1;
|
||||
},
|
||||
indexOf: function(object) {
|
||||
var i;
|
||||
|
||||
i = this.length;
|
||||
while (i--) {
|
||||
if (this[i] === object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
},
|
||||
pushArrays: function() {
|
||||
var arg, args, _i, _len;
|
||||
|
||||
args = arguments;
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
this.push.apply(this, arg);
|
||||
}
|
||||
},
|
||||
remove: function(object) {
|
||||
var index;
|
||||
|
||||
if ((index = this.indexOf(object)) > -1) {
|
||||
return this.splice(index, 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.extend(String.prototype, {
|
||||
capitalize: function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
},
|
||||
contains: function(string) {
|
||||
return this.indexOf(string) > -1;
|
||||
}
|
||||
});
|
||||
|
||||
$.extend($, {
|
||||
id: function(id) {
|
||||
$.id = function(id) {
|
||||
return d.getElementById(id);
|
||||
},
|
||||
ready: function(fc) {
|
||||
};
|
||||
|
||||
$.ready = function(fc) {
|
||||
var cb, _ref;
|
||||
|
||||
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
||||
@ -392,8 +386,9 @@
|
||||
return fc();
|
||||
};
|
||||
return $.on(d, 'DOMContentLoaded', cb);
|
||||
},
|
||||
formData: function(form) {
|
||||
};
|
||||
|
||||
$.formData = function(form) {
|
||||
var fd, key, val;
|
||||
|
||||
if (form instanceof HTMLFormElement) {
|
||||
@ -412,8 +407,9 @@
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
},
|
||||
ajax: function(url, callbacks, opts) {
|
||||
};
|
||||
|
||||
$.ajax = function(url, callbacks, opts) {
|
||||
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
||||
|
||||
if (opts == null) {
|
||||
@ -433,8 +429,9 @@
|
||||
r.withCredentials = cred;
|
||||
r.send(form);
|
||||
return r;
|
||||
},
|
||||
cache: (function() {
|
||||
};
|
||||
|
||||
$.cache = (function() {
|
||||
var reqs;
|
||||
|
||||
reqs = {};
|
||||
@ -469,8 +466,9 @@
|
||||
req.callbacks = [cb];
|
||||
return reqs[url] = req;
|
||||
};
|
||||
})(),
|
||||
cb: {
|
||||
})();
|
||||
|
||||
$.cb = {
|
||||
checked: function() {
|
||||
$.set(this.name, this.checked);
|
||||
return Conf[this.name] = this.checked;
|
||||
@ -479,15 +477,17 @@
|
||||
$.set(this.name, this.value.trim());
|
||||
return Conf[this.name] = this.value;
|
||||
}
|
||||
},
|
||||
asap: function(test, cb) {
|
||||
};
|
||||
|
||||
$.asap = function(test, cb) {
|
||||
if (test()) {
|
||||
return cb();
|
||||
} else {
|
||||
return setTimeout($.asap, 25, test, cb);
|
||||
}
|
||||
},
|
||||
addStyle: function(css, id) {
|
||||
};
|
||||
|
||||
$.addStyle = function(css, id) {
|
||||
var style;
|
||||
|
||||
style = $.el('style', {
|
||||
@ -500,28 +500,35 @@
|
||||
return $.add(d.head, style);
|
||||
});
|
||||
return style;
|
||||
},
|
||||
x: function(path, root) {
|
||||
};
|
||||
|
||||
$.x = function(path, root) {
|
||||
root || (root = d.body);
|
||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||
},
|
||||
X: function(path, root) {
|
||||
};
|
||||
|
||||
$.X = function(path, root) {
|
||||
root || (root = d.body);
|
||||
return d.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
},
|
||||
addClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.addClass = function(el, className) {
|
||||
return el.classList.add(className);
|
||||
},
|
||||
rmClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.rmClass = function(el, className) {
|
||||
return el.classList.remove(className);
|
||||
},
|
||||
toggleClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.toggleClass = function(el, className) {
|
||||
return el.classList.toggle(className);
|
||||
},
|
||||
hasClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.hasClass = function(el, className) {
|
||||
return el.classList.contains(className);
|
||||
},
|
||||
rm: (function() {
|
||||
};
|
||||
|
||||
$.rm = (function() {
|
||||
if ('remove' in Element.prototype) {
|
||||
return function(el) {
|
||||
return el.remove();
|
||||
@ -533,21 +540,25 @@
|
||||
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
||||
};
|
||||
}
|
||||
})(),
|
||||
rmAll: function(root) {
|
||||
})();
|
||||
|
||||
$.rmAll = function(root) {
|
||||
var node;
|
||||
|
||||
while (node = root.firstChild) {
|
||||
root.removeChild(node);
|
||||
}
|
||||
},
|
||||
tn: function(s) {
|
||||
};
|
||||
|
||||
$.tn = function(s) {
|
||||
return d.createTextNode(s);
|
||||
},
|
||||
frag: function() {
|
||||
};
|
||||
|
||||
$.frag = function() {
|
||||
return d.createDocumentFragment();
|
||||
},
|
||||
nodes: function(nodes) {
|
||||
};
|
||||
|
||||
$.nodes = function(nodes) {
|
||||
var frag, node, _i, _len;
|
||||
|
||||
if (!(nodes instanceof Array)) {
|
||||
@ -559,23 +570,29 @@
|
||||
frag.appendChild(node);
|
||||
}
|
||||
return frag;
|
||||
},
|
||||
add: function(parent, el) {
|
||||
};
|
||||
|
||||
$.add = function(parent, el) {
|
||||
return parent.appendChild($.nodes(el));
|
||||
},
|
||||
prepend: function(parent, el) {
|
||||
};
|
||||
|
||||
$.prepend = function(parent, el) {
|
||||
return parent.insertBefore($.nodes(el), parent.firstChild);
|
||||
},
|
||||
after: function(root, el) {
|
||||
};
|
||||
|
||||
$.after = function(root, el) {
|
||||
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
||||
},
|
||||
before: function(root, el) {
|
||||
};
|
||||
|
||||
$.before = function(root, el) {
|
||||
return root.parentNode.insertBefore($.nodes(el), root);
|
||||
},
|
||||
replace: function(root, el) {
|
||||
};
|
||||
|
||||
$.replace = function(root, el) {
|
||||
return root.parentNode.replaceChild($.nodes(el), root);
|
||||
},
|
||||
el: function(tag, properties) {
|
||||
};
|
||||
|
||||
$.el = function(tag, properties) {
|
||||
var el;
|
||||
|
||||
el = d.createElement(tag);
|
||||
@ -583,8 +600,9 @@
|
||||
$.extend(el, properties);
|
||||
}
|
||||
return el;
|
||||
},
|
||||
on: function(el, events, handler) {
|
||||
};
|
||||
|
||||
$.on = function(el, events, handler) {
|
||||
var event, _i, _len, _ref;
|
||||
|
||||
_ref = events.split(' ');
|
||||
@ -592,8 +610,9 @@
|
||||
event = _ref[_i];
|
||||
el.addEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
off: function(el, events, handler) {
|
||||
};
|
||||
|
||||
$.off = function(el, events, handler) {
|
||||
var event, _i, _len, _ref;
|
||||
|
||||
_ref = events.split(' ');
|
||||
@ -601,8 +620,9 @@
|
||||
event = _ref[_i];
|
||||
el.removeEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
event: function(event, detail, root) {
|
||||
};
|
||||
|
||||
$.event = function(event, detail, root) {
|
||||
if (root == null) {
|
||||
root = d;
|
||||
}
|
||||
@ -610,8 +630,9 @@
|
||||
bubbles: true,
|
||||
detail: detail
|
||||
}));
|
||||
},
|
||||
open: (function() {
|
||||
};
|
||||
|
||||
$.open = (function() {
|
||||
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
||||
return function(URL) {
|
||||
var a;
|
||||
@ -626,8 +647,9 @@
|
||||
return window.open(URL, '_blank');
|
||||
};
|
||||
}
|
||||
})(),
|
||||
debounce: function(wait, fn) {
|
||||
})();
|
||||
|
||||
$.debounce = function(wait, fn) {
|
||||
var args, exec, that, timeout;
|
||||
|
||||
timeout = null;
|
||||
@ -647,8 +669,9 @@
|
||||
}
|
||||
return timeout = setTimeout(exec, wait);
|
||||
};
|
||||
},
|
||||
queueTask: (function() {
|
||||
};
|
||||
|
||||
$.queueTask = (function() {
|
||||
var execTask, taskChannel, taskQueue;
|
||||
|
||||
taskQueue = [];
|
||||
@ -673,8 +696,9 @@
|
||||
return setTimeout(execTask, 0);
|
||||
};
|
||||
}
|
||||
})(),
|
||||
globalEval: function(code) {
|
||||
})();
|
||||
|
||||
$.globalEval = function(code) {
|
||||
var script;
|
||||
|
||||
script = $.el('script', {
|
||||
@ -682,8 +706,9 @@
|
||||
});
|
||||
$.add(d.head || doc, script);
|
||||
return $.rm(script);
|
||||
},
|
||||
bytesToString: function(size) {
|
||||
};
|
||||
|
||||
$.bytesToString = function(size) {
|
||||
var unit;
|
||||
|
||||
unit = 0;
|
||||
@ -693,12 +718,15 @@
|
||||
}
|
||||
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
||||
return "" + size + " " + ['B', 'KB', 'MB', 'GB'][unit];
|
||||
},
|
||||
minmax: function(value, min, max) {
|
||||
};
|
||||
|
||||
$.minmax = function(value, min, max) {
|
||||
return (value < min ? min : value > max ? max : value);
|
||||
},
|
||||
syncing: {},
|
||||
sync: (function() {
|
||||
};
|
||||
|
||||
$.syncing = {};
|
||||
|
||||
$.sync = (function() {
|
||||
window.addEventListener('storage', function(e) {
|
||||
var cb;
|
||||
|
||||
@ -709,15 +737,17 @@
|
||||
return function(key, cb) {
|
||||
return $.syncing[g.NAMESPACE + key] = cb;
|
||||
};
|
||||
})(),
|
||||
item: function(key, val) {
|
||||
})();
|
||||
|
||||
$.item = function(key, val) {
|
||||
var item;
|
||||
|
||||
item = {};
|
||||
item[key] = val;
|
||||
return item;
|
||||
},
|
||||
"delete": function(keys) {
|
||||
};
|
||||
|
||||
$["delete"] = function(keys) {
|
||||
var key, _i, _len;
|
||||
|
||||
if (!(keys instanceof Array)) {
|
||||
@ -729,8 +759,9 @@
|
||||
localStorage.removeItem(key);
|
||||
GM_deleteValue(key);
|
||||
}
|
||||
},
|
||||
get: function(key, val, cb) {
|
||||
};
|
||||
|
||||
$.get = function(key, val, cb) {
|
||||
var items;
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
@ -747,8 +778,9 @@
|
||||
}
|
||||
return cb(items);
|
||||
});
|
||||
},
|
||||
set: (function() {
|
||||
};
|
||||
|
||||
$.set = (function() {
|
||||
var set;
|
||||
|
||||
set = function(key, val) {
|
||||
@ -771,8 +803,14 @@
|
||||
set(key, val);
|
||||
}
|
||||
};
|
||||
})()
|
||||
});
|
||||
})();
|
||||
|
||||
$$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
}
|
||||
return __slice.call(root.querySelectorAll(selector));
|
||||
};
|
||||
|
||||
Build = {
|
||||
spoilerRange: {},
|
||||
|
||||
@ -193,6 +193,59 @@
|
||||
posts: {}
|
||||
};
|
||||
|
||||
String.prototype.capitalize = function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
};
|
||||
|
||||
String.prototype.contains = function(string) {
|
||||
return this.indexOf(string) > -1;
|
||||
};
|
||||
|
||||
Array.prototype.add = function(object, position) {
|
||||
var keep;
|
||||
|
||||
keep = this.slice(position);
|
||||
this.length = position;
|
||||
this.push(object);
|
||||
return this.pushArrays(keep);
|
||||
};
|
||||
|
||||
Array.prototype.contains = function(object) {
|
||||
return this.indexOf(object) > -1;
|
||||
};
|
||||
|
||||
Array.prototype.indexOf = function(object) {
|
||||
var i;
|
||||
|
||||
i = this.length;
|
||||
while (i--) {
|
||||
if (this[i] === object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
Array.prototype.pushArrays = function() {
|
||||
var arg, args, _i, _len;
|
||||
|
||||
args = arguments;
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
this.push.apply(this, arg);
|
||||
}
|
||||
};
|
||||
|
||||
Array.prototype.remove = function(object) {
|
||||
var index;
|
||||
|
||||
if ((index = this.indexOf(object)) > -1) {
|
||||
return this.splice(index, 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
@ -200,15 +253,6 @@
|
||||
return root.querySelector(selector);
|
||||
};
|
||||
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||
|
||||
$$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
}
|
||||
return __slice.call(root.querySelectorAll(selector));
|
||||
};
|
||||
|
||||
$.extend = function(object, properties) {
|
||||
var key, val;
|
||||
|
||||
@ -221,63 +265,13 @@
|
||||
}
|
||||
};
|
||||
|
||||
$.extend(Array.prototype, {
|
||||
add: function(object, position) {
|
||||
var keep;
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||
|
||||
keep = this.slice(position);
|
||||
this.length = position;
|
||||
this.push(object);
|
||||
return this.pushArrays(keep);
|
||||
},
|
||||
contains: function(object) {
|
||||
return this.indexOf(object) > -1;
|
||||
},
|
||||
indexOf: function(object) {
|
||||
var i;
|
||||
|
||||
i = this.length;
|
||||
while (i--) {
|
||||
if (this[i] === object) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return i;
|
||||
},
|
||||
pushArrays: function() {
|
||||
var arg, args, _i, _len;
|
||||
|
||||
args = arguments;
|
||||
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
||||
arg = args[_i];
|
||||
this.push.apply(this, arg);
|
||||
}
|
||||
},
|
||||
remove: function(object) {
|
||||
var index;
|
||||
|
||||
if ((index = this.indexOf(object)) > -1) {
|
||||
return this.splice(index, 1);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.extend(String.prototype, {
|
||||
capitalize: function() {
|
||||
return this.charAt(0).toUpperCase() + this.slice(1);
|
||||
},
|
||||
contains: function(string) {
|
||||
return this.indexOf(string) > -1;
|
||||
}
|
||||
});
|
||||
|
||||
$.extend($, {
|
||||
id: function(id) {
|
||||
$.id = function(id) {
|
||||
return d.getElementById(id);
|
||||
},
|
||||
ready: function(fc) {
|
||||
};
|
||||
|
||||
$.ready = function(fc) {
|
||||
var cb, _ref;
|
||||
|
||||
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
||||
@ -289,8 +283,9 @@
|
||||
return fc();
|
||||
};
|
||||
return $.on(d, 'DOMContentLoaded', cb);
|
||||
},
|
||||
formData: function(form) {
|
||||
};
|
||||
|
||||
$.formData = function(form) {
|
||||
var fd, key, val;
|
||||
|
||||
if (form instanceof HTMLFormElement) {
|
||||
@ -309,8 +304,9 @@
|
||||
}
|
||||
}
|
||||
return fd;
|
||||
},
|
||||
ajax: function(url, callbacks, opts) {
|
||||
};
|
||||
|
||||
$.ajax = function(url, callbacks, opts) {
|
||||
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
||||
|
||||
if (opts == null) {
|
||||
@ -330,8 +326,9 @@
|
||||
r.withCredentials = cred;
|
||||
r.send(form);
|
||||
return r;
|
||||
},
|
||||
cache: (function() {
|
||||
};
|
||||
|
||||
$.cache = (function() {
|
||||
var reqs;
|
||||
|
||||
reqs = {};
|
||||
@ -366,8 +363,9 @@
|
||||
req.callbacks = [cb];
|
||||
return reqs[url] = req;
|
||||
};
|
||||
})(),
|
||||
cb: {
|
||||
})();
|
||||
|
||||
$.cb = {
|
||||
checked: function() {
|
||||
$.set(this.name, this.checked);
|
||||
return Conf[this.name] = this.checked;
|
||||
@ -376,15 +374,17 @@
|
||||
$.set(this.name, this.value.trim());
|
||||
return Conf[this.name] = this.value;
|
||||
}
|
||||
},
|
||||
asap: function(test, cb) {
|
||||
};
|
||||
|
||||
$.asap = function(test, cb) {
|
||||
if (test()) {
|
||||
return cb();
|
||||
} else {
|
||||
return setTimeout($.asap, 25, test, cb);
|
||||
}
|
||||
},
|
||||
addStyle: function(css, id) {
|
||||
};
|
||||
|
||||
$.addStyle = function(css, id) {
|
||||
var style;
|
||||
|
||||
style = $.el('style', {
|
||||
@ -397,28 +397,35 @@
|
||||
return $.add(d.head, style);
|
||||
});
|
||||
return style;
|
||||
},
|
||||
x: function(path, root) {
|
||||
};
|
||||
|
||||
$.x = function(path, root) {
|
||||
root || (root = d.body);
|
||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||
},
|
||||
X: function(path, root) {
|
||||
};
|
||||
|
||||
$.X = function(path, root) {
|
||||
root || (root = d.body);
|
||||
return d.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
||||
},
|
||||
addClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.addClass = function(el, className) {
|
||||
return el.classList.add(className);
|
||||
},
|
||||
rmClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.rmClass = function(el, className) {
|
||||
return el.classList.remove(className);
|
||||
},
|
||||
toggleClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.toggleClass = function(el, className) {
|
||||
return el.classList.toggle(className);
|
||||
},
|
||||
hasClass: function(el, className) {
|
||||
};
|
||||
|
||||
$.hasClass = function(el, className) {
|
||||
return el.classList.contains(className);
|
||||
},
|
||||
rm: (function() {
|
||||
};
|
||||
|
||||
$.rm = (function() {
|
||||
if ('remove' in Element.prototype) {
|
||||
return function(el) {
|
||||
return el.remove();
|
||||
@ -430,21 +437,25 @@
|
||||
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
||||
};
|
||||
}
|
||||
})(),
|
||||
rmAll: function(root) {
|
||||
})();
|
||||
|
||||
$.rmAll = function(root) {
|
||||
var node;
|
||||
|
||||
while (node = root.firstChild) {
|
||||
root.removeChild(node);
|
||||
}
|
||||
},
|
||||
tn: function(s) {
|
||||
};
|
||||
|
||||
$.tn = function(s) {
|
||||
return d.createTextNode(s);
|
||||
},
|
||||
frag: function() {
|
||||
};
|
||||
|
||||
$.frag = function() {
|
||||
return d.createDocumentFragment();
|
||||
},
|
||||
nodes: function(nodes) {
|
||||
};
|
||||
|
||||
$.nodes = function(nodes) {
|
||||
var frag, node, _i, _len;
|
||||
|
||||
if (!(nodes instanceof Array)) {
|
||||
@ -456,23 +467,29 @@
|
||||
frag.appendChild(node);
|
||||
}
|
||||
return frag;
|
||||
},
|
||||
add: function(parent, el) {
|
||||
};
|
||||
|
||||
$.add = function(parent, el) {
|
||||
return parent.appendChild($.nodes(el));
|
||||
},
|
||||
prepend: function(parent, el) {
|
||||
};
|
||||
|
||||
$.prepend = function(parent, el) {
|
||||
return parent.insertBefore($.nodes(el), parent.firstChild);
|
||||
},
|
||||
after: function(root, el) {
|
||||
};
|
||||
|
||||
$.after = function(root, el) {
|
||||
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
||||
},
|
||||
before: function(root, el) {
|
||||
};
|
||||
|
||||
$.before = function(root, el) {
|
||||
return root.parentNode.insertBefore($.nodes(el), root);
|
||||
},
|
||||
replace: function(root, el) {
|
||||
};
|
||||
|
||||
$.replace = function(root, el) {
|
||||
return root.parentNode.replaceChild($.nodes(el), root);
|
||||
},
|
||||
el: function(tag, properties) {
|
||||
};
|
||||
|
||||
$.el = function(tag, properties) {
|
||||
var el;
|
||||
|
||||
el = d.createElement(tag);
|
||||
@ -480,8 +497,9 @@
|
||||
$.extend(el, properties);
|
||||
}
|
||||
return el;
|
||||
},
|
||||
on: function(el, events, handler) {
|
||||
};
|
||||
|
||||
$.on = function(el, events, handler) {
|
||||
var event, _i, _len, _ref;
|
||||
|
||||
_ref = events.split(' ');
|
||||
@ -489,8 +507,9 @@
|
||||
event = _ref[_i];
|
||||
el.addEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
off: function(el, events, handler) {
|
||||
};
|
||||
|
||||
$.off = function(el, events, handler) {
|
||||
var event, _i, _len, _ref;
|
||||
|
||||
_ref = events.split(' ');
|
||||
@ -498,8 +517,9 @@
|
||||
event = _ref[_i];
|
||||
el.removeEventListener(event, handler, false);
|
||||
}
|
||||
},
|
||||
event: function(event, detail, root) {
|
||||
};
|
||||
|
||||
$.event = function(event, detail, root) {
|
||||
if (root == null) {
|
||||
root = d;
|
||||
}
|
||||
@ -507,8 +527,9 @@
|
||||
bubbles: true,
|
||||
detail: detail
|
||||
}));
|
||||
},
|
||||
open: (function() {
|
||||
};
|
||||
|
||||
$.open = (function() {
|
||||
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
||||
return function(URL) {
|
||||
var a;
|
||||
@ -523,8 +544,9 @@
|
||||
return window.open(URL, '_blank');
|
||||
};
|
||||
}
|
||||
})(),
|
||||
debounce: function(wait, fn) {
|
||||
})();
|
||||
|
||||
$.debounce = function(wait, fn) {
|
||||
var args, exec, that, timeout;
|
||||
|
||||
timeout = null;
|
||||
@ -544,8 +566,9 @@
|
||||
}
|
||||
return timeout = setTimeout(exec, wait);
|
||||
};
|
||||
},
|
||||
queueTask: (function() {
|
||||
};
|
||||
|
||||
$.queueTask = (function() {
|
||||
var execTask, taskChannel, taskQueue;
|
||||
|
||||
taskQueue = [];
|
||||
@ -570,8 +593,9 @@
|
||||
return setTimeout(execTask, 0);
|
||||
};
|
||||
}
|
||||
})(),
|
||||
globalEval: function(code) {
|
||||
})();
|
||||
|
||||
$.globalEval = function(code) {
|
||||
var script;
|
||||
|
||||
script = $.el('script', {
|
||||
@ -579,8 +603,9 @@
|
||||
});
|
||||
$.add(d.head || doc, script);
|
||||
return $.rm(script);
|
||||
},
|
||||
bytesToString: function(size) {
|
||||
};
|
||||
|
||||
$.bytesToString = function(size) {
|
||||
var unit;
|
||||
|
||||
unit = 0;
|
||||
@ -590,12 +615,15 @@
|
||||
}
|
||||
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
||||
return "" + size + " " + ['B', 'KB', 'MB', 'GB'][unit];
|
||||
},
|
||||
minmax: function(value, min, max) {
|
||||
};
|
||||
|
||||
$.minmax = function(value, min, max) {
|
||||
return (value < min ? min : value > max ? max : value);
|
||||
},
|
||||
syncing: {},
|
||||
sync: (function() {
|
||||
};
|
||||
|
||||
$.syncing = {};
|
||||
|
||||
$.sync = (function() {
|
||||
chrome.storage.onChanged.addListener(function(changes) {
|
||||
var cb, key;
|
||||
|
||||
@ -608,18 +636,21 @@
|
||||
return function(key, cb) {
|
||||
return $.syncing[key] = cb;
|
||||
};
|
||||
})(),
|
||||
item: function(key, val) {
|
||||
})();
|
||||
|
||||
$.item = function(key, val) {
|
||||
var item;
|
||||
|
||||
item = {};
|
||||
item[key] = val;
|
||||
return item;
|
||||
},
|
||||
"delete": function(keys) {
|
||||
};
|
||||
|
||||
$["delete"] = function(keys) {
|
||||
return chrome.storage.sync.remove(keys);
|
||||
},
|
||||
get: function(key, val, cb) {
|
||||
};
|
||||
|
||||
$.get = function(key, val, cb) {
|
||||
var items;
|
||||
|
||||
if (typeof cb === 'function') {
|
||||
@ -629,14 +660,21 @@
|
||||
cb = val;
|
||||
}
|
||||
return chrome.storage.sync.get(items, cb);
|
||||
},
|
||||
set: function(key, val) {
|
||||
};
|
||||
|
||||
$.set = function(key, val) {
|
||||
var items;
|
||||
|
||||
items = typeof key === 'string' ? $.item(key, val) : key;
|
||||
return chrome.storage.sync.set(items);
|
||||
};
|
||||
|
||||
$$ = function(selector, root) {
|
||||
if (root == null) {
|
||||
root = d.body;
|
||||
}
|
||||
});
|
||||
return __slice.call(root.querySelectorAll(selector));
|
||||
};
|
||||
|
||||
Build = {
|
||||
spoilerRange: {},
|
||||
|
||||
211
src/lib/$.coffee
211
src/lib/$.coffee
@ -1,60 +1,54 @@
|
||||
String::capitalize = ->
|
||||
@charAt(0).toUpperCase() + @slice(1);
|
||||
|
||||
String::contains = (string) ->
|
||||
@indexOf(string) > -1
|
||||
|
||||
Array::add = (object, position) ->
|
||||
keep = @slice position
|
||||
@length = position
|
||||
@push object
|
||||
@pushArrays keep
|
||||
|
||||
Array::contains = (object) ->
|
||||
@indexOf(object) > -1
|
||||
|
||||
Array::indexOf = (object) ->
|
||||
i = @length
|
||||
while i--
|
||||
break if @[i] is object
|
||||
return i
|
||||
|
||||
Array::pushArrays = ->
|
||||
args = arguments
|
||||
for arg in args
|
||||
@push.apply @, arg
|
||||
return
|
||||
|
||||
Array::remove = (object) ->
|
||||
if (index = @indexOf object) > -1
|
||||
@splice index, 1
|
||||
else
|
||||
false
|
||||
|
||||
# loosely follows the jquery api:
|
||||
# http://api.jquery.com/
|
||||
# not chainable
|
||||
$ = (selector, root=d.body) ->
|
||||
root.querySelector selector
|
||||
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)))
|
||||
|
||||
$$ = (selector, root=d.body) ->
|
||||
[root.querySelectorAll(selector)...]
|
||||
|
||||
$.extend = (object, properties) ->
|
||||
for key, val of properties
|
||||
continue unless properties.hasOwnProperty key
|
||||
object[key] = val
|
||||
return
|
||||
|
||||
# Various prototypes I've wanted or needed to add.
|
||||
$.extend Array::,
|
||||
add: (object, position) ->
|
||||
keep = @slice position
|
||||
@length = position
|
||||
@push object
|
||||
@pushArrays keep
|
||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)))
|
||||
|
||||
contains: (object) ->
|
||||
@indexOf(object) > -1
|
||||
|
||||
indexOf: (object) ->
|
||||
i = @length
|
||||
while i--
|
||||
break if @[i] is object
|
||||
return i
|
||||
|
||||
pushArrays: ->
|
||||
args = arguments
|
||||
for arg in args
|
||||
@push.apply @, arg
|
||||
return
|
||||
|
||||
remove: (object) ->
|
||||
if (index = @indexOf object) > -1
|
||||
@splice index, 1
|
||||
else
|
||||
false
|
||||
|
||||
$.extend String::,
|
||||
capitalize: ->
|
||||
@charAt(0).toUpperCase() + @slice(1);
|
||||
|
||||
contains: (string) ->
|
||||
@indexOf(string) > -1
|
||||
|
||||
$.extend $,
|
||||
id: (id) ->
|
||||
$.id = (id) ->
|
||||
d.getElementById id
|
||||
ready: (fc) ->
|
||||
|
||||
$.ready = (fc) ->
|
||||
if d.readyState in ['interactive', 'complete']
|
||||
$.queueTask fc
|
||||
return
|
||||
@ -62,7 +56,8 @@ $.extend $,
|
||||
$.off d, 'DOMContentLoaded', cb
|
||||
fc()
|
||||
$.on d, 'DOMContentLoaded', cb
|
||||
formData: (form) ->
|
||||
|
||||
$.formData = (form) ->
|
||||
if form instanceof HTMLFormElement
|
||||
return new FormData form
|
||||
fd = new FormData()
|
||||
@ -75,7 +70,8 @@ $.extend $,
|
||||
else
|
||||
fd.append key, val
|
||||
fd
|
||||
ajax: (url, callbacks, opts={}) ->
|
||||
|
||||
$.ajax = (url, callbacks, opts={}) ->
|
||||
{type, cred, headers, upCallbacks, form, sync} = opts
|
||||
r = new XMLHttpRequest()
|
||||
r.overrideMimeType 'text/html'
|
||||
@ -88,7 +84,8 @@ $.extend $,
|
||||
r.withCredentials = cred
|
||||
r.send form
|
||||
r
|
||||
cache: do ->
|
||||
|
||||
$.cache = do ->
|
||||
reqs = {}
|
||||
(url, cb) ->
|
||||
if req = reqs[url]
|
||||
@ -106,87 +103,111 @@ $.extend $,
|
||||
onerror: rm
|
||||
req.callbacks = [cb]
|
||||
reqs[url] = req
|
||||
cb:
|
||||
|
||||
$.cb =
|
||||
checked: ->
|
||||
$.set @name, @checked
|
||||
Conf[@name] = @checked
|
||||
value: ->
|
||||
$.set @name, @value.trim()
|
||||
Conf[@name] = @value
|
||||
asap: (test, cb) ->
|
||||
|
||||
$.asap = (test, cb) ->
|
||||
if test()
|
||||
cb()
|
||||
else
|
||||
setTimeout $.asap, 25, test, cb
|
||||
addStyle: (css, id) ->
|
||||
|
||||
$.addStyle = (css, id) ->
|
||||
style = $.el 'style',
|
||||
id: id
|
||||
textContent: css
|
||||
$.asap (-> d.head), ->
|
||||
$.add d.head, style
|
||||
style
|
||||
x: (path, root) ->
|
||||
|
||||
$.x = (path, root) ->
|
||||
root or= d.body
|
||||
# XPathResult.ANY_UNORDERED_NODE_TYPE === 8
|
||||
d.evaluate(path, root, null, 8, null).singleNodeValue
|
||||
X: (path, root) ->
|
||||
|
||||
$.X = (path, root) ->
|
||||
root or= d.body
|
||||
d.evaluate path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
|
||||
addClass: (el, className) ->
|
||||
|
||||
$.addClass = (el, className) ->
|
||||
el.classList.add className
|
||||
rmClass: (el, className) ->
|
||||
|
||||
$.rmClass = (el, className) ->
|
||||
el.classList.remove className
|
||||
toggleClass: (el, className) ->
|
||||
|
||||
$.toggleClass = (el, className) ->
|
||||
el.classList.toggle className
|
||||
hasClass: (el, className) ->
|
||||
|
||||
$.hasClass = (el, className) ->
|
||||
el.classList.contains className
|
||||
rm: do ->
|
||||
|
||||
$.rm = do ->
|
||||
if 'remove' of Element.prototype
|
||||
(el) -> el.remove()
|
||||
else
|
||||
(el) -> el.parentNode?.removeChild el
|
||||
rmAll: (root) ->
|
||||
|
||||
$.rmAll = (root) ->
|
||||
# jsperf.com/emptify-element
|
||||
while node = root.firstChild
|
||||
# HTMLSelectElement.remove !== Element.remove
|
||||
root.removeChild node
|
||||
return
|
||||
tn: (s) ->
|
||||
|
||||
$.tn = (s) ->
|
||||
d.createTextNode s
|
||||
frag: ->
|
||||
|
||||
$.frag = ->
|
||||
d.createDocumentFragment()
|
||||
nodes: (nodes) ->
|
||||
|
||||
$.nodes = (nodes) ->
|
||||
unless nodes instanceof Array
|
||||
return nodes
|
||||
frag = $.frag()
|
||||
for node in nodes
|
||||
frag.appendChild node
|
||||
frag
|
||||
add: (parent, el) ->
|
||||
|
||||
$.add = (parent, el) ->
|
||||
parent.appendChild $.nodes el
|
||||
prepend: (parent, el) ->
|
||||
|
||||
$.prepend = (parent, el) ->
|
||||
parent.insertBefore $.nodes(el), parent.firstChild
|
||||
after: (root, el) ->
|
||||
|
||||
$.after = (root, el) ->
|
||||
root.parentNode.insertBefore $.nodes(el), root.nextSibling
|
||||
before: (root, el) ->
|
||||
|
||||
$.before = (root, el) ->
|
||||
root.parentNode.insertBefore $.nodes(el), root
|
||||
replace: (root, el) ->
|
||||
|
||||
$.replace = (root, el) ->
|
||||
root.parentNode.replaceChild $.nodes(el), root
|
||||
el: (tag, properties) ->
|
||||
|
||||
$.el = (tag, properties) ->
|
||||
el = d.createElement tag
|
||||
$.extend el, properties if properties
|
||||
el
|
||||
on: (el, events, handler) ->
|
||||
|
||||
$.on = (el, events, handler) ->
|
||||
for event in events.split ' '
|
||||
el.addEventListener event, handler, false
|
||||
return
|
||||
off: (el, events, handler) ->
|
||||
|
||||
$.off = (el, events, handler) ->
|
||||
for event in events.split ' '
|
||||
el.removeEventListener event, handler, false
|
||||
return
|
||||
event: (event, detail, root=d) ->
|
||||
|
||||
$.event = (event, detail, root=d) ->
|
||||
root.dispatchEvent new CustomEvent event, {bubbles: true, detail}
|
||||
open: do ->
|
||||
|
||||
$.open = do ->
|
||||
if GM_openInTab?
|
||||
(URL) ->
|
||||
# XXX fix GM opening file://// for protocol-less URLs.
|
||||
@ -194,7 +215,8 @@ $.extend $,
|
||||
GM_openInTab a.href
|
||||
else
|
||||
(URL) -> window.open URL, '_blank'
|
||||
debounce: (wait, fn) ->
|
||||
|
||||
$.debounce = (wait, fn) ->
|
||||
timeout = null
|
||||
that = null
|
||||
args = null
|
||||
@ -212,7 +234,8 @@ $.extend $,
|
||||
|
||||
# after wait, let next invocation execute immediately
|
||||
timeout = setTimeout exec, wait
|
||||
queueTask: do ->
|
||||
|
||||
$.queueTask = do ->
|
||||
# inspired by https://www.w3.org/Bugs/Public/show_bug.cgi?id=15007
|
||||
taskQueue = []
|
||||
execTask = ->
|
||||
@ -230,12 +253,14 @@ $.extend $,
|
||||
->
|
||||
taskQueue.push arguments
|
||||
setTimeout execTask, 0
|
||||
globalEval: (code) ->
|
||||
|
||||
$.globalEval = (code) ->
|
||||
script = $.el 'script',
|
||||
textContent: code
|
||||
$.add (d.head or doc), script
|
||||
$.rm script
|
||||
bytesToString: (size) ->
|
||||
|
||||
$.bytesToString = (size) ->
|
||||
unit = 0 # Bytes
|
||||
while size >= 1024
|
||||
size /= 1024
|
||||
@ -250,7 +275,8 @@ $.extend $,
|
||||
# Round to an integer otherwise.
|
||||
Math.round size
|
||||
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
||||
minmax: (value, min, max) ->
|
||||
|
||||
$.minmax = (value, min, max) ->
|
||||
return (
|
||||
if value < min
|
||||
min
|
||||
@ -260,8 +286,10 @@ $.extend $,
|
||||
else
|
||||
value
|
||||
)
|
||||
syncing: {}
|
||||
sync: do ->
|
||||
|
||||
$.syncing = {}
|
||||
|
||||
$.sync = do ->
|
||||
<% if (type === 'crx') { %>
|
||||
chrome.storage.onChanged.addListener (changes) ->
|
||||
for key of changes
|
||||
@ -276,27 +304,32 @@ $.extend $,
|
||||
, false
|
||||
(key, cb) -> $.syncing[g.NAMESPACE + key] = cb
|
||||
<% } %>
|
||||
item: (key, val) ->
|
||||
|
||||
$.item = (key, val) ->
|
||||
item = {}
|
||||
item[key] = val
|
||||
item
|
||||
<% if (type === 'crx') { %>
|
||||
# https://developer.chrome.com/extensions/storage.html
|
||||
delete: (keys) ->
|
||||
|
||||
$.delete = (keys) ->
|
||||
chrome.storage.sync.remove keys
|
||||
get: (key, val, cb) ->
|
||||
|
||||
$.get = (key, val, cb) ->
|
||||
if typeof cb is 'function'
|
||||
items = $.item key, val
|
||||
else
|
||||
items = key
|
||||
cb = val
|
||||
chrome.storage.sync.get items, cb
|
||||
set: (key, val) ->
|
||||
|
||||
$.set = (key, val) ->
|
||||
items = if typeof key is 'string'
|
||||
$.item key, val
|
||||
else
|
||||
key
|
||||
chrome.storage.sync.set items
|
||||
|
||||
<% } else if (type === 'userjs') { %>
|
||||
do ->
|
||||
# http://www.opera.com/docs/userjs/specs/#scriptstorage
|
||||
@ -326,7 +359,7 @@ do ->
|
||||
if val = scriptStorage[g.NAMESPACE + key]
|
||||
items[key] = JSON.parse val
|
||||
cb items
|
||||
$.set = do ->
|
||||
$.set = do ->
|
||||
set = (key, val) ->
|
||||
key = g.NAMESPACE + key
|
||||
val = JSON.stringify val
|
||||
@ -342,8 +375,9 @@ do ->
|
||||
set key, val
|
||||
return
|
||||
<% } else { %>
|
||||
# http://wiki.greasespot.net/Main_Page
|
||||
delete: (keys) ->
|
||||
|
||||
# http://wiki.greasespot.net/Main_Page
|
||||
$.delete = (keys) ->
|
||||
unless keys instanceof Array
|
||||
keys = [keys]
|
||||
for key in keys
|
||||
@ -351,7 +385,8 @@ do ->
|
||||
localStorage.removeItem key
|
||||
GM_deleteValue key
|
||||
return
|
||||
get: (key, val, cb) ->
|
||||
|
||||
$.get = (key, val, cb) ->
|
||||
if typeof cb is 'function'
|
||||
items = $.item key, val
|
||||
else
|
||||
@ -362,7 +397,8 @@ do ->
|
||||
if val = GM_getValue g.NAMESPACE + key
|
||||
items[key] = JSON.parse val
|
||||
cb items
|
||||
set: do ->
|
||||
|
||||
$.set = do ->
|
||||
set = (key, val) ->
|
||||
key = g.NAMESPACE + key
|
||||
val = JSON.stringify val
|
||||
@ -378,3 +414,6 @@ do ->
|
||||
set key, val
|
||||
return
|
||||
<% } %>
|
||||
|
||||
$$ = (selector, root=d.body) ->
|
||||
[root.querySelectorAll(selector)...]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user