mirror of
https://github.com/Jonnyan404/memos-bber.git
synced 2026-04-25 03:58:37 +09:00
Add files via upload
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
chrome.contextMenus.create({
|
||||
title: "记下 “%s”",
|
||||
contexts: ['selection'],
|
||||
onclick: function(info, tab){
|
||||
//设定打开页面的一些初始值
|
||||
console.log(info);
|
||||
chrome.storage.sync.set({open_action: "save_text",open_content:info.selectionText}, function() {
|
||||
chrome.windows.create({
|
||||
url: chrome.extension.getURL("html/popup.html"),
|
||||
left: 50,
|
||||
top: 50,
|
||||
width: 550,
|
||||
height: 300,
|
||||
type: "popup"
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
Vendored
+2
File diff suppressed because one or more lines are too long
@@ -0,0 +1,65 @@
|
||||
/**
|
||||
* 消息提示组件
|
||||
*
|
||||
* 1.调用
|
||||
* 字符串类型参数: $.message('成功');
|
||||
* 对象型参数:$.message({});
|
||||
*
|
||||
* 2.参数详解
|
||||
* message:' 操作成功', //提示信息
|
||||
time:'2000', //显示时间(默认:2s)
|
||||
type:'success', //显示类型,包括4种:success.error,info,warning
|
||||
showClose:false, //显示关闭按钮(默认:否)
|
||||
autoClose:true, //是否自动关闭(默认:是)
|
||||
*
|
||||
* type:success,error,info,warning
|
||||
*/
|
||||
|
||||
$.extend({
|
||||
message: function(options) {
|
||||
var defaults={
|
||||
message:' 操作成功',
|
||||
time:'2000',
|
||||
autoClose: true,
|
||||
onClose:function(){}
|
||||
};
|
||||
|
||||
if(typeof options === 'string'){
|
||||
defaults.message=options;
|
||||
}
|
||||
if(typeof options === 'object'){
|
||||
defaults=$.extend({},defaults,options);
|
||||
}
|
||||
//message模版
|
||||
var template='<div class="tip animate bounceIn">\n' +
|
||||
' <p class="tip-info">'+defaults.message+'</p>\n' +
|
||||
'</div>';
|
||||
var _this=this;
|
||||
var $body=$('body');
|
||||
var $message=$(template);
|
||||
var timer;
|
||||
|
||||
//移除所有并插入该消息
|
||||
$('.tip').remove();
|
||||
$body.append($message);
|
||||
//居中
|
||||
$message.css({
|
||||
'margin-left':'-'+$message.width()/2+'px'
|
||||
});
|
||||
|
||||
|
||||
//自动关闭
|
||||
if (defaults.autoClose){
|
||||
timer=setTimeout(function(){
|
||||
closeFn();
|
||||
},defaults.time);
|
||||
}
|
||||
//关闭
|
||||
var closeFn = function(){
|
||||
$message.addClass('hide');
|
||||
$message.remove();
|
||||
defaults.onClose(defaults);
|
||||
clearTimeout(timer);
|
||||
};
|
||||
}
|
||||
});
|
||||
+154
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* open_action: 打开这个页面执行的操作
|
||||
* open_text:打开这页面需要复原的输入框的内容
|
||||
*/
|
||||
get_info(function (info) {
|
||||
if (info.status) {
|
||||
//已经有绑定信息了,折叠
|
||||
$('#blog_info').hide()
|
||||
}
|
||||
$('#apiUrl').val(info.apiUrl)
|
||||
$('#content').val(info.open_content)
|
||||
//从localstorage 里面读取数据
|
||||
setTimeout(get_info, 1)
|
||||
})
|
||||
|
||||
//监听输入结束,保存未发送内容到本地
|
||||
$('#content').blur(function () {
|
||||
chrome.storage.sync.set(
|
||||
{ open_action: 'save_text', open_content: $('#content').val() },
|
||||
function () {}
|
||||
)
|
||||
})
|
||||
|
||||
$('#saveKey').click(function () {
|
||||
// 保存数据
|
||||
chrome.storage.sync.set(
|
||||
{
|
||||
apiUrl: $('#apiUrl').val()
|
||||
},
|
||||
function () {
|
||||
$.message({
|
||||
message: '保存信息成功'
|
||||
})
|
||||
$('#blog_info').hide()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
$('#tags').click(function () {
|
||||
//add("要出入的文本");
|
||||
get_info(function (info) {
|
||||
if (info.status) {
|
||||
var tagUrl = info.apiUrl.replace(/api\/memo/,'api/tag')
|
||||
var tagDom = ""
|
||||
$.get(tagUrl,function(data,status){
|
||||
var arrData = data.data
|
||||
$.each(arrData, function(i,obj){
|
||||
tagDom += '<span class="item-container">#'+obj+'</span>'
|
||||
});
|
||||
//console.log(tagDom)
|
||||
$("#taglist").html(tagDom).slideToggle()
|
||||
});
|
||||
} else {
|
||||
$.message({
|
||||
message: '请先填写好 API 链接'
|
||||
})
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
$(document).on("click",".item-container",function () {
|
||||
var tagHtml = $(this).text()+" "
|
||||
add(tagHtml);
|
||||
})
|
||||
|
||||
function add(str) {
|
||||
var tc = document.getElementById("content");
|
||||
var tclen = tc.value.length;
|
||||
tc.focus();
|
||||
if(typeof document.selection != "undefined"){
|
||||
document.selection.createRange().text = str;
|
||||
}else{
|
||||
tc.value =
|
||||
tc.value.substr(0, tc.selectionStart) +
|
||||
str +
|
||||
tc.value.substring(tc.selectionStart, tclen);
|
||||
}
|
||||
}
|
||||
|
||||
$('#blog_info_edit').click(function () {
|
||||
$('#blog_info').slideToggle()
|
||||
})
|
||||
|
||||
function get_info(callback) {
|
||||
chrome.storage.sync.get(
|
||||
{
|
||||
apiUrl: '',
|
||||
open_action: '',
|
||||
open_content: ''
|
||||
},
|
||||
function (items) {
|
||||
var flag = false
|
||||
var returnObject = {}
|
||||
if (items.apiUrl === '' || items.repo === '') {
|
||||
flag = false
|
||||
} else {
|
||||
flag = true
|
||||
}
|
||||
returnObject.status = flag
|
||||
returnObject.apiUrl = items.apiUrl
|
||||
returnObject.open_content = items.open_content
|
||||
returnObject.open_action = items.open_action
|
||||
if (callback) callback(returnObject)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
//发送操作
|
||||
$('#content_submit_text').click(function () {
|
||||
sendText()
|
||||
})
|
||||
function sendText() {
|
||||
get_info(function (info) {
|
||||
if (info.status) {
|
||||
//信息满足了
|
||||
$.message({message: '发送中'})
|
||||
$("#content_submit_text").attr('disabled','disabled');
|
||||
let content = $('#content').val()
|
||||
$.ajax({
|
||||
url:info.apiUrl,
|
||||
type:"POST",
|
||||
data:JSON.stringify({'content': content}),
|
||||
contentType:"application/json;",
|
||||
dataType:"json",
|
||||
success: function(result){
|
||||
//发送成功
|
||||
chrome.storage.sync.set(
|
||||
{ open_action: '', open_content: '' },
|
||||
function () {
|
||||
$.message({
|
||||
message: '发送成功!'
|
||||
})
|
||||
$("#content_submit_text").removeAttr('disabled');
|
||||
$('#content').val('')
|
||||
}
|
||||
)
|
||||
},
|
||||
error:function(err){//清空open_action(打开时候进行的操作),同时清空open_content
|
||||
chrome.storage.sync.set(
|
||||
{ open_action: '', open_content: '' },
|
||||
function () {
|
||||
$.message({
|
||||
message: '网络问题发送成功!'
|
||||
})
|
||||
}
|
||||
)},
|
||||
})
|
||||
} else {
|
||||
$.message({
|
||||
message: '请先填写好 API 链接'
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user