Merge pull request #44 from inertia42/main

修复获取标签功能
This commit is contained in:
林木木
2024-06-15 16:22:45 +08:00
committed by GitHub
3 changed files with 71 additions and 31 deletions
+3
View File
@@ -85,5 +85,8 @@
}, },
"memoFailed":{ "memoFailed":{
"message": "Failed! 😭" "message": "Failed! 😭"
},
"invalidToken":{
"message": "Invalid token or url 😭"
} }
} }
+3
View File
@@ -88,5 +88,8 @@
}, },
"memoFailed":{ "memoFailed":{
"message": "发送失败 😭" "message": "发送失败 😭"
},
"invalidToken":{
"message": "无效的 token 或 url 😭"
} }
} }
+44 -10
View File
@@ -11,6 +11,7 @@ function get_info(callback) {
memo_lock: '', memo_lock: '',
open_action: '', open_action: '',
open_content: '', open_content: '',
userid: '',
resourceIdList: [] resourceIdList: []
}, },
function (items) { function (items) {
@@ -32,6 +33,7 @@ function get_info(callback) {
returnObject.memo_lock = items.memo_lock returnObject.memo_lock = items.memo_lock
returnObject.open_content = items.open_content returnObject.open_content = items.open_content
returnObject.open_action = items.open_action returnObject.open_action = items.open_action
returnObject.userid = items.userid
returnObject.resourceIdList = items.resourceIdList returnObject.resourceIdList = items.resourceIdList
if (callback) callback(returnObject) if (callback) callback(returnObject)
@@ -209,19 +211,48 @@ function uploadImage(data) {
} }
$('#saveKey').click(function () { $('#saveKey').click(function () {
var apiUrl = $('#apiUrl').val()
var apiTokens = $('#apiTokens').val()
// 设置请求参数
const settings = {
async: true,
crossDomain: true,
url: apiUrl + 'api/v1/auth/status',
method: 'POST',
headers: {
'Authorization': 'Bearer ' + apiTokens
}
};
$.ajax(settings).done(function (response) {
if (response && response.id) {
// 如果响应包含用户 ID,存储 apiUrl 和 apiTokens
chrome.storage.sync.set( chrome.storage.sync.set(
{ {
apiUrl: $('#apiUrl').val(), apiUrl: apiUrl,
apiTokens: $('#apiTokens').val() apiTokens: apiTokens,
userid: response.id
}, },
function () { function () {
$.message({ $.message({
message: chrome.i18n.getMessage("saveSuccess") message: chrome.i18n.getMessage("saveSuccess")
}) });
$('#blog_info').hide() $('#blog_info').hide();
} }
) );
}) } else {
// 如果响应不包含用户 ID,显示错误消息
$.message({
message: chrome.i18n.getMessage("invalidToken")
});
}
}).fail(function () {
// 请求失败时显示错误消息
$.message({
message: chrome.i18n.getMessage("invalidToken")
});
});
});
$('#opensite').click(function () { $('#opensite').click(function () {
get_info(function (info) { get_info(function (info) {
@@ -232,8 +263,11 @@ $('#opensite').click(function () {
$('#tags').click(function () { $('#tags').click(function () {
get_info(function (info) { get_info(function (info) {
if (info.apiUrl) { if (info.apiUrl) {
var tagUrl = info.apiUrl+'api/v1/tag' var parent = "memos/-";
var tagDom = "" // 如果不使用 user 过滤,会返回所有用户的标签
var filter = "?filter=" + encodeURIComponent(`creator == 'users/${info.userid}'`);
var tagUrl = info.apiUrl + 'api/v1/' + parent + '/tags' + filter;
var tagDom = "";
$.ajax({ $.ajax({
url: tagUrl, url: tagUrl,
type: "GET", type: "GET",
@@ -241,8 +275,8 @@ $('#tags').click(function () {
dataType: "json", dataType: "json",
headers: { 'Authorization': 'Bearer ' + info.apiTokens }, headers: { 'Authorization': 'Bearer ' + info.apiTokens },
success: function (data) { success: function (data) {
$.each(data, function(i,obj){ $.each(data.tagAmounts, function (tag, amount) {
tagDom += '<span class="item-container">#'+obj+'</span>' tagDom += '<span class="item-container">#' + tag + '</span>';
}); });
tagDom += '<svg id="hideTag" class="hidetag" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M78.807 362.435c201.539 314.275 666.962 314.188 868.398-.241 16.056-24.99 13.143-54.241-4.04-62.54-17.244-8.377-40.504 3.854-54.077 24.887-174.484 272.338-577.633 272.41-752.19.195-13.573-21.043-36.874-33.213-54.113-24.837-17.177 8.294-20.06 37.545-3.978 62.536z" fill="#fff"/><path d="M894.72 612.67L787.978 494.386l38.554-34.785 106.742 118.251-38.554 34.816zM635.505 727.51l-49.04-147.123 49.255-16.41 49.054 147.098-49.27 16.435zm-236.18-12.001l-49.568-15.488 43.29-138.48 49.557 15.513-43.28 138.455zM154.49 601.006l-38.743-34.565 95.186-106.732 38.763 34.566-95.206 106.731z" fill="#fff"/></svg>' tagDom += '<svg id="hideTag" class="hidetag" viewBox="0 0 1024 1024" xmlns="http://www.w3.org/2000/svg" width="24" height="24"><path d="M78.807 362.435c201.539 314.275 666.962 314.188 868.398-.241 16.056-24.99 13.143-54.241-4.04-62.54-17.244-8.377-40.504 3.854-54.077 24.887-174.484 272.338-577.633 272.41-752.19.195-13.573-21.043-36.874-33.213-54.113-24.837-17.177 8.294-20.06 37.545-3.978 62.536z" fill="#fff"/><path d="M894.72 612.67L787.978 494.386l38.554-34.785 106.742 118.251-38.554 34.816zM635.505 727.51l-49.04-147.123 49.255-16.41 49.054 147.098-49.27 16.435zm-236.18-12.001l-49.568-15.488 43.29-138.48 49.557 15.513-43.28 138.455zM154.49 601.006l-38.743-34.565 95.186-106.732 38.763 34.566-95.206 106.731z" fill="#fff"/></svg>'
$("#taglist").html(tagDom).slideToggle(500) $("#taglist").html(tagDom).slideToggle(500)