Merge branch 'v3' of git://github.com/zixaphir/appchan-x
This commit is contained in:
commit
133c8bd1f9
@ -302,6 +302,59 @@
|
|||||||
posts: {}
|
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) {
|
$ = function(selector, root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = d.body;
|
root = d.body;
|
||||||
@ -309,15 +362,6 @@
|
|||||||
return root.querySelector(selector);
|
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) {
|
$.extend = function(object, properties) {
|
||||||
var key, val;
|
var key, val;
|
||||||
|
|
||||||
@ -330,63 +374,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$.extend(Array.prototype, {
|
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||||
add: function(object, position) {
|
|
||||||
var keep;
|
|
||||||
|
|
||||||
keep = this.slice(position);
|
$.id = function(id) {
|
||||||
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) {
|
|
||||||
return d.getElementById(id);
|
return d.getElementById(id);
|
||||||
},
|
};
|
||||||
ready: function(fc) {
|
|
||||||
|
$.ready = function(fc) {
|
||||||
var cb, _ref;
|
var cb, _ref;
|
||||||
|
|
||||||
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
||||||
@ -398,8 +392,9 @@
|
|||||||
return fc();
|
return fc();
|
||||||
};
|
};
|
||||||
return $.on(d, 'DOMContentLoaded', cb);
|
return $.on(d, 'DOMContentLoaded', cb);
|
||||||
},
|
};
|
||||||
formData: function(form) {
|
|
||||||
|
$.formData = function(form) {
|
||||||
var fd, key, val;
|
var fd, key, val;
|
||||||
|
|
||||||
if (form instanceof HTMLFormElement) {
|
if (form instanceof HTMLFormElement) {
|
||||||
@ -418,8 +413,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
},
|
};
|
||||||
ajax: function(url, callbacks, opts) {
|
|
||||||
|
$.ajax = function(url, callbacks, opts) {
|
||||||
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
||||||
|
|
||||||
if (opts == null) {
|
if (opts == null) {
|
||||||
@ -439,8 +435,9 @@
|
|||||||
r.withCredentials = cred;
|
r.withCredentials = cred;
|
||||||
r.send(form);
|
r.send(form);
|
||||||
return r;
|
return r;
|
||||||
},
|
};
|
||||||
cache: (function() {
|
|
||||||
|
$.cache = (function() {
|
||||||
var reqs;
|
var reqs;
|
||||||
|
|
||||||
reqs = {};
|
reqs = {};
|
||||||
@ -475,8 +472,9 @@
|
|||||||
req.callbacks = [cb];
|
req.callbacks = [cb];
|
||||||
return reqs[url] = req;
|
return reqs[url] = req;
|
||||||
};
|
};
|
||||||
})(),
|
})();
|
||||||
cb: {
|
|
||||||
|
$.cb = {
|
||||||
checked: function() {
|
checked: function() {
|
||||||
$.set(this.name, this.checked);
|
$.set(this.name, this.checked);
|
||||||
return Conf[this.name] = this.checked;
|
return Conf[this.name] = this.checked;
|
||||||
@ -485,15 +483,17 @@
|
|||||||
$.set(this.name, this.value.trim());
|
$.set(this.name, this.value.trim());
|
||||||
return Conf[this.name] = this.value;
|
return Conf[this.name] = this.value;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
asap: function(test, cb) {
|
|
||||||
|
$.asap = function(test, cb) {
|
||||||
if (test()) {
|
if (test()) {
|
||||||
return cb();
|
return cb();
|
||||||
} else {
|
} else {
|
||||||
return setTimeout($.asap, 25, test, cb);
|
return setTimeout($.asap, 25, test, cb);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
addStyle: function(css, id) {
|
|
||||||
|
$.addStyle = function(css, id) {
|
||||||
var style;
|
var style;
|
||||||
|
|
||||||
style = $.el('style', {
|
style = $.el('style', {
|
||||||
@ -506,28 +506,35 @@
|
|||||||
return $.add(d.head, style);
|
return $.add(d.head, style);
|
||||||
});
|
});
|
||||||
return style;
|
return style;
|
||||||
},
|
};
|
||||||
x: function(path, root) {
|
|
||||||
|
$.x = function(path, root) {
|
||||||
root || (root = d.body);
|
root || (root = d.body);
|
||||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||||
},
|
};
|
||||||
X: function(path, root) {
|
|
||||||
|
$.X = function(path, root) {
|
||||||
root || (root = d.body);
|
root || (root = d.body);
|
||||||
return d.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
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);
|
return el.classList.add(className);
|
||||||
},
|
};
|
||||||
rmClass: function(el, className) {
|
|
||||||
|
$.rmClass = function(el, className) {
|
||||||
return el.classList.remove(className);
|
return el.classList.remove(className);
|
||||||
},
|
};
|
||||||
toggleClass: function(el, className) {
|
|
||||||
|
$.toggleClass = function(el, className) {
|
||||||
return el.classList.toggle(className);
|
return el.classList.toggle(className);
|
||||||
},
|
};
|
||||||
hasClass: function(el, className) {
|
|
||||||
|
$.hasClass = function(el, className) {
|
||||||
return el.classList.contains(className);
|
return el.classList.contains(className);
|
||||||
},
|
};
|
||||||
rm: (function() {
|
|
||||||
|
$.rm = (function() {
|
||||||
if ('remove' in Element.prototype) {
|
if ('remove' in Element.prototype) {
|
||||||
return function(el) {
|
return function(el) {
|
||||||
return el.remove();
|
return el.remove();
|
||||||
@ -539,21 +546,25 @@
|
|||||||
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
rmAll: function(root) {
|
|
||||||
|
$.rmAll = function(root) {
|
||||||
var node;
|
var node;
|
||||||
|
|
||||||
while (node = root.firstChild) {
|
while (node = root.firstChild) {
|
||||||
root.removeChild(node);
|
root.removeChild(node);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
tn: function(s) {
|
|
||||||
|
$.tn = function(s) {
|
||||||
return d.createTextNode(s);
|
return d.createTextNode(s);
|
||||||
},
|
};
|
||||||
frag: function() {
|
|
||||||
|
$.frag = function() {
|
||||||
return d.createDocumentFragment();
|
return d.createDocumentFragment();
|
||||||
},
|
};
|
||||||
nodes: function(nodes) {
|
|
||||||
|
$.nodes = function(nodes) {
|
||||||
var frag, node, _i, _len;
|
var frag, node, _i, _len;
|
||||||
|
|
||||||
if (!(nodes instanceof Array)) {
|
if (!(nodes instanceof Array)) {
|
||||||
@ -565,23 +576,29 @@
|
|||||||
frag.appendChild(node);
|
frag.appendChild(node);
|
||||||
}
|
}
|
||||||
return frag;
|
return frag;
|
||||||
},
|
};
|
||||||
add: function(parent, el) {
|
|
||||||
|
$.add = function(parent, el) {
|
||||||
return parent.appendChild($.nodes(el));
|
return parent.appendChild($.nodes(el));
|
||||||
},
|
};
|
||||||
prepend: function(parent, el) {
|
|
||||||
|
$.prepend = function(parent, el) {
|
||||||
return parent.insertBefore($.nodes(el), parent.firstChild);
|
return parent.insertBefore($.nodes(el), parent.firstChild);
|
||||||
},
|
};
|
||||||
after: function(root, el) {
|
|
||||||
|
$.after = function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
||||||
},
|
};
|
||||||
before: function(root, el) {
|
|
||||||
|
$.before = function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root);
|
return root.parentNode.insertBefore($.nodes(el), root);
|
||||||
},
|
};
|
||||||
replace: function(root, el) {
|
|
||||||
|
$.replace = function(root, el) {
|
||||||
return root.parentNode.replaceChild($.nodes(el), root);
|
return root.parentNode.replaceChild($.nodes(el), root);
|
||||||
},
|
};
|
||||||
el: function(tag, properties) {
|
|
||||||
|
$.el = function(tag, properties) {
|
||||||
var el;
|
var el;
|
||||||
|
|
||||||
el = d.createElement(tag);
|
el = d.createElement(tag);
|
||||||
@ -589,8 +606,9 @@
|
|||||||
$.extend(el, properties);
|
$.extend(el, properties);
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
},
|
};
|
||||||
on: function(el, events, handler) {
|
|
||||||
|
$.on = function(el, events, handler) {
|
||||||
var event, _i, _len, _ref;
|
var event, _i, _len, _ref;
|
||||||
|
|
||||||
_ref = events.split(' ');
|
_ref = events.split(' ');
|
||||||
@ -598,8 +616,9 @@
|
|||||||
event = _ref[_i];
|
event = _ref[_i];
|
||||||
el.addEventListener(event, handler, false);
|
el.addEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
off: function(el, events, handler) {
|
|
||||||
|
$.off = function(el, events, handler) {
|
||||||
var event, _i, _len, _ref;
|
var event, _i, _len, _ref;
|
||||||
|
|
||||||
_ref = events.split(' ');
|
_ref = events.split(' ');
|
||||||
@ -607,8 +626,9 @@
|
|||||||
event = _ref[_i];
|
event = _ref[_i];
|
||||||
el.removeEventListener(event, handler, false);
|
el.removeEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
event: function(event, detail, root) {
|
|
||||||
|
$.event = function(event, detail, root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = d;
|
root = d;
|
||||||
}
|
}
|
||||||
@ -616,8 +636,9 @@
|
|||||||
bubbles: true,
|
bubbles: true,
|
||||||
detail: detail
|
detail: detail
|
||||||
}));
|
}));
|
||||||
},
|
};
|
||||||
open: (function() {
|
|
||||||
|
$.open = (function() {
|
||||||
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
||||||
return function(URL) {
|
return function(URL) {
|
||||||
var a;
|
var a;
|
||||||
@ -632,8 +653,9 @@
|
|||||||
return window.open(URL, '_blank');
|
return window.open(URL, '_blank');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
debounce: function(wait, fn) {
|
|
||||||
|
$.debounce = function(wait, fn) {
|
||||||
var args, exec, that, timeout;
|
var args, exec, that, timeout;
|
||||||
|
|
||||||
timeout = null;
|
timeout = null;
|
||||||
@ -653,8 +675,9 @@
|
|||||||
}
|
}
|
||||||
return timeout = setTimeout(exec, wait);
|
return timeout = setTimeout(exec, wait);
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
queueTask: (function() {
|
|
||||||
|
$.queueTask = (function() {
|
||||||
var execTask, taskChannel, taskQueue;
|
var execTask, taskChannel, taskQueue;
|
||||||
|
|
||||||
taskQueue = [];
|
taskQueue = [];
|
||||||
@ -679,8 +702,9 @@
|
|||||||
return setTimeout(execTask, 0);
|
return setTimeout(execTask, 0);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
globalEval: function(code) {
|
|
||||||
|
$.globalEval = function(code) {
|
||||||
var script;
|
var script;
|
||||||
|
|
||||||
script = $.el('script', {
|
script = $.el('script', {
|
||||||
@ -688,8 +712,9 @@
|
|||||||
});
|
});
|
||||||
$.add(d.head || doc, script);
|
$.add(d.head || doc, script);
|
||||||
return $.rm(script);
|
return $.rm(script);
|
||||||
},
|
};
|
||||||
bytesToString: function(size) {
|
|
||||||
|
$.bytesToString = function(size) {
|
||||||
var unit;
|
var unit;
|
||||||
|
|
||||||
unit = 0;
|
unit = 0;
|
||||||
@ -699,12 +724,15 @@
|
|||||||
}
|
}
|
||||||
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
||||||
return "" + size + " " + ['B', 'KB', 'MB', 'GB'][unit];
|
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);
|
return (value < min ? min : value > max ? max : value);
|
||||||
},
|
};
|
||||||
syncing: {},
|
|
||||||
sync: (function() {
|
$.syncing = {};
|
||||||
|
|
||||||
|
$.sync = (function() {
|
||||||
window.addEventListener('storage', function(e) {
|
window.addEventListener('storage', function(e) {
|
||||||
var cb;
|
var cb;
|
||||||
|
|
||||||
@ -715,23 +743,21 @@
|
|||||||
return function(key, cb) {
|
return function(key, cb) {
|
||||||
return $.syncing[g.NAMESPACE + key] = cb;
|
return $.syncing[g.NAMESPACE + key] = cb;
|
||||||
};
|
};
|
||||||
})(),
|
})();
|
||||||
item: function(key, val) {
|
|
||||||
|
$.item = function(key, val) {
|
||||||
var item;
|
var item;
|
||||||
|
|
||||||
item = {};
|
item = {};
|
||||||
item[key] = val;
|
item[key] = val;
|
||||||
return item;
|
return item;
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
var scriptStorage;
|
var cb, items, key, keys, scriptStorage, _i, _len;
|
||||||
|
|
||||||
scriptStorage = opera.scriptStorage;
|
scriptStorage = opera.scriptStorage;
|
||||||
$["delete"] = function(keys) {
|
$["delete"] = function(keys) {};
|
||||||
var key, _i, _len;
|
|
||||||
|
|
||||||
if (!(keys instanceof Array)) {
|
if (!(keys instanceof Array)) {
|
||||||
keys = [keys];
|
keys = [keys];
|
||||||
}
|
}
|
||||||
@ -741,10 +767,8 @@
|
|||||||
localStorage.removeItem(key);
|
localStorage.removeItem(key);
|
||||||
delete scriptStorage[key];
|
delete scriptStorage[key];
|
||||||
}
|
}
|
||||||
};
|
return;
|
||||||
$.get = function(key, val, cb) {
|
$.get = function(key, val, cb) {};
|
||||||
var items;
|
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
items = $.item(key, val);
|
items = $.item(key, val);
|
||||||
} else {
|
} else {
|
||||||
@ -752,6 +776,8 @@
|
|||||||
cb = val;
|
cb = val;
|
||||||
}
|
}
|
||||||
return $.queueTask(function() {
|
return $.queueTask(function() {
|
||||||
|
var val;
|
||||||
|
|
||||||
for (key in items) {
|
for (key in items) {
|
||||||
if (val = scriptStorage[g.NAMESPACE + key]) {
|
if (val = scriptStorage[g.NAMESPACE + key]) {
|
||||||
items[key] = JSON.parse(val);
|
items[key] = JSON.parse(val);
|
||||||
@ -759,8 +785,9 @@
|
|||||||
}
|
}
|
||||||
return cb(items);
|
return cb(items);
|
||||||
});
|
});
|
||||||
};
|
})();
|
||||||
return $.set = (function() {
|
|
||||||
|
$.set = (function() {
|
||||||
var set;
|
var set;
|
||||||
|
|
||||||
set = function(key, val) {
|
set = function(key, val) {
|
||||||
@ -784,7 +811,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
})();
|
|
||||||
|
$$ = function(selector, root) {
|
||||||
|
if (root == null) {
|
||||||
|
root = d.body;
|
||||||
|
}
|
||||||
|
return __slice.call(root.querySelectorAll(selector));
|
||||||
|
};
|
||||||
|
|
||||||
Build = {
|
Build = {
|
||||||
spoilerRange: {},
|
spoilerRange: {},
|
||||||
|
|||||||
@ -299,6 +299,59 @@
|
|||||||
posts: {}
|
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) {
|
$ = function(selector, root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = d.body;
|
root = d.body;
|
||||||
@ -306,15 +359,6 @@
|
|||||||
return root.querySelector(selector);
|
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) {
|
$.extend = function(object, properties) {
|
||||||
var key, val;
|
var key, val;
|
||||||
|
|
||||||
@ -327,63 +371,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$.extend(Array.prototype, {
|
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||||
add: function(object, position) {
|
|
||||||
var keep;
|
|
||||||
|
|
||||||
keep = this.slice(position);
|
$.id = function(id) {
|
||||||
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) {
|
|
||||||
return d.getElementById(id);
|
return d.getElementById(id);
|
||||||
},
|
};
|
||||||
ready: function(fc) {
|
|
||||||
|
$.ready = function(fc) {
|
||||||
var cb, _ref;
|
var cb, _ref;
|
||||||
|
|
||||||
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
||||||
@ -395,8 +389,9 @@
|
|||||||
return fc();
|
return fc();
|
||||||
};
|
};
|
||||||
return $.on(d, 'DOMContentLoaded', cb);
|
return $.on(d, 'DOMContentLoaded', cb);
|
||||||
},
|
};
|
||||||
formData: function(form) {
|
|
||||||
|
$.formData = function(form) {
|
||||||
var fd, key, val;
|
var fd, key, val;
|
||||||
|
|
||||||
if (form instanceof HTMLFormElement) {
|
if (form instanceof HTMLFormElement) {
|
||||||
@ -415,8 +410,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
},
|
};
|
||||||
ajax: function(url, callbacks, opts) {
|
|
||||||
|
$.ajax = function(url, callbacks, opts) {
|
||||||
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
||||||
|
|
||||||
if (opts == null) {
|
if (opts == null) {
|
||||||
@ -436,8 +432,9 @@
|
|||||||
r.withCredentials = cred;
|
r.withCredentials = cred;
|
||||||
r.send(form);
|
r.send(form);
|
||||||
return r;
|
return r;
|
||||||
},
|
};
|
||||||
cache: (function() {
|
|
||||||
|
$.cache = (function() {
|
||||||
var reqs;
|
var reqs;
|
||||||
|
|
||||||
reqs = {};
|
reqs = {};
|
||||||
@ -472,8 +469,9 @@
|
|||||||
req.callbacks = [cb];
|
req.callbacks = [cb];
|
||||||
return reqs[url] = req;
|
return reqs[url] = req;
|
||||||
};
|
};
|
||||||
})(),
|
})();
|
||||||
cb: {
|
|
||||||
|
$.cb = {
|
||||||
checked: function() {
|
checked: function() {
|
||||||
$.set(this.name, this.checked);
|
$.set(this.name, this.checked);
|
||||||
return Conf[this.name] = this.checked;
|
return Conf[this.name] = this.checked;
|
||||||
@ -482,15 +480,17 @@
|
|||||||
$.set(this.name, this.value.trim());
|
$.set(this.name, this.value.trim());
|
||||||
return Conf[this.name] = this.value;
|
return Conf[this.name] = this.value;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
asap: function(test, cb) {
|
|
||||||
|
$.asap = function(test, cb) {
|
||||||
if (test()) {
|
if (test()) {
|
||||||
return cb();
|
return cb();
|
||||||
} else {
|
} else {
|
||||||
return setTimeout($.asap, 25, test, cb);
|
return setTimeout($.asap, 25, test, cb);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
addStyle: function(css, id) {
|
|
||||||
|
$.addStyle = function(css, id) {
|
||||||
var style;
|
var style;
|
||||||
|
|
||||||
style = $.el('style', {
|
style = $.el('style', {
|
||||||
@ -503,28 +503,35 @@
|
|||||||
return $.add(d.head, style);
|
return $.add(d.head, style);
|
||||||
});
|
});
|
||||||
return style;
|
return style;
|
||||||
},
|
};
|
||||||
x: function(path, root) {
|
|
||||||
|
$.x = function(path, root) {
|
||||||
root || (root = d.body);
|
root || (root = d.body);
|
||||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||||
},
|
};
|
||||||
X: function(path, root) {
|
|
||||||
|
$.X = function(path, root) {
|
||||||
root || (root = d.body);
|
root || (root = d.body);
|
||||||
return d.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
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);
|
return el.classList.add(className);
|
||||||
},
|
};
|
||||||
rmClass: function(el, className) {
|
|
||||||
|
$.rmClass = function(el, className) {
|
||||||
return el.classList.remove(className);
|
return el.classList.remove(className);
|
||||||
},
|
};
|
||||||
toggleClass: function(el, className) {
|
|
||||||
|
$.toggleClass = function(el, className) {
|
||||||
return el.classList.toggle(className);
|
return el.classList.toggle(className);
|
||||||
},
|
};
|
||||||
hasClass: function(el, className) {
|
|
||||||
|
$.hasClass = function(el, className) {
|
||||||
return el.classList.contains(className);
|
return el.classList.contains(className);
|
||||||
},
|
};
|
||||||
rm: (function() {
|
|
||||||
|
$.rm = (function() {
|
||||||
if ('remove' in Element.prototype) {
|
if ('remove' in Element.prototype) {
|
||||||
return function(el) {
|
return function(el) {
|
||||||
return el.remove();
|
return el.remove();
|
||||||
@ -536,21 +543,25 @@
|
|||||||
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
rmAll: function(root) {
|
|
||||||
|
$.rmAll = function(root) {
|
||||||
var node;
|
var node;
|
||||||
|
|
||||||
while (node = root.firstChild) {
|
while (node = root.firstChild) {
|
||||||
root.removeChild(node);
|
root.removeChild(node);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
tn: function(s) {
|
|
||||||
|
$.tn = function(s) {
|
||||||
return d.createTextNode(s);
|
return d.createTextNode(s);
|
||||||
},
|
};
|
||||||
frag: function() {
|
|
||||||
|
$.frag = function() {
|
||||||
return d.createDocumentFragment();
|
return d.createDocumentFragment();
|
||||||
},
|
};
|
||||||
nodes: function(nodes) {
|
|
||||||
|
$.nodes = function(nodes) {
|
||||||
var frag, node, _i, _len;
|
var frag, node, _i, _len;
|
||||||
|
|
||||||
if (!(nodes instanceof Array)) {
|
if (!(nodes instanceof Array)) {
|
||||||
@ -562,23 +573,29 @@
|
|||||||
frag.appendChild(node);
|
frag.appendChild(node);
|
||||||
}
|
}
|
||||||
return frag;
|
return frag;
|
||||||
},
|
};
|
||||||
add: function(parent, el) {
|
|
||||||
|
$.add = function(parent, el) {
|
||||||
return parent.appendChild($.nodes(el));
|
return parent.appendChild($.nodes(el));
|
||||||
},
|
};
|
||||||
prepend: function(parent, el) {
|
|
||||||
|
$.prepend = function(parent, el) {
|
||||||
return parent.insertBefore($.nodes(el), parent.firstChild);
|
return parent.insertBefore($.nodes(el), parent.firstChild);
|
||||||
},
|
};
|
||||||
after: function(root, el) {
|
|
||||||
|
$.after = function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
||||||
},
|
};
|
||||||
before: function(root, el) {
|
|
||||||
|
$.before = function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root);
|
return root.parentNode.insertBefore($.nodes(el), root);
|
||||||
},
|
};
|
||||||
replace: function(root, el) {
|
|
||||||
|
$.replace = function(root, el) {
|
||||||
return root.parentNode.replaceChild($.nodes(el), root);
|
return root.parentNode.replaceChild($.nodes(el), root);
|
||||||
},
|
};
|
||||||
el: function(tag, properties) {
|
|
||||||
|
$.el = function(tag, properties) {
|
||||||
var el;
|
var el;
|
||||||
|
|
||||||
el = d.createElement(tag);
|
el = d.createElement(tag);
|
||||||
@ -586,8 +603,9 @@
|
|||||||
$.extend(el, properties);
|
$.extend(el, properties);
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
},
|
};
|
||||||
on: function(el, events, handler) {
|
|
||||||
|
$.on = function(el, events, handler) {
|
||||||
var event, _i, _len, _ref;
|
var event, _i, _len, _ref;
|
||||||
|
|
||||||
_ref = events.split(' ');
|
_ref = events.split(' ');
|
||||||
@ -595,8 +613,9 @@
|
|||||||
event = _ref[_i];
|
event = _ref[_i];
|
||||||
el.addEventListener(event, handler, false);
|
el.addEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
off: function(el, events, handler) {
|
|
||||||
|
$.off = function(el, events, handler) {
|
||||||
var event, _i, _len, _ref;
|
var event, _i, _len, _ref;
|
||||||
|
|
||||||
_ref = events.split(' ');
|
_ref = events.split(' ');
|
||||||
@ -604,8 +623,9 @@
|
|||||||
event = _ref[_i];
|
event = _ref[_i];
|
||||||
el.removeEventListener(event, handler, false);
|
el.removeEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
event: function(event, detail, root) {
|
|
||||||
|
$.event = function(event, detail, root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = d;
|
root = d;
|
||||||
}
|
}
|
||||||
@ -613,8 +633,9 @@
|
|||||||
bubbles: true,
|
bubbles: true,
|
||||||
detail: detail
|
detail: detail
|
||||||
}));
|
}));
|
||||||
},
|
};
|
||||||
open: (function() {
|
|
||||||
|
$.open = (function() {
|
||||||
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
||||||
return function(URL) {
|
return function(URL) {
|
||||||
var a;
|
var a;
|
||||||
@ -629,8 +650,9 @@
|
|||||||
return window.open(URL, '_blank');
|
return window.open(URL, '_blank');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
debounce: function(wait, fn) {
|
|
||||||
|
$.debounce = function(wait, fn) {
|
||||||
var args, exec, that, timeout;
|
var args, exec, that, timeout;
|
||||||
|
|
||||||
timeout = null;
|
timeout = null;
|
||||||
@ -650,8 +672,9 @@
|
|||||||
}
|
}
|
||||||
return timeout = setTimeout(exec, wait);
|
return timeout = setTimeout(exec, wait);
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
queueTask: (function() {
|
|
||||||
|
$.queueTask = (function() {
|
||||||
var execTask, taskChannel, taskQueue;
|
var execTask, taskChannel, taskQueue;
|
||||||
|
|
||||||
taskQueue = [];
|
taskQueue = [];
|
||||||
@ -676,8 +699,9 @@
|
|||||||
return setTimeout(execTask, 0);
|
return setTimeout(execTask, 0);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
globalEval: function(code) {
|
|
||||||
|
$.globalEval = function(code) {
|
||||||
var script;
|
var script;
|
||||||
|
|
||||||
script = $.el('script', {
|
script = $.el('script', {
|
||||||
@ -685,8 +709,9 @@
|
|||||||
});
|
});
|
||||||
$.add(d.head || doc, script);
|
$.add(d.head || doc, script);
|
||||||
return $.rm(script);
|
return $.rm(script);
|
||||||
},
|
};
|
||||||
bytesToString: function(size) {
|
|
||||||
|
$.bytesToString = function(size) {
|
||||||
var unit;
|
var unit;
|
||||||
|
|
||||||
unit = 0;
|
unit = 0;
|
||||||
@ -696,12 +721,15 @@
|
|||||||
}
|
}
|
||||||
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
||||||
return "" + size + " " + ['B', 'KB', 'MB', 'GB'][unit];
|
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);
|
return (value < min ? min : value > max ? max : value);
|
||||||
},
|
};
|
||||||
syncing: {},
|
|
||||||
sync: (function() {
|
$.syncing = {};
|
||||||
|
|
||||||
|
$.sync = (function() {
|
||||||
window.addEventListener('storage', function(e) {
|
window.addEventListener('storage', function(e) {
|
||||||
var cb;
|
var cb;
|
||||||
|
|
||||||
@ -712,15 +740,17 @@
|
|||||||
return function(key, cb) {
|
return function(key, cb) {
|
||||||
return $.syncing[g.NAMESPACE + key] = cb;
|
return $.syncing[g.NAMESPACE + key] = cb;
|
||||||
};
|
};
|
||||||
})(),
|
})();
|
||||||
item: function(key, val) {
|
|
||||||
|
$.item = function(key, val) {
|
||||||
var item;
|
var item;
|
||||||
|
|
||||||
item = {};
|
item = {};
|
||||||
item[key] = val;
|
item[key] = val;
|
||||||
return item;
|
return item;
|
||||||
},
|
};
|
||||||
"delete": function(keys) {
|
|
||||||
|
$["delete"] = function(keys) {
|
||||||
var key, _i, _len;
|
var key, _i, _len;
|
||||||
|
|
||||||
if (!(keys instanceof Array)) {
|
if (!(keys instanceof Array)) {
|
||||||
@ -732,8 +762,9 @@
|
|||||||
localStorage.removeItem(key);
|
localStorage.removeItem(key);
|
||||||
GM_deleteValue(key);
|
GM_deleteValue(key);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
get: function(key, val, cb) {
|
|
||||||
|
$.get = function(key, val, cb) {
|
||||||
var items;
|
var items;
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
@ -750,8 +781,9 @@
|
|||||||
}
|
}
|
||||||
return cb(items);
|
return cb(items);
|
||||||
});
|
});
|
||||||
},
|
};
|
||||||
set: (function() {
|
|
||||||
|
$.set = (function() {
|
||||||
var set;
|
var set;
|
||||||
|
|
||||||
set = function(key, val) {
|
set = function(key, val) {
|
||||||
@ -774,8 +806,14 @@
|
|||||||
set(key, val);
|
set(key, val);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})()
|
})();
|
||||||
});
|
|
||||||
|
$$ = function(selector, root) {
|
||||||
|
if (root == null) {
|
||||||
|
root = d.body;
|
||||||
|
}
|
||||||
|
return __slice.call(root.querySelectorAll(selector));
|
||||||
|
};
|
||||||
|
|
||||||
Build = {
|
Build = {
|
||||||
spoilerRange: {},
|
spoilerRange: {},
|
||||||
|
|||||||
@ -196,6 +196,59 @@
|
|||||||
posts: {}
|
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) {
|
$ = function(selector, root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = d.body;
|
root = d.body;
|
||||||
@ -203,15 +256,6 @@
|
|||||||
return root.querySelector(selector);
|
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) {
|
$.extend = function(object, properties) {
|
||||||
var key, val;
|
var key, val;
|
||||||
|
|
||||||
@ -224,63 +268,13 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
$.extend(Array.prototype, {
|
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)));
|
||||||
add: function(object, position) {
|
|
||||||
var keep;
|
|
||||||
|
|
||||||
keep = this.slice(position);
|
$.id = function(id) {
|
||||||
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) {
|
|
||||||
return d.getElementById(id);
|
return d.getElementById(id);
|
||||||
},
|
};
|
||||||
ready: function(fc) {
|
|
||||||
|
$.ready = function(fc) {
|
||||||
var cb, _ref;
|
var cb, _ref;
|
||||||
|
|
||||||
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
if ((_ref = d.readyState) === 'interactive' || _ref === 'complete') {
|
||||||
@ -292,8 +286,9 @@
|
|||||||
return fc();
|
return fc();
|
||||||
};
|
};
|
||||||
return $.on(d, 'DOMContentLoaded', cb);
|
return $.on(d, 'DOMContentLoaded', cb);
|
||||||
},
|
};
|
||||||
formData: function(form) {
|
|
||||||
|
$.formData = function(form) {
|
||||||
var fd, key, val;
|
var fd, key, val;
|
||||||
|
|
||||||
if (form instanceof HTMLFormElement) {
|
if (form instanceof HTMLFormElement) {
|
||||||
@ -312,8 +307,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return fd;
|
return fd;
|
||||||
},
|
};
|
||||||
ajax: function(url, callbacks, opts) {
|
|
||||||
|
$.ajax = function(url, callbacks, opts) {
|
||||||
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
var cred, form, headers, key, r, sync, type, upCallbacks, val;
|
||||||
|
|
||||||
if (opts == null) {
|
if (opts == null) {
|
||||||
@ -333,8 +329,9 @@
|
|||||||
r.withCredentials = cred;
|
r.withCredentials = cred;
|
||||||
r.send(form);
|
r.send(form);
|
||||||
return r;
|
return r;
|
||||||
},
|
};
|
||||||
cache: (function() {
|
|
||||||
|
$.cache = (function() {
|
||||||
var reqs;
|
var reqs;
|
||||||
|
|
||||||
reqs = {};
|
reqs = {};
|
||||||
@ -369,8 +366,9 @@
|
|||||||
req.callbacks = [cb];
|
req.callbacks = [cb];
|
||||||
return reqs[url] = req;
|
return reqs[url] = req;
|
||||||
};
|
};
|
||||||
})(),
|
})();
|
||||||
cb: {
|
|
||||||
|
$.cb = {
|
||||||
checked: function() {
|
checked: function() {
|
||||||
$.set(this.name, this.checked);
|
$.set(this.name, this.checked);
|
||||||
return Conf[this.name] = this.checked;
|
return Conf[this.name] = this.checked;
|
||||||
@ -379,15 +377,17 @@
|
|||||||
$.set(this.name, this.value.trim());
|
$.set(this.name, this.value.trim());
|
||||||
return Conf[this.name] = this.value;
|
return Conf[this.name] = this.value;
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
asap: function(test, cb) {
|
|
||||||
|
$.asap = function(test, cb) {
|
||||||
if (test()) {
|
if (test()) {
|
||||||
return cb();
|
return cb();
|
||||||
} else {
|
} else {
|
||||||
return setTimeout($.asap, 25, test, cb);
|
return setTimeout($.asap, 25, test, cb);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
addStyle: function(css, id) {
|
|
||||||
|
$.addStyle = function(css, id) {
|
||||||
var style;
|
var style;
|
||||||
|
|
||||||
style = $.el('style', {
|
style = $.el('style', {
|
||||||
@ -400,28 +400,35 @@
|
|||||||
return $.add(d.head, style);
|
return $.add(d.head, style);
|
||||||
});
|
});
|
||||||
return style;
|
return style;
|
||||||
},
|
};
|
||||||
x: function(path, root) {
|
|
||||||
|
$.x = function(path, root) {
|
||||||
root || (root = d.body);
|
root || (root = d.body);
|
||||||
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
return d.evaluate(path, root, null, 8, null).singleNodeValue;
|
||||||
},
|
};
|
||||||
X: function(path, root) {
|
|
||||||
|
$.X = function(path, root) {
|
||||||
root || (root = d.body);
|
root || (root = d.body);
|
||||||
return d.evaluate(path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
|
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);
|
return el.classList.add(className);
|
||||||
},
|
};
|
||||||
rmClass: function(el, className) {
|
|
||||||
|
$.rmClass = function(el, className) {
|
||||||
return el.classList.remove(className);
|
return el.classList.remove(className);
|
||||||
},
|
};
|
||||||
toggleClass: function(el, className) {
|
|
||||||
|
$.toggleClass = function(el, className) {
|
||||||
return el.classList.toggle(className);
|
return el.classList.toggle(className);
|
||||||
},
|
};
|
||||||
hasClass: function(el, className) {
|
|
||||||
|
$.hasClass = function(el, className) {
|
||||||
return el.classList.contains(className);
|
return el.classList.contains(className);
|
||||||
},
|
};
|
||||||
rm: (function() {
|
|
||||||
|
$.rm = (function() {
|
||||||
if ('remove' in Element.prototype) {
|
if ('remove' in Element.prototype) {
|
||||||
return function(el) {
|
return function(el) {
|
||||||
return el.remove();
|
return el.remove();
|
||||||
@ -433,21 +440,25 @@
|
|||||||
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
return (_ref = el.parentNode) != null ? _ref.removeChild(el) : void 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
rmAll: function(root) {
|
|
||||||
|
$.rmAll = function(root) {
|
||||||
var node;
|
var node;
|
||||||
|
|
||||||
while (node = root.firstChild) {
|
while (node = root.firstChild) {
|
||||||
root.removeChild(node);
|
root.removeChild(node);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
tn: function(s) {
|
|
||||||
|
$.tn = function(s) {
|
||||||
return d.createTextNode(s);
|
return d.createTextNode(s);
|
||||||
},
|
};
|
||||||
frag: function() {
|
|
||||||
|
$.frag = function() {
|
||||||
return d.createDocumentFragment();
|
return d.createDocumentFragment();
|
||||||
},
|
};
|
||||||
nodes: function(nodes) {
|
|
||||||
|
$.nodes = function(nodes) {
|
||||||
var frag, node, _i, _len;
|
var frag, node, _i, _len;
|
||||||
|
|
||||||
if (!(nodes instanceof Array)) {
|
if (!(nodes instanceof Array)) {
|
||||||
@ -459,23 +470,29 @@
|
|||||||
frag.appendChild(node);
|
frag.appendChild(node);
|
||||||
}
|
}
|
||||||
return frag;
|
return frag;
|
||||||
},
|
};
|
||||||
add: function(parent, el) {
|
|
||||||
|
$.add = function(parent, el) {
|
||||||
return parent.appendChild($.nodes(el));
|
return parent.appendChild($.nodes(el));
|
||||||
},
|
};
|
||||||
prepend: function(parent, el) {
|
|
||||||
|
$.prepend = function(parent, el) {
|
||||||
return parent.insertBefore($.nodes(el), parent.firstChild);
|
return parent.insertBefore($.nodes(el), parent.firstChild);
|
||||||
},
|
};
|
||||||
after: function(root, el) {
|
|
||||||
|
$.after = function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
return root.parentNode.insertBefore($.nodes(el), root.nextSibling);
|
||||||
},
|
};
|
||||||
before: function(root, el) {
|
|
||||||
|
$.before = function(root, el) {
|
||||||
return root.parentNode.insertBefore($.nodes(el), root);
|
return root.parentNode.insertBefore($.nodes(el), root);
|
||||||
},
|
};
|
||||||
replace: function(root, el) {
|
|
||||||
|
$.replace = function(root, el) {
|
||||||
return root.parentNode.replaceChild($.nodes(el), root);
|
return root.parentNode.replaceChild($.nodes(el), root);
|
||||||
},
|
};
|
||||||
el: function(tag, properties) {
|
|
||||||
|
$.el = function(tag, properties) {
|
||||||
var el;
|
var el;
|
||||||
|
|
||||||
el = d.createElement(tag);
|
el = d.createElement(tag);
|
||||||
@ -483,8 +500,9 @@
|
|||||||
$.extend(el, properties);
|
$.extend(el, properties);
|
||||||
}
|
}
|
||||||
return el;
|
return el;
|
||||||
},
|
};
|
||||||
on: function(el, events, handler) {
|
|
||||||
|
$.on = function(el, events, handler) {
|
||||||
var event, _i, _len, _ref;
|
var event, _i, _len, _ref;
|
||||||
|
|
||||||
_ref = events.split(' ');
|
_ref = events.split(' ');
|
||||||
@ -492,8 +510,9 @@
|
|||||||
event = _ref[_i];
|
event = _ref[_i];
|
||||||
el.addEventListener(event, handler, false);
|
el.addEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
off: function(el, events, handler) {
|
|
||||||
|
$.off = function(el, events, handler) {
|
||||||
var event, _i, _len, _ref;
|
var event, _i, _len, _ref;
|
||||||
|
|
||||||
_ref = events.split(' ');
|
_ref = events.split(' ');
|
||||||
@ -501,8 +520,9 @@
|
|||||||
event = _ref[_i];
|
event = _ref[_i];
|
||||||
el.removeEventListener(event, handler, false);
|
el.removeEventListener(event, handler, false);
|
||||||
}
|
}
|
||||||
},
|
};
|
||||||
event: function(event, detail, root) {
|
|
||||||
|
$.event = function(event, detail, root) {
|
||||||
if (root == null) {
|
if (root == null) {
|
||||||
root = d;
|
root = d;
|
||||||
}
|
}
|
||||||
@ -510,8 +530,9 @@
|
|||||||
bubbles: true,
|
bubbles: true,
|
||||||
detail: detail
|
detail: detail
|
||||||
}));
|
}));
|
||||||
},
|
};
|
||||||
open: (function() {
|
|
||||||
|
$.open = (function() {
|
||||||
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
if (typeof GM_openInTab !== "undefined" && GM_openInTab !== null) {
|
||||||
return function(URL) {
|
return function(URL) {
|
||||||
var a;
|
var a;
|
||||||
@ -526,8 +547,9 @@
|
|||||||
return window.open(URL, '_blank');
|
return window.open(URL, '_blank');
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
debounce: function(wait, fn) {
|
|
||||||
|
$.debounce = function(wait, fn) {
|
||||||
var args, exec, that, timeout;
|
var args, exec, that, timeout;
|
||||||
|
|
||||||
timeout = null;
|
timeout = null;
|
||||||
@ -547,8 +569,9 @@
|
|||||||
}
|
}
|
||||||
return timeout = setTimeout(exec, wait);
|
return timeout = setTimeout(exec, wait);
|
||||||
};
|
};
|
||||||
},
|
};
|
||||||
queueTask: (function() {
|
|
||||||
|
$.queueTask = (function() {
|
||||||
var execTask, taskChannel, taskQueue;
|
var execTask, taskChannel, taskQueue;
|
||||||
|
|
||||||
taskQueue = [];
|
taskQueue = [];
|
||||||
@ -573,8 +596,9 @@
|
|||||||
return setTimeout(execTask, 0);
|
return setTimeout(execTask, 0);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
})(),
|
})();
|
||||||
globalEval: function(code) {
|
|
||||||
|
$.globalEval = function(code) {
|
||||||
var script;
|
var script;
|
||||||
|
|
||||||
script = $.el('script', {
|
script = $.el('script', {
|
||||||
@ -582,8 +606,9 @@
|
|||||||
});
|
});
|
||||||
$.add(d.head || doc, script);
|
$.add(d.head || doc, script);
|
||||||
return $.rm(script);
|
return $.rm(script);
|
||||||
},
|
};
|
||||||
bytesToString: function(size) {
|
|
||||||
|
$.bytesToString = function(size) {
|
||||||
var unit;
|
var unit;
|
||||||
|
|
||||||
unit = 0;
|
unit = 0;
|
||||||
@ -593,12 +618,15 @@
|
|||||||
}
|
}
|
||||||
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
size = unit > 1 ? Math.round(size * 100) / 100 : Math.round(size);
|
||||||
return "" + size + " " + ['B', 'KB', 'MB', 'GB'][unit];
|
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);
|
return (value < min ? min : value > max ? max : value);
|
||||||
},
|
};
|
||||||
syncing: {},
|
|
||||||
sync: (function() {
|
$.syncing = {};
|
||||||
|
|
||||||
|
$.sync = (function() {
|
||||||
chrome.storage.onChanged.addListener(function(changes) {
|
chrome.storage.onChanged.addListener(function(changes) {
|
||||||
var cb, key;
|
var cb, key;
|
||||||
|
|
||||||
@ -611,18 +639,21 @@
|
|||||||
return function(key, cb) {
|
return function(key, cb) {
|
||||||
return $.syncing[key] = cb;
|
return $.syncing[key] = cb;
|
||||||
};
|
};
|
||||||
})(),
|
})();
|
||||||
item: function(key, val) {
|
|
||||||
|
$.item = function(key, val) {
|
||||||
var item;
|
var item;
|
||||||
|
|
||||||
item = {};
|
item = {};
|
||||||
item[key] = val;
|
item[key] = val;
|
||||||
return item;
|
return item;
|
||||||
},
|
};
|
||||||
"delete": function(keys) {
|
|
||||||
|
$["delete"] = function(keys) {
|
||||||
return chrome.storage.sync.remove(keys);
|
return chrome.storage.sync.remove(keys);
|
||||||
},
|
};
|
||||||
get: function(key, val, cb) {
|
|
||||||
|
$.get = function(key, val, cb) {
|
||||||
var items;
|
var items;
|
||||||
|
|
||||||
if (typeof cb === 'function') {
|
if (typeof cb === 'function') {
|
||||||
@ -632,14 +663,21 @@
|
|||||||
cb = val;
|
cb = val;
|
||||||
}
|
}
|
||||||
return chrome.storage.sync.get(items, cb);
|
return chrome.storage.sync.get(items, cb);
|
||||||
},
|
};
|
||||||
set: function(key, val) {
|
|
||||||
|
$.set = function(key, val) {
|
||||||
var items;
|
var items;
|
||||||
|
|
||||||
items = typeof key === 'string' ? $.item(key, val) : key;
|
items = typeof key === 'string' ? $.item(key, val) : key;
|
||||||
return chrome.storage.sync.set(items);
|
return chrome.storage.sync.set(items);
|
||||||
|
};
|
||||||
|
|
||||||
|
$$ = function(selector, root) {
|
||||||
|
if (root == null) {
|
||||||
|
root = d.body;
|
||||||
}
|
}
|
||||||
});
|
return __slice.call(root.querySelectorAll(selector));
|
||||||
|
};
|
||||||
|
|
||||||
Build = {
|
Build = {
|
||||||
spoilerRange: {},
|
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:
|
# loosely follows the jquery api:
|
||||||
# http://api.jquery.com/
|
# http://api.jquery.com/
|
||||||
# not chainable
|
# not chainable
|
||||||
$ = (selector, root=d.body) ->
|
$ = (selector, root=d.body) ->
|
||||||
root.querySelector selector
|
root.querySelector selector
|
||||||
|
|
||||||
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)))
|
|
||||||
|
|
||||||
$$ = (selector, root=d.body) ->
|
|
||||||
[root.querySelectorAll(selector)...]
|
|
||||||
|
|
||||||
$.extend = (object, properties) ->
|
$.extend = (object, properties) ->
|
||||||
for key, val of properties
|
for key, val of properties
|
||||||
continue unless properties.hasOwnProperty key
|
continue unless properties.hasOwnProperty key
|
||||||
object[key] = val
|
object[key] = val
|
||||||
return
|
return
|
||||||
|
|
||||||
# Various prototypes I've wanted or needed to add.
|
$.DAY = 24 * ($.HOUR = 60 * ($.MINUTE = 60 * ($.SECOND = 1000)))
|
||||||
$.extend Array::,
|
|
||||||
add: (object, position) ->
|
|
||||||
keep = @slice position
|
|
||||||
@length = position
|
|
||||||
@push object
|
|
||||||
@pushArrays keep
|
|
||||||
|
|
||||||
contains: (object) ->
|
$.id = (id) ->
|
||||||
@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) ->
|
|
||||||
d.getElementById id
|
d.getElementById id
|
||||||
ready: (fc) ->
|
|
||||||
|
$.ready = (fc) ->
|
||||||
if d.readyState in ['interactive', 'complete']
|
if d.readyState in ['interactive', 'complete']
|
||||||
$.queueTask fc
|
$.queueTask fc
|
||||||
return
|
return
|
||||||
@ -62,7 +56,8 @@ $.extend $,
|
|||||||
$.off d, 'DOMContentLoaded', cb
|
$.off d, 'DOMContentLoaded', cb
|
||||||
fc()
|
fc()
|
||||||
$.on d, 'DOMContentLoaded', cb
|
$.on d, 'DOMContentLoaded', cb
|
||||||
formData: (form) ->
|
|
||||||
|
$.formData = (form) ->
|
||||||
if form instanceof HTMLFormElement
|
if form instanceof HTMLFormElement
|
||||||
return new FormData form
|
return new FormData form
|
||||||
fd = new FormData()
|
fd = new FormData()
|
||||||
@ -75,7 +70,8 @@ $.extend $,
|
|||||||
else
|
else
|
||||||
fd.append key, val
|
fd.append key, val
|
||||||
fd
|
fd
|
||||||
ajax: (url, callbacks, opts={}) ->
|
|
||||||
|
$.ajax = (url, callbacks, opts={}) ->
|
||||||
{type, cred, headers, upCallbacks, form, sync} = opts
|
{type, cred, headers, upCallbacks, form, sync} = opts
|
||||||
r = new XMLHttpRequest()
|
r = new XMLHttpRequest()
|
||||||
r.overrideMimeType 'text/html'
|
r.overrideMimeType 'text/html'
|
||||||
@ -88,7 +84,8 @@ $.extend $,
|
|||||||
r.withCredentials = cred
|
r.withCredentials = cred
|
||||||
r.send form
|
r.send form
|
||||||
r
|
r
|
||||||
cache: do ->
|
|
||||||
|
$.cache = do ->
|
||||||
reqs = {}
|
reqs = {}
|
||||||
(url, cb) ->
|
(url, cb) ->
|
||||||
if req = reqs[url]
|
if req = reqs[url]
|
||||||
@ -106,87 +103,111 @@ $.extend $,
|
|||||||
onerror: rm
|
onerror: rm
|
||||||
req.callbacks = [cb]
|
req.callbacks = [cb]
|
||||||
reqs[url] = req
|
reqs[url] = req
|
||||||
cb:
|
|
||||||
|
$.cb =
|
||||||
checked: ->
|
checked: ->
|
||||||
$.set @name, @checked
|
$.set @name, @checked
|
||||||
Conf[@name] = @checked
|
Conf[@name] = @checked
|
||||||
value: ->
|
value: ->
|
||||||
$.set @name, @value.trim()
|
$.set @name, @value.trim()
|
||||||
Conf[@name] = @value
|
Conf[@name] = @value
|
||||||
asap: (test, cb) ->
|
|
||||||
|
$.asap = (test, cb) ->
|
||||||
if test()
|
if test()
|
||||||
cb()
|
cb()
|
||||||
else
|
else
|
||||||
setTimeout $.asap, 25, test, cb
|
setTimeout $.asap, 25, test, cb
|
||||||
addStyle: (css, id) ->
|
|
||||||
|
$.addStyle = (css, id) ->
|
||||||
style = $.el 'style',
|
style = $.el 'style',
|
||||||
id: id
|
id: id
|
||||||
textContent: css
|
textContent: css
|
||||||
$.asap (-> d.head), ->
|
$.asap (-> d.head), ->
|
||||||
$.add d.head, style
|
$.add d.head, style
|
||||||
style
|
style
|
||||||
x: (path, root) ->
|
|
||||||
|
$.x = (path, root) ->
|
||||||
root or= d.body
|
root or= d.body
|
||||||
# XPathResult.ANY_UNORDERED_NODE_TYPE === 8
|
# XPathResult.ANY_UNORDERED_NODE_TYPE === 8
|
||||||
d.evaluate(path, root, null, 8, null).singleNodeValue
|
d.evaluate(path, root, null, 8, null).singleNodeValue
|
||||||
X: (path, root) ->
|
|
||||||
|
$.X = (path, root) ->
|
||||||
root or= d.body
|
root or= d.body
|
||||||
d.evaluate path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
|
d.evaluate path, root, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null
|
||||||
addClass: (el, className) ->
|
|
||||||
|
$.addClass = (el, className) ->
|
||||||
el.classList.add className
|
el.classList.add className
|
||||||
rmClass: (el, className) ->
|
|
||||||
|
$.rmClass = (el, className) ->
|
||||||
el.classList.remove className
|
el.classList.remove className
|
||||||
toggleClass: (el, className) ->
|
|
||||||
|
$.toggleClass = (el, className) ->
|
||||||
el.classList.toggle className
|
el.classList.toggle className
|
||||||
hasClass: (el, className) ->
|
|
||||||
|
$.hasClass = (el, className) ->
|
||||||
el.classList.contains className
|
el.classList.contains className
|
||||||
rm: do ->
|
|
||||||
|
$.rm = do ->
|
||||||
if 'remove' of Element.prototype
|
if 'remove' of Element.prototype
|
||||||
(el) -> el.remove()
|
(el) -> el.remove()
|
||||||
else
|
else
|
||||||
(el) -> el.parentNode?.removeChild el
|
(el) -> el.parentNode?.removeChild el
|
||||||
rmAll: (root) ->
|
|
||||||
|
$.rmAll = (root) ->
|
||||||
# jsperf.com/emptify-element
|
# jsperf.com/emptify-element
|
||||||
while node = root.firstChild
|
while node = root.firstChild
|
||||||
# HTMLSelectElement.remove !== Element.remove
|
# HTMLSelectElement.remove !== Element.remove
|
||||||
root.removeChild node
|
root.removeChild node
|
||||||
return
|
return
|
||||||
tn: (s) ->
|
|
||||||
|
$.tn = (s) ->
|
||||||
d.createTextNode s
|
d.createTextNode s
|
||||||
frag: ->
|
|
||||||
|
$.frag = ->
|
||||||
d.createDocumentFragment()
|
d.createDocumentFragment()
|
||||||
nodes: (nodes) ->
|
|
||||||
|
$.nodes = (nodes) ->
|
||||||
unless nodes instanceof Array
|
unless nodes instanceof Array
|
||||||
return nodes
|
return nodes
|
||||||
frag = $.frag()
|
frag = $.frag()
|
||||||
for node in nodes
|
for node in nodes
|
||||||
frag.appendChild node
|
frag.appendChild node
|
||||||
frag
|
frag
|
||||||
add: (parent, el) ->
|
|
||||||
|
$.add = (parent, el) ->
|
||||||
parent.appendChild $.nodes el
|
parent.appendChild $.nodes el
|
||||||
prepend: (parent, el) ->
|
|
||||||
|
$.prepend = (parent, el) ->
|
||||||
parent.insertBefore $.nodes(el), parent.firstChild
|
parent.insertBefore $.nodes(el), parent.firstChild
|
||||||
after: (root, el) ->
|
|
||||||
|
$.after = (root, el) ->
|
||||||
root.parentNode.insertBefore $.nodes(el), root.nextSibling
|
root.parentNode.insertBefore $.nodes(el), root.nextSibling
|
||||||
before: (root, el) ->
|
|
||||||
|
$.before = (root, el) ->
|
||||||
root.parentNode.insertBefore $.nodes(el), root
|
root.parentNode.insertBefore $.nodes(el), root
|
||||||
replace: (root, el) ->
|
|
||||||
|
$.replace = (root, el) ->
|
||||||
root.parentNode.replaceChild $.nodes(el), root
|
root.parentNode.replaceChild $.nodes(el), root
|
||||||
el: (tag, properties) ->
|
|
||||||
|
$.el = (tag, properties) ->
|
||||||
el = d.createElement tag
|
el = d.createElement tag
|
||||||
$.extend el, properties if properties
|
$.extend el, properties if properties
|
||||||
el
|
el
|
||||||
on: (el, events, handler) ->
|
|
||||||
|
$.on = (el, events, handler) ->
|
||||||
for event in events.split ' '
|
for event in events.split ' '
|
||||||
el.addEventListener event, handler, false
|
el.addEventListener event, handler, false
|
||||||
return
|
return
|
||||||
off: (el, events, handler) ->
|
|
||||||
|
$.off = (el, events, handler) ->
|
||||||
for event in events.split ' '
|
for event in events.split ' '
|
||||||
el.removeEventListener event, handler, false
|
el.removeEventListener event, handler, false
|
||||||
return
|
return
|
||||||
event: (event, detail, root=d) ->
|
|
||||||
|
$.event = (event, detail, root=d) ->
|
||||||
root.dispatchEvent new CustomEvent event, {bubbles: true, detail}
|
root.dispatchEvent new CustomEvent event, {bubbles: true, detail}
|
||||||
open: do ->
|
|
||||||
|
$.open = do ->
|
||||||
if GM_openInTab?
|
if GM_openInTab?
|
||||||
(URL) ->
|
(URL) ->
|
||||||
# XXX fix GM opening file://// for protocol-less URLs.
|
# XXX fix GM opening file://// for protocol-less URLs.
|
||||||
@ -194,7 +215,8 @@ $.extend $,
|
|||||||
GM_openInTab a.href
|
GM_openInTab a.href
|
||||||
else
|
else
|
||||||
(URL) -> window.open URL, '_blank'
|
(URL) -> window.open URL, '_blank'
|
||||||
debounce: (wait, fn) ->
|
|
||||||
|
$.debounce = (wait, fn) ->
|
||||||
timeout = null
|
timeout = null
|
||||||
that = null
|
that = null
|
||||||
args = null
|
args = null
|
||||||
@ -212,7 +234,8 @@ $.extend $,
|
|||||||
|
|
||||||
# after wait, let next invocation execute immediately
|
# after wait, let next invocation execute immediately
|
||||||
timeout = setTimeout exec, wait
|
timeout = setTimeout exec, wait
|
||||||
queueTask: do ->
|
|
||||||
|
$.queueTask = do ->
|
||||||
# inspired by https://www.w3.org/Bugs/Public/show_bug.cgi?id=15007
|
# inspired by https://www.w3.org/Bugs/Public/show_bug.cgi?id=15007
|
||||||
taskQueue = []
|
taskQueue = []
|
||||||
execTask = ->
|
execTask = ->
|
||||||
@ -230,12 +253,14 @@ $.extend $,
|
|||||||
->
|
->
|
||||||
taskQueue.push arguments
|
taskQueue.push arguments
|
||||||
setTimeout execTask, 0
|
setTimeout execTask, 0
|
||||||
globalEval: (code) ->
|
|
||||||
|
$.globalEval = (code) ->
|
||||||
script = $.el 'script',
|
script = $.el 'script',
|
||||||
textContent: code
|
textContent: code
|
||||||
$.add (d.head or doc), script
|
$.add (d.head or doc), script
|
||||||
$.rm script
|
$.rm script
|
||||||
bytesToString: (size) ->
|
|
||||||
|
$.bytesToString = (size) ->
|
||||||
unit = 0 # Bytes
|
unit = 0 # Bytes
|
||||||
while size >= 1024
|
while size >= 1024
|
||||||
size /= 1024
|
size /= 1024
|
||||||
@ -250,7 +275,8 @@ $.extend $,
|
|||||||
# Round to an integer otherwise.
|
# Round to an integer otherwise.
|
||||||
Math.round size
|
Math.round size
|
||||||
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
"#{size} #{['B', 'KB', 'MB', 'GB'][unit]}"
|
||||||
minmax: (value, min, max) ->
|
|
||||||
|
$.minmax = (value, min, max) ->
|
||||||
return (
|
return (
|
||||||
if value < min
|
if value < min
|
||||||
min
|
min
|
||||||
@ -260,8 +286,10 @@ $.extend $,
|
|||||||
else
|
else
|
||||||
value
|
value
|
||||||
)
|
)
|
||||||
syncing: {}
|
|
||||||
sync: do ->
|
$.syncing = {}
|
||||||
|
|
||||||
|
$.sync = do ->
|
||||||
<% if (type === 'crx') { %>
|
<% if (type === 'crx') { %>
|
||||||
chrome.storage.onChanged.addListener (changes) ->
|
chrome.storage.onChanged.addListener (changes) ->
|
||||||
for key of changes
|
for key of changes
|
||||||
@ -276,27 +304,32 @@ $.extend $,
|
|||||||
, false
|
, false
|
||||||
(key, cb) -> $.syncing[g.NAMESPACE + key] = cb
|
(key, cb) -> $.syncing[g.NAMESPACE + key] = cb
|
||||||
<% } %>
|
<% } %>
|
||||||
item: (key, val) ->
|
|
||||||
|
$.item = (key, val) ->
|
||||||
item = {}
|
item = {}
|
||||||
item[key] = val
|
item[key] = val
|
||||||
item
|
item
|
||||||
<% if (type === 'crx') { %>
|
<% if (type === 'crx') { %>
|
||||||
# https://developer.chrome.com/extensions/storage.html
|
# https://developer.chrome.com/extensions/storage.html
|
||||||
delete: (keys) ->
|
|
||||||
|
$.delete = (keys) ->
|
||||||
chrome.storage.sync.remove keys
|
chrome.storage.sync.remove keys
|
||||||
get: (key, val, cb) ->
|
|
||||||
|
$.get = (key, val, cb) ->
|
||||||
if typeof cb is 'function'
|
if typeof cb is 'function'
|
||||||
items = $.item key, val
|
items = $.item key, val
|
||||||
else
|
else
|
||||||
items = key
|
items = key
|
||||||
cb = val
|
cb = val
|
||||||
chrome.storage.sync.get items, cb
|
chrome.storage.sync.get items, cb
|
||||||
set: (key, val) ->
|
|
||||||
|
$.set = (key, val) ->
|
||||||
items = if typeof key is 'string'
|
items = if typeof key is 'string'
|
||||||
$.item key, val
|
$.item key, val
|
||||||
else
|
else
|
||||||
key
|
key
|
||||||
chrome.storage.sync.set items
|
chrome.storage.sync.set items
|
||||||
|
|
||||||
<% } else if (type === 'userjs') { %>
|
<% } else if (type === 'userjs') { %>
|
||||||
do ->
|
do ->
|
||||||
# http://www.opera.com/docs/userjs/specs/#scriptstorage
|
# http://www.opera.com/docs/userjs/specs/#scriptstorage
|
||||||
@ -326,7 +359,7 @@ do ->
|
|||||||
if val = scriptStorage[g.NAMESPACE + key]
|
if val = scriptStorage[g.NAMESPACE + key]
|
||||||
items[key] = JSON.parse val
|
items[key] = JSON.parse val
|
||||||
cb items
|
cb items
|
||||||
$.set = do ->
|
$.set = do ->
|
||||||
set = (key, val) ->
|
set = (key, val) ->
|
||||||
key = g.NAMESPACE + key
|
key = g.NAMESPACE + key
|
||||||
val = JSON.stringify val
|
val = JSON.stringify val
|
||||||
@ -342,8 +375,9 @@ do ->
|
|||||||
set key, val
|
set key, val
|
||||||
return
|
return
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
# http://wiki.greasespot.net/Main_Page
|
|
||||||
delete: (keys) ->
|
# http://wiki.greasespot.net/Main_Page
|
||||||
|
$.delete = (keys) ->
|
||||||
unless keys instanceof Array
|
unless keys instanceof Array
|
||||||
keys = [keys]
|
keys = [keys]
|
||||||
for key in keys
|
for key in keys
|
||||||
@ -351,7 +385,8 @@ do ->
|
|||||||
localStorage.removeItem key
|
localStorage.removeItem key
|
||||||
GM_deleteValue key
|
GM_deleteValue key
|
||||||
return
|
return
|
||||||
get: (key, val, cb) ->
|
|
||||||
|
$.get = (key, val, cb) ->
|
||||||
if typeof cb is 'function'
|
if typeof cb is 'function'
|
||||||
items = $.item key, val
|
items = $.item key, val
|
||||||
else
|
else
|
||||||
@ -362,7 +397,8 @@ do ->
|
|||||||
if val = GM_getValue g.NAMESPACE + key
|
if val = GM_getValue g.NAMESPACE + key
|
||||||
items[key] = JSON.parse val
|
items[key] = JSON.parse val
|
||||||
cb items
|
cb items
|
||||||
set: do ->
|
|
||||||
|
$.set = do ->
|
||||||
set = (key, val) ->
|
set = (key, val) ->
|
||||||
key = g.NAMESPACE + key
|
key = g.NAMESPACE + key
|
||||||
val = JSON.stringify val
|
val = JSON.stringify val
|
||||||
@ -378,3 +414,6 @@ do ->
|
|||||||
set key, val
|
set key, val
|
||||||
return
|
return
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
$$ = (selector, root=d.body) ->
|
||||||
|
[root.querySelectorAll(selector)...]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user