-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpter_post_cache.user.js
More file actions
65 lines (60 loc) · 2.85 KB
/
Copy pathpter_post_cache.user.js
File metadata and controls
65 lines (60 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// ==UserScript==
// @name Pter Post Cache
// @namespace https://pterclub.com
// @version 0.0.6
// @description 猫站论坛缓存
// @author BbLaCk
// @credits soleil
// @include http*://*pterclub.com/forums.php?action=newtopic&forumid=*
// @include http*://pterclub.com/forums.php?action=reply*
// @include http*://*pterclub.com/forums.php?action=editpost&postid=*
// @include http*://pterclub.com/forums.php?action=quotepost*
// @require https://cdn.staticfile.org/jquery/3.5.1/jquery.min.js
// @charset UTF-8
// ==/UserScript==
(function() {
'use strict';
$(document).ready(function() {
var TOKEN_KEY_TITLE = 'newpost_title';
var TOKEN_KEY_CONTENT = 'newpost_content';
//设置缓存
var setpostca = function () {
window.localStorage.setItem(TOKEN_KEY_TITLE, $("input[name='subject']").val());
window.localStorage.setItem(TOKEN_KEY_CONTENT, $("#body").val());
};
//删除缓存
var delpostca = function () {
let msg = "真的要删除缓存吗?删除缓存后文章内容将消失!";
if (confirm(msg)===true){
window.localStorage.removeItem(TOKEN_KEY_TITLE);
window.localStorage.removeItem(TOKEN_KEY_CONTENT);
$("input[name='subject']").val("");
$("#body").val("");
}
};
//恢复内容
var recpostca = function () {
let title = window.localStorage.getItem(TOKEN_KEY_TITLE);
let post = window.localStorage.getItem(TOKEN_KEY_CONTENT);
if (title){$("input[name='subject']").val(title);}
if (post){$("#body").val(post);}
console.log(window.localStorage.getItem(TOKEN_KEY_CONTENT))
};
//输入内容更新缓存
$("input[name='subject'],#body").bind("input", setpostca );
//鼠标聚焦更新缓存
$("input[name='subject'],#body").focus( setpostca );
//发布文章删除缓存
//$('#submit_button').on("click", delpostca );
$(document).on("click", "#get_localstorage", function() {//一键恢复
recpostca();
}).on("click", "#del_localstorage", function() {//删除缓存
delpostca();
});
//增加按钮
$("#previewbutton").after(' <a class="btn2" id="del_localstorage" href="javascript:void(0);">⊗ 删除缓存</a>');
$("#previewbutton").after(' <a class="btn2" id="get_localstorage" href="javascript:void(0);">↺ 恢复缓存</a>');
//恢复内容
if (window.location.href.includes('forums.php?action=editpost&postid=') === false && window.location.href.includes('forums.php?action=quotepost&postid=') === false){recpostca()}
});
})();