// ==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 // @downloadURL 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('
自动保存已经开启,每5秒保存一次!
'); $("#rg_autosave_msg").css("position", "fixed").css("top", 50).css("left", 10).css("opacity", 0.4); $('body').append(''); $("#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 != "


") 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 != "


") storage.setItem('bihu_content', encodeURI(content)); },5000); } })();