// ==UserScript==
// @name WordPress Post Backup
// @namespace https://gitcafe.net
// @version 0.2
// @description 给WordPress网站站长提供文章自动容灾备份的小脚本
// @author 云落
// @include */wp-admin/post*
// @grant none
// @charset UTF-8
// @run-at document-end
// @downloadURL none
// ==/UserScript==
(function() {
'use strict';
$(document).ready(function() {
function getUrlParam(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
var postid = getUrlParam('post');
var TOKEN_KEY;
if (postid) {
TOKEN_KEY = postid;
} else {
TOKEN_KEY = 'newpost';
}
$("#content").bind("input",
function() {
window.localStorage.setItem(TOKEN_KEY, $("#content").val());
});
jQuery(document).on("click", "#get_localstorage",
function() {
var c = window.localStorage.getItem(TOKEN_KEY);
$("#content").val(c);
});
jQuery(document).on("click", "#del_localstorage",
function() {
window.localStorage.removeItem(TOKEN_KEY);
});
$("#wp-content-media-buttons").append(' ↺ 一键恢复 ♻ 一键清空');
});
})();