zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    Cookies Reader

    
    "use strict";
    
    /**
     *
     * @author xgqfrms
     * @license MIT
     * @copyright xgqfrms
     *
     * @description CookiesReader
     * @augments
     * @example
     *
     */
    
    const CookiesReader = (key = ``, debug = false) => {
        if(key) {
            let name = `${key}=`;
            let decodedCookie = decodeURIComponent(document.cookie);
            let cookies = decodedCookie.split(`;`);
            for(let i = 0; i <cookies.length; i++) {
                let cookie = cookies[i];
                while (cookie.charAt(0) === ` `) {
                    // trim() ???
                    cookie = cookie.substring(1);
                }
                if (cookie.indexOf(name) === 0) {
                    return cookie.substring(name.length, cookie.length);
                }
            }
            return "";
        } else {
            console.error(`Please pass the key of cookie!, key = ${key}`);
        }
    };
    
    const getCookieValue = (key = ``, debug = false) => {
        if(key) {
            let name = `${key}=`;
            let decodedCookie = decodeURIComponent(document.cookie);
            let cookies = decodedCookie.split(`;`);
            for(let i = 0; i <cookies.length; i++) {
                let cookie = cookies[i];
                while (cookie.charAt(0) === ` `) {
                    // trim() ???
                    cookie = cookie.substring(1);
                }
                if (cookie.indexOf(name) === 0) {
                    return cookie.substring(name.length, cookie.length);
                }
            }
            return "";
        } else {
            console.error(`Please pass the key of cookie!, key = ${key}`);
        }
    };
    
    
    
    export default CookiesReader;
    
    export {
        CookiesReader,
        getCookieValue,
    };
    
    
    
    /*
    
    
    import {
        getCookieValue,
        // CookiesReader,
    } from "./cookies-reader";
    
    JSON.parse(decodeURIComponent(atob(getCookieValue(`access_token_test`).split(`.`)[1])));
    JSON.parse(decodeURIComponent(atob(getCookieValue(`access_token_prod`).split(`.`)[1])));
    
    
    JSON.parse(decodeURIComponent(atob(getCookieValue(`${access_token}`).split(`.`)[1])));
    
    
    */
    
    

    demo

    
    import {
        getCookieValue,
        // CookiesReader,
    } from "./cookies-reader";
    
    
    JSON.parse(decodeURIComponent(atob(getCookieValue(`access_token_test`).split(`.`)[1])));
    JSON.parse(decodeURIComponent(atob(getCookieValue(`access_token_prod`).split(`.`)[1])));
    
    
    
    
    
    
    import {
        getCookieValue,
        // CookiesReader,
    } from "./cookies-reader";
    
    import {
        ROLE,
        DEV
    } from "./url-roles";
    
    
    
    let access_token = ``;
    
    if (DEV === "production") {
        access_token = `access_token_prod`;
    } else {
        access_token = `access_token_test`;
    }
    
    
    // let token = JSON.parse(decodeURIComponent(atob(document.cookie.replace(`${access_token}`, ``).split(`.`)[1])));
    let token = JSON.parse(decodeURIComponent(atob(getCookieValue(`${access_token}`).split(`.`)[1])));
    
    

    HttpOnly & bug

    bug

    const CookiesReader = (key = ``, debug = false) => {
        if(key) {
            let name = `${key}=`;
            let decodedCookie = decodeURIComponent(document.cookie);
            let cookies = decodedCookie.split(`;`);
            for(let i = 0; i <cookies.length; i++) {
                let cookie = cookies[i];
                while (cookie.charAt(0) === ` `) {
                    // trim() ???
                    cookie = cookie.substring(1);
                }
                if (cookie.indexOf(name) === 0) {
                    return cookie.substring(name.length, cookie.length);
                }
            }
            return "";
        } else {
            console.error(`Please pass the key of cookie!, key = ${key}`);
        }
    };
    
    CookiesReader(`JSESSIONID`);
    
    


  • 相关阅读:
    判断鼠标在按钮区域上面
    在MFC下绘制直线,使用橡皮筋技术,可以使直线效果跟随鼠标移
    三缓冲
    MFC--自己优化滚动条的双缓冲绘图方法
    MFC视图切换大全总结
    各种线程:事件、互斥量、信号量、临界区 的用法,我自己做的,有用,附件里面有,博客附件里面有
    http://www.cctry.com/forum.php?mod=viewthread&tid=800&reltid=4131&pre_thread_id=0&pre_pos=3&ext=
    关于Mac下pycharm无法调用摄像头权限的问题
    终于理解清楚attention,利用attention对黄金价格进行预测
    tensorboard在colab中的实现
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/9816422.html
Copyright © 2011-2022 走看看