Greasy Fork

Greasy Fork is available in English.

Bihu Addons

Try to make some useful functions to help bihu users. Changed the store position from cookie to localstorge.

当前为 2018-03-10 提交的版本,查看 最新版本

// ==UserScript==
// @name         Bihu Addons
// @namespace    https://bihu.com/people/112225
// @version      0.2
// @description  Try to make some useful functions to help bihu users. Changed the store position from cookie to localstorge.
// @author       Riley Ge
// @match        https://bihu.com/edit
// @require      https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js
// @require      https://cdn.jsdelivr.net/npm/js-cookie@2/src/js.cookie.min.js
// @grant        none
// ==/UserScript==

(function() {
    // Your code here...
    // add a button to the page and position it in the top left corner
    //var jqCookie = Cookies.noConflict();

    $('body').append('<div id="rg_autosave_msg">自动保存已经开启,每5秒保存一次!</div>');
    $("#rg_autosave_msg").css("position", "fixed").css("top", 50).css("left", 10).css("opacity", 0.4);

    $('body').append('<input article=0 type="button" value="加载草稿" id="rg_autosave_load">');
    $("#rg_autosave_load").css("position", "fixed").css("top", 10).css("left", 10).css("opacity", 0.4);

    if(!window.localStorage){
        //不支持localStorage的时候用Cookie来保存数据
        $('#rg_autosave_load').click(function(){
            $("#title")[0].value = Cookies.get('bihu_title'); // => 'value';
            $("div.w-e-text").html(decodeURI(Cookies.get('bihu_content')));
        });

        var clks = setInterval(function(){
            var title = $("#title")[0].value;
            if(title.length > 0)
                Cookies.set('bihu_title', title,  { expires: 365 });
            var content = $("div.w-e-text").html();
            if(content != "<p><br></p>")
                Cookies.set('bihu_content', encodeURI(content),  { expires: 365 });
        },5000);
    }else{
        var storage=window.localStorage;
        $('#rg_autosave_load').click(function(){
            $("#title")[0].value = storage.getItem("bihu_title");
            $("div.w-e-text").html(decodeURI(storage.getItem('bihu_content')));
        });

        var clks2 = setInterval(function(){
            var title = $("#title")[0].value;
            if(title.length > 0)
                storage.setItem("bihu_title", title);
            var content = $("div.w-e-text").html();
            if(content != "<p><br></p>")
                storage.setItem('bihu_content', encodeURI(content));
        },5000);
    }
})();