cookie & cookies


"use strict"; /**
*
* @author xgqfrms
* @license MIT
* @copyright xgqfrms
*
* @description cookies
* @augments
* @example
*
*/ // const cookiesGenerator = (datas = [], debug = false) => {
// let result = ``;
// // do something...
// return result;
// }; // export default cookies; // export {
// cookies,
// }; ;(function (factory) {
var registeredInModuleLoader;
if (typeof define === 'function' && define.amd) {
define(factory);
registeredInModuleLoader = true;
}
if (typeof exports === 'object') {
module.exports = factory();
registeredInModuleLoader = true;
}
if (!registeredInModuleLoader) {
var OldCookies = window.Cookies;
var api = window.Cookies = factory();
api.noConflict = function () {
window.Cookies = OldCookies;
return api;
};
}
}(function () {
function extend () {
var i = 0;
var result = {};
for (; i < arguments.length; i++) {
var attributes = arguments[ i ];
for (var key in attributes) {
result[key] = attributes[key];
}
}
return result;
}
function decode (s) {
return s.replace(/(%[0-9A-Z]{2})+/g, decodeURIComponent);
}
function init (converter) {
function api() {}
function set (key, value, attributes) {
if (typeof document === 'undefined') {
return;
}
attributes = extend({
path: '/'
}, api.defaults, attributes);
if (typeof attributes.expires === 'number') {
attributes.expires = new Date(new Date() * 1 + attributes.expires * 864e+5);
}
// We're using "expires" because "max-age" is not supported by IE
attributes.expires = attributes.expires ? attributes.expires.toUTCString() : '';
try {
var result = JSON.stringify(value);
if (/^[\{\[]/.test(result)) {
value = result;
}
} catch (e) {
if (console.log) {
console.log("error =", e);
}
}
value = converter.write ?
converter.write(value, key) :
encodeURIComponent(String(value))
.replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent);
key = encodeURIComponent(String(key))
.replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent)
.replace(/[\(\)]/g, escape); var stringifiedAttributes = '';
for (var attributeName in attributes) {
if (!attributes[attributeName]) {
continue;
}
stringifiedAttributes += '; ' + attributeName;
if (attributes[attributeName] === true) {
continue;
}
// Considers RFC 6265 section 5.2:
// ...
// 3. If the remaining unparsed-attributes contains a %x3B (";")
// character:
// Consume the characters of the unparsed-attributes up to,
// not including, the first %x3B (";") character.
// ...
stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];
}
return (document.cookie = key + '=' + value + stringifiedAttributes);
}
function get (key, json) {
if (typeof document === 'undefined') {
return;
}
var jar = {};
// To prevent the for loop in the first place assign an empty array
// in case there are no cookies at all.
var cookies = document.cookie ? document.cookie.split('; ') : [];
var i = 0;
for (; i < cookies.length; i++) {
var parts = cookies[i].split('=');
var cookie = parts.slice(1).join('=');
if (!json && cookie.charAt(0) === '"') {
cookie = cookie.slice(1, -1);
}
try {
var name = decode(parts[0]);
cookie = (converter.read || converter)(cookie, name) ||
decode(cookie);
if (json) {
try {
cookie = JSON.parse(cookie);
} catch (e) {}
}
jar[name] = cookie; if (key === name) {
break;
}
} catch (e) {}
}
return key ? jar[key] : jar;
}
api.set = set;
api.get = function (key) {
return get(key, false /* read as raw */);
};
api.getJSON = function (key) {
return get(key, true /* read as json */);
};
api.remove = function (key, attributes) {
set(key, '', extend(attributes, {
expires: -1
}));
};
api.defaults = {};
api.withConverter = init;
return api;
}
return init(function () {});
}));


function cookies() {
var D = new Date();
D.setDate(D.getDate() + 30);
document.cookie = "author=xgqfrms; website=www.xgqfrms.xyz; domain=xgqfrms.xyz; secure ;expire=" + D;
/*
// read cookie
var rc = document.cookie.substring(5);
if (rc != "www.xgqfrms.xyz") {
alert("cookie is empty!"+rc);
var D = new Date();
D.setDate(D.getDate()+30);
//write cookie
document.cookie="name=www.xgqfrms.xyz;domain=xgqfrms.xyz;HttpOnly;expire="+D;
}else{
alert("cookie is:"+rc);
}
*/
};
cookies();

view-source:https://www.xgqfrms.xyz/

最新文章

  1. Linux的主机规划和磁盘分区
  2. 【MySQL】Create table 以及 foreign key 删表顺序考究。
  3. codeforces 501 C,D,E
  4. [javascript] 使用闭包编写模块
  5. ptmalloc2源码解析初探
  6. load-on-startup
  7. 1uboot移植要点[原创☆☆]
  8. c# List Sort排序
  9. vector 与 set区别
  10. C#实训 打字游戏
  11. 我所不知道的 Chrome 开发者工具
  12. C和指针---读书笔记。
  13. Apache HttpServer Installing the apache2.2 service &lt;OS 5&gt;拒绝访问. :Failed to open the WinNT service manager
  14. Parse error: syntax error, unexpected &#39;[&#39; in D:\phpStudy\WWW\tp5\thinkphp\library\think\Loader.php on line 18
  15. mysql 索引类型
  16. 使用原生 python 造轮子搭建博客
  17. memcahe
  18. 定制库到Maven本地资源库
  19. 使用pyinotify监控文件系统的变化
  20. perl 入门知识(1)

热门文章

  1. 栗染-Myeclispe连接SQL Server数据库
  2. python实现汉诺塔程序
  3. [COCI2006-2007 Contest#3] BICIKLI
  4. Java多线程(六)守护进程
  5. mydatepicker97 日历控件
  6. 51nod1298 圆与三角形
  7. 242 Valid Anagram 有效的字母异位词
  8. 【JAVA 学习笔记2】if使用例子
  9. [ CERC 2014 ] Vocabulary
  10. python实现qq机器人qqbot