Skip to content

Commit

Permalink
默认关闭 vDaily、移除获取老主题数据的功能
Browse files Browse the repository at this point in the history
  • Loading branch information
T authored and T committed Jun 4, 2023
1 parent 04c816b commit 4bfa310
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 77 deletions.
10 changes: 8 additions & 2 deletions background.js
Expand Up @@ -24,8 +24,8 @@ chrome.runtime.onInstalled.addListener(async (e) => {
chrome.notifications.create({
type: "basic",
iconUrl: "icon/icon38_msg.png",
title: "更新至 2.1.0",
message: "修复楼中楼缺楼的问题,如需反馈欢迎 @sciooga"
title: "更新至 2.1.1",
message: "新版默认关闭 vDaily,老版本用户可按需手动关闭,移除 vDaily 获取老主题数据的功能,如需反馈欢迎 @sciooga"
})

// 2.0.0 checkin typo
Expand Down Expand Up @@ -66,6 +66,12 @@ chrome.runtime.onInstalled.addListener(async (e) => {
options.markColor = '#ff0000'
chrome.storage.sync.set({ options })
}

// 2.1.1 版本重置 vDaily 为关闭
if (e.previousVersion && e.previousVersion == '2.1.0') {
options.vDaily = 0
chrome.storage.sync.set({ options })
}
}
})

Expand Down
4 changes: 0 additions & 4 deletions inject/topicList/index.css
Expand Up @@ -27,10 +27,6 @@
height: 2em;
}

#my-recent-topics {
display: none;
}

.vdaily {
float: right;
}
29 changes: 0 additions & 29 deletions inject/topicList/index.js
Expand Up @@ -75,35 +75,6 @@ chrome.storage.sync.get("options", async (data) => {

// vDaily 推荐主题和回复
if (data.options.vDaily) {
// 修复最近浏览
let recentTopics = document.querySelector('#my-recent-topics .box')
if (recentTopics) {
let cellMeta
recentTopics.querySelectorAll('.cell.from_').forEach(el => {
cellMeta = el
el.remove()
})
chrome.storage.sync.get('recentTopics', async (data) => {
let topics = data.recentTopics || []
topics.forEach(i => {
let cell = cellMeta.cloneNode(1)
let user = cell.querySelector('a[href^="/member/"]')
let avatar = user.querySelector('img')
let title = cell.querySelector('.item_hot_topic_title a')
user.href = `/member/${i['author']}`
avatar.src = i['avatar']
avatar.alt = i['username']
title.href = `/t/${i['id']}`
title.innerText = i['name']
recentTopics.append(cell)
document.querySelector('#my-recent-topics').style.display = 'block'
})
})
recentTopics.querySelector('a[href="#;"]').addEventListener('click', e => {
chrome.storage.sync.set({ recentTopics: [] })
})
}

let TopicsHot = document.querySelector('#TopicsHot')
if (!TopicsHot) return

Expand Down
3 changes: 2 additions & 1 deletion pages/options/index.html
Expand Up @@ -240,7 +240,8 @@ <h2 class="title">其他</h2>
<li>
<label class="item">
<div class="item-content">启用 vDaily<div class="item-content-tip">
首页右侧栏将展示推荐主题,在浏览主题时会将基本信息提交到 vDaily,同时接受等量的爬取任务</div>
首页右侧栏将展示推荐主题、推荐回复,在浏览主题时提交主题数据到 vDaily 以做推荐及排行<br>
(不涉及用户隐私,不会提交 Cookie)</div>
</div>
<div class="item-secondary">
<span class="toggle">
Expand Down
2 changes: 1 addition & 1 deletion pages/options/index.js
Expand Up @@ -26,7 +26,7 @@ let options = {
weekNewuser: 0, // 淡化新用户回复

// 其他
vDaily: 1, // 启用 vDaily 默认打开
vDaily: 0, // 启用 vDaily 默认关闭
userinfo: 1, // 查看用户信息 默认打开
markColor: '#ff0000', // 标记用户颜色
userMarkList: [], // 标记用户列表
Expand Down
41 changes: 1 addition & 40 deletions spider/index.js
Expand Up @@ -84,7 +84,7 @@ function spider(dom, topicId, topicPage) {
return topic
}

const SPIDER_VERSION = '1.0.1'
const SPIDER_VERSION = '1.0.2'
// 1.0.0 首个记录版本
// 1.0.1 请求失败自动重试

Expand Down Expand Up @@ -134,18 +134,6 @@ chrome.storage.sync.get("options", async (data) => {
let id = +regexGet(/\/t\/(\d+)/, location.pathname)
let page = +regexGet(/p=(\d+)/, location.search, 1)
let topic = spider(document.body, id, page)
chrome.storage.sync.get('recentTopics', async (data) => {
let recentTopics = data.recentTopics || []
if (recentTopics.find(i => i.id == topic.id)) return
recentTopics.unshift({
author: topic.author,
avatar: topic.avatar,
id: topic.id,
name: topic.name
})
recentTopics = recentTopics.slice(0, 5)
chrome.storage.sync.set({ recentTopics })
})
await postTopicInfo(topic)
} catch (error) {
console.error(error)
Expand All @@ -156,31 +144,4 @@ chrome.storage.sync.get("options", async (data) => {
time: new Date()
})
}

// 每 30 秒爬取一个新的主题,最多执行 3 次
let taskSpider = async () => {
let task = await (await get(`${endpoint}/api/topic/task`)).json()
if (!task.url) return
try {
let dom = document.createElement('div')
let rep = await get(task.url)
if (rep.status != 200) throw new Error(`错误码${rep.status}`)
dom.innerHTML = await rep.text()
let topic = spider(dom, task.id, task.page)
await postTopicInfo(topic, task.sign)
} catch (error) {
console.error(error)
await post(`${endpoint}/api/error/info`, {
type: 'task', // 浏览
url: task.url,
error: error.stack,
time: new Date()
})
}
}
await taskSpider()
let times = 3
setInterval(async () => {
if (times--) await taskSpider()
}, 30000)
})

0 comments on commit 4bfa310

Please sign in to comment.