博客

  • 谷歌浏览器控制台中将Js中的变量保存为本地json文件

    在js中添加自执行函数,给console添加save方法

    (function (console) {
    console.save = function (data, filename) {
    if (!data) {
    console.error(‘Console.save: No data’);
    return;
    }

        if (!filename) filename = 'console.json';
        if (typeof data === "object") {
            data = JSON.stringify(data, undefined, 4)
        }
    
        var blob = new Blob([data], {type: 'text/json'}),
            e = document.createEvent('MouseEvents'),
            a = document.createElement('a');
        a.download = filename;
        a.href = window.URL.createObjectURL(blob);
        a.dataset.downloadurl = ['text/json', a.download, a.href].join(':');
        e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
        a.dispatchEvent(e)
    }

    })(console);

    将js变量保存为json格式的字符串

    JSON.stringify(Variable)

    将js变量Variable转换为json格式

    console.save中已设置判断如果变量是Object,将其转换为json格式。

    保存变量至json文件

    console.save(JSON.stringify(Variable),filename);

    第一个参数为变量,第二个参数为导出的文件名;

    例如:

    console.save(JSON.stringify(ary),”ary.json”);

  • 限制wordpress前端访问,后台和手机均可访问

    只要在将以下代码加入functions.php文件开头最前面即可。

    add_filter("template_include", function($template){
    if(!minisi_is_mobile()){
    if(is_home() || is_single() || is_page() || is_category() || is_tag() || is_tax() || is_archive()){
    header('HTTP/1.1 404 Not Found');
    header("status: 404 Not Found");
    exit;
    }
    }
    return $template;
    },999);
    
    function minisi_is_mobile()
    {
    if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
    {
    return true;
    }
    if (isset ($_SERVER['HTTP_VIA']))
    {
    return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    }
    if (isset ($_SERVER['HTTP_USER_AGENT']))
    {
    $clientkeywords = array ('nokia',
    'sony',
    'ericsson',
    'mot',
    'samsung',
    'htc',
    'sgh',
    'lg',
    'sharp',
    'sie-',
    'philips',
    'panasonic',
    'alcatel',
    'lenovo',
    'iphone',
    'ipod',
    'blackberry',
    'meizu',
    'android',
    'netfront',
    'symbian',
    'ucweb',
    'windowsce',
    'palm',
    'operamini',
    'operamobi',
    'openwave',
    'nexusone',
    'cldc',
    'midp',
    'wap',
    'mobile'
    );
    if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
    {
    return true;
    }
    }
    if (isset ($_SERVER['HTTP_ACCEPT']))
    {
    if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
    {
    return true;
    }
    }
    return false;
    }
  • 世界,您好!

    欢迎使用 WordPress。这是您的第一篇文章。编辑或删除它,然后开始写作吧!