szurubooru/client/js/util/polyfill.js
ReAnzu 2a69f0193f server/auth: add token authentication
* Users are only authenticated against their password on login,
  and to retrieve a token
* Passwords are wiped from the GUI frontend and cookies
  after login and token retrieval
* Tokens are revoked at the end of the session/logout
* If the user chooses the "remember me" option,
  the token is stored in the cookie
* Tokens correctly delete themselves on logout
* Tokens can expire at user-specified date
* Tokens have their last usage time
* Tokens can have user defined descriptions
* Users can manage login tokens in their account settings
2018-03-25 22:23:29 +02:00

68 lines
1.6 KiB
JavaScript

'use strict';
// fix iterating over NodeList in Chrome and Opera
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
NodeList.prototype.querySelector = function(...args) {
for (let node of this) {
if (node.nodeType === 3) {
continue;
}
const result = node.querySelector(...args);
if (result) {
return result;
}
}
return null;
};
NodeList.prototype.querySelectorAll = function(...args) {
let result = [];
for (let node of this) {
if (node.nodeType === 3) {
continue;
}
for (let childNode of node.querySelectorAll(...args)) {
result.push(childNode);
}
}
return result;
};
// non standard
Node.prototype.prependChild = function(child) {
if (this.firstChild) {
this.insertBefore(child, this.firstChild);
} else {
this.appendChild(child);
}
};
// non standard
Promise.prototype.always = function(onResolveOrReject) {
return this.then(
onResolveOrReject,
reason => {
onResolveOrReject(reason);
throw reason;
});
};
// non standard
Number.prototype.between = function(a, b, inclusive) {
const min = Math.min(a, b);
const max = Math.max(a, b);
return inclusive ?
this >= min && this <= max :
this > min && this < max;
};
// non standard
Promise.prototype.abort = () => {};
// non standard
Date.prototype.addDays = function(days) {
let dat = new Date(this.valueOf());
dat.setDate(dat.getDate() + days);
return dat;
};