snippets:js:helpers
差别
这里会显示出您选择的修订版和当前版本之间的差别。
snippets:js:helpers [2021/01/20 09:00] – 创建 admin | snippets:js:helpers [2021/07/12 12:23] (当前版本) – admin | ||
---|---|---|---|
行 2: | 行 2: | ||
/** | /** | ||
* 为数组添加删除方法 | * 为数组添加删除方法 | ||
- | * @param 接收一个数组元素 | + | * @param |
* @return boolean | * @return boolean | ||
*/ | */ | ||
- | Array.prototype.remove = function(b) { | + | Array.prototype.remove = function (b) { |
- | | + | |
if (a >= 0) { | if (a >= 0) { | ||
this.splice(a, | this.splice(a, | ||
行 13: | 行 13: | ||
return false; | 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的方法 | * 为window.location 添加查询params的方法 | ||
- | * @param 接收一个字符串 | + | * @param |
* @return null|string | * @return null|string | ||
*/ | */ | ||
- | window.location.query = function(b) { | + | window.location.query = function (b) { |
- | | + | |
- | | + | |
- | if (r != null) return | + | if (r != null) return r[2]; |
return null; | return null; | ||
}; | }; | ||
+ | |||
+ | |||
+ | |||
/** | /** | ||
* 为window.location 添加查询当前平台的方法 | * 为window.location 添加查询当前平台的方法 | ||
* @return null|string | * @return null|string | ||
*/ | */ | ||
- | window.location.platform = function(){ | + | window.location.platform = function () { |
- | | + | |
- | | + | |
- | const platforms = ['Windows NT','Linux','Macintosh','Android','iPhone','iPod','iPad','Windows Phone']; | + | // prettier-ignore |
- | for(i=0; | + | |
- | if(useragent.indexOf(platforms[i]) > -1){ | + | for (let i = 0; i <= platforms.length; |
- | platform = platforms[i]; | + | if (useragent.indexOf(platforms[i]) > -1) { |
- | break; | + | platform = platforms[i]; |
- | } | + | break; |
} | } | ||
- | | + | } |
- | }; | + | |
+ | }; | ||
</ | </ |
snippets/js/helpers.txt · 最后更改: 2021/07/12 12:23 由 admin