/** * 为数组添加删除方法 * @param {string} b 接收一个数组元素 * @return boolean */ Array.prototype.remove = function (b) { const a = this.indexOf(b); if (a >= 0) { this.splice(a, 1); return true; } return false; }; /** * 随机打乱数组 * * @return {Array} */ Array.prototype.shuffle = function () { var input = this; for (var i = input.length - 1; i >= 0; i--) { var randomIndex = Math.floor(Math.random() * (i + 1)); var itemAtIndex = input[randomIndex]; input[randomIndex] = input[i]; input[i] = itemAtIndex; } return input; }; /** * 为window.location 添加查询params的方法 * @param {string} b 接收一个字符串 * @return null|string */ window.location.query = function (b) { const reg = new RegExp("(^|&|/?)" + b + "=([^&]*)(&|$)", "i"); const r = window.location.href.substr(1).match(reg); if (r != null) return r[2]; return null; }; /** * 为window.location 添加查询当前平台的方法 * @return null|string */ window.location.platform = function () { let platform = null; const useragent = navigator.userAgent; // prettier-ignore const platforms = ["Windows NT", "Linux", "Macintosh", "Android", "iPhone", "iPod", "iPad", "Windows Phone"]; for (let i = 0; i <= platforms.length; i++) { if (useragent.indexOf(platforms[i]) > -1) { platform = platforms[i]; break; } } return platform; };