-
Notifications
You must be signed in to change notification settings - Fork 1
/
lightshotSave.js
130 lines (115 loc) · 4.38 KB
/
lightshotSave.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// ==UserScript==
// @name lightshot截图存储
// @namespace http://tampermonkey.net/
// @require https://code.jquery.com/jquery-2.0.0.min.js
// @require https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js
// @version 1.2
// @description lightshot base64图片转url,方便Markdown文档内插入图片
// @author isaacXu
// @supportURL https://github.com/meterXu/mtMonkeyJs
// @updateURL https://tampermonkey.isaacxu.com/lightshotSave.js
// @match https://prnt.sc/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
const baseUrl = "https://server.isaacxu.com:3001"
removeAd();
$(function(){
init();
setSaveBtnEvent();
})
function init(){
let timerid = window.setInterval(function(){
if($(".under-image img").length>0){
$(".social").append(`<div class="social__tw my-save-btn" style='padding:0 5px;height:20px;background-color:green;text-align:center;border-radius:4px;margin-top:-5px;cursor:pointer'>
<span id="saveImg" style='font-size:11px;color:#fff'>⭐ 保存</span>
</div>`)
setSaveBtnEvent()
window.clearInterval(timerid)
}
},1000)
}
function removeAd(){
$(".additional").remove()
}
function setSaveBtnEvent(){
let code = window.location.pathname;
if(code){
code = code.replace('/','')
}
searchImgUrl(code)
$("#saveImg").on('click',function(){
let imgbase64 = $(".under-image img").prop('src')
let title = $(".image__title").text()||$(".image__title a").text()
saveImg(code,title,imgbase64)
})
}
function searchImgUrl(code){
$.ajax({
url:baseUrl+"/exca/searchImg",
type:'get',
data:{code:code},
success:function(res){
if(res&&res.success){
createCopyBtn(res.info.url)
}
}
})
}
function saveImg(code,title,data){
let user = document.querySelector("#username").innerText.replace("%username%","-")
$.ajax({
url:baseUrl+"/exca/saveImg",
type:'post',
data:{
code:code,
title:title,
data:data,
user:user
},
beforeSend:function(){
$("#saveImg").text("… 正在保存")
$(".my-save-btn").css({
"backgroundColor":"#676767"
})
},
dataType:'json',
success:function(res){
if(res&&res.success){
$("#saveImg").text("✔ 保存成功")
$(".my-save-btn").css({
"backgroundColor":"green"
})
createCopyBtn(res.info.url)
}else{
$("#saveImg").text("× 保存失败")
$(".my-save-btn").css({
"backgroundColor":"red"
})
$("#my-err-info").remove()
$(".social").after(`<div id='my-err-info' style='color:red'>${res.info.msg}</div>`)
}
},
error:function(err){
$("#my-err-info").remove()
$(".social").after(`<div id='my-err-info' style='color:red'>${err.statusText}</div>`)
}
})
}
function createCopyBtn(url){
$("#my-img-url-copy").unbind('click')
$("#my-img-url-container").remove();
$(".image-info").after(`<div id="my-img-url-container" style="display: flex;justify-content: center;"><input id='my-img-url' type='text' style='width:400px;height:24px;line-hieght:24px;background:#fbfbfb;outline:none;text-indent:10px' value='${url}'/>
<button id='my-img-url-copy' type='button' style="padding: 0 10px;height: 24px;cursor: pointer;outline: none;background: #76ab74;color: #fff" data-clipboard-target="#my-img-url">复制</button>
</div>`)
$("#my-img-url-copy").on('click',copyUrl)
}
function copyUrl(){
new ClipboardJS("#my-img-url-copy")
$("#my-img-url-copy").text("复制成功").css({
"background":"#bd2788"
})
}
})();