Skip to content

Commit

Permalink
up-laterUrl. 删除单个链接(通过 feedly)
Browse files Browse the repository at this point in the history
  • Loading branch information
wdssmq committed Aug 29, 2024
1 parent b83080f commit f90ccdb
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/later-url/src/__info.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const gm_banner = `
// @noframes
// @run-at document-end
// @match https://space.bilibili.com/*
// @match https://feedly.com/i/saved
// @grant GM_xmlhttpRequest
// @grant GM_getValue
// @grant GM_setValue
Expand Down
84 changes: 84 additions & 0 deletions packages/later-url/src/_feedly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {
_log,
$n,
$na,
curUrl,
fnElChange,
} from "./_base";

import { gob } from "./_gob";

(() => {
if (curUrl.indexOf("feedly") === -1) {
return;
}
// _log($n("body").innerHTML);
const $root = $n("#root");

// 获取链接信息
const getUrlInfo = ($con, $title) => {
const info = {
url: "",
title: "",
category: "",
};
info.url = $title.href;
info.title = $title.textContent;
// 获取分类
const textCon = $con.textContent;
// 判断是否含有 https://space.bilibili.com/\d+/video
const oMatch = textCon.match(/https:\/\/space.bilibili.com\/(\d+)\/video/);
if (oMatch) {
info.category = `bilibili_${oMatch[1]}`;
}
return info;
};

// 添加按钮并绑定事件
const addBtn = ($con, $title) => {
const info = getUrlInfo($con, $title);
if (!info.category) {
return;
}
// $正文元素内添加一个按钮并绑定点击事件
const $btn = document.createElement("button");
$btn.textContent = "从 cf-later 删除";
$btn.style.margin = "10px";
$btn.onclick = async () => {
_log(info);
await gob.delUrl(info.url, info.category);
};
$con.appendChild($btn);
};

const onElChange = () => {
const $$展开的文章 = $na("div > .SelectedEntryScroller");
let $展开的文章;
if ($$展开的文章.length > 0) {
$展开的文章 = $$展开的文章[0];
} else {
return;
}
// 如果已经设置 data-url-btn="true",则不再设置
if ($展开的文章.getAttribute("data-url-btn") === "true") {
return;
}
// 获取正文元素
const $正文 = $展开的文章.querySelector(".entryBody .content");
const $标题 = $展开的文章.querySelector(".entryHeader a");
if (!$正文 || !$标题) {
return;
}
_log("$展开的文章 = ", $展开的文章);
_log(
$正文,
$标题,
);
addBtn($正文, $标题);
// 设置 data-url-btn="true"
$展开的文章.setAttribute("data-url-btn", "true");
};

fnElChange($root, onElChange);

})();
24 changes: 24 additions & 0 deletions packages/later-url/src/_gob.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { _log, curTimestamp } from "./_base";
import { gm_name } from "./__info";
import http from "./_http";
import config from "./_config";

// localStorage 封装
const lsObj = {
Expand Down Expand Up @@ -30,6 +31,7 @@ const gob = {
_lsKey: `${gm_name}_data`,
_bolLoaded: false,
data: {},
config,
// 初始
init() {
// 根据 gobInfo 设置 gob 属性
Expand Down Expand Up @@ -80,6 +82,28 @@ const gob = {

gob.http = http;

// 删除 url
gob.delUrl = async (url, category) => {
const { baseUrl, authToken } = config.data;
const headers = {
"Authorization": "Bearer " + authToken,
};

const apiUrl = `${baseUrl}admin/${category}/del-url/?url=${url}`;
try {
const res = await gob.http.get(apiUrl, headers);
// _log("gob.delUrl()\n", res);
// _log("gob.delUrl()\n", res.responseText);
const resJSON = JSON.parse(res.responseText);
_log("gob.delUrl()\n",resJSON);
return true;
} catch (error) {
gob.errCount += 1;
_log("gob.delUrl() - error\n", error);
return false;
}
};

gob.stopByErrCount = () => {
if (gob.errCount >= 4) {
_log("gob.stopByErrCount()\n", "累计错误达到限制");
Expand Down
3 changes: 3 additions & 0 deletions packages/later-url/src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
// _bilibili
import _bilibili from "./_bilibili";

// _feedly
import _feedely from "./_feedly";

// 具体功能在单独的文件中实现,这里只是导入

0 comments on commit f90ccdb

Please sign in to comment.