diff --git a/README.md b/README.md index 5da2ec4..1a3b92d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,13 @@ 移植自 `bigfa `大大的 `hugo-theme-farallon` 原汁原味,可以直接使用 原主题的CSS 精简部分 JS. - + +- 2024.6.12 + +更新豆瓣API获取方式 +[Docker 自动同步豆瓣书影音记录](https://fatesinger.com/103483) +主题设置处填入API + - 2024.6.7 用自带评论做的说说页面,来自 @@ -50,15 +56,17 @@ https://github.com/bigfa/hugo-theme-farallon ### 豆瓣观影 - -使用原版的获取方式 - ->豆瓣收藏使用方法 -微信扫码登录https://node.wpista.com/ -输入你的豆瓣数字 id,点击保存即可自动同步豆瓣记录。 -点击 Get integration token 会生成一个 token。 -获取`token`之后填入主题设置项中 + 更新 获取方式 + +~~使用原版的获取方式~~ + +~~豆瓣收藏使用方法~~ +~~微信扫码登录https://node.wpista.com/~~ +~~输入你的豆瓣数字 id,点击保存即可自动同步豆瓣记录。~~ +~~点击 Get integration token 会生成一个 token。~~ + +~~获取`token`之后填入主题设置项中~~ ### 友情链接 diff --git a/dist/js/db.js b/dist/js/db.js new file mode 100644 index 0000000..a76dabb --- /dev/null +++ b/dist/js/db.js @@ -0,0 +1,350 @@ +class Douban { + constructor(config) { + this.container = config.container; + this.types = config.types ?? [ + "movie", + "book", + "music", + "game", + "drama", + ]; + this.baseAPI = config.baseAPI; + this.ver = "1.0.6"; + this.type = "movie"; + this.status = "done"; + this.finished = false; + this.paged = 1; + this.genre_list = [ + { + name: "已看", + value: "done", + }, + { + name: "在看", + value: "doing", + }, + { + name: "想看", + value: "mark", + }, + ]; + this.subjects = []; + this._create(); + } + + on(event, element, callback) { + const nodeList = document.querySelectorAll(element); + nodeList.forEach((item) => { + item.addEventListener(event, callback); + }); + } + + _handleGenreClick() { + this.on("click", ".db--genreItem", (t) => { + const self = t.currentTarget; + if (self.classList.contains("is-active")) { + return; + } + document.querySelector(".db--list").innerHTML = ""; + document.querySelector(".lds-ripple").classList.remove("u-hide"); + + this.status = self.dataset.status || ""; // Provide a default value of an empty string if self.dataset.status is undefined + this._renderGenre(); + this.paged = 1; + this.finished = false; + this.subjects = []; + this._fetchData(); + }); + } + + _reanderTypes() { + document.querySelector(".db--nav").innerHTML = this.types + .map((item) => { + return `${item}`; + }) + .join(""); + this._handleNavClick(); + } + + _renderGenre() { + document.querySelector(".db--genres").innerHTML = this.genre_list + .map((item) => { + return `${item.name}`; + }) + .join(""); + this._handleGenreClick(); + } + + _fetchData() { + const params = new URLSearchParams({ + paged: this.paged.toString(), + type: this.type, + status: this.status, + }); + fetch(this.baseAPI + "list?" + params.toString()) + .then((response) => response.json()) + .then((t) => { + console.log(t.results); + if (t.results.length) { + if ( + document + .querySelector(".db--list") + .classList.contains("db--list__card") + ) { + this.subjects = [...this.subjects, ...t.results]; + this._randerDateTemplate(); + } else { + this.subjects = [...this.subjects, ...t.results]; + this._randerListTemplate(); + } + document + .querySelector(".lds-ripple") + .classList.add("u-hide"); + } else { + this.finished = true; + document + .querySelector(".lds-ripple") + .classList.add("u-hide"); + } + }); + } + + _randerDateTemplate() { + const result = this.subjects.reduce((result, item) => { + const date = new Date(item.create_time); + const year = date.getFullYear(); + const month = date.getMonth() + 1; + const key = `${year}-${month.toString().padStart(2, "0")}`; + if (Object.prototype.hasOwnProperty.call(result, key)) { + result[key].push(item); + } else { + result[key] = [item]; + } + return result; + }, {}); + + let html = ``; + for (let key in result) { + const date = key.split("-"); + html += `
${date[1]}
${date[0]}
`; + html += result[key] + .map((movie) => { + return `
${ + movie.douban_score > 0 + ? '' + + movie.douban_score + : "" + }${ + movie.year > 0 ? " · " + movie.year : "" + }
`; + }) + .join(""); + html += `
`; + } + document.querySelector(".db--list").innerHTML = html; + } + + _randerListTemplate() { + document.querySelector(".db--list").innerHTML = this.subjects + .map((item) => { + return `
${ + item.create_time + }
${ + item.douban_score + ? '' + + item.douban_score + : "" + }${ + item.year ? " · " + item.year : "" + }
${item.name}
+
+ `; + }) + .join(""); + } + + _handleScroll() { + window.addEventListener("scroll", () => { + var t = window.scrollY || window.pageYOffset; + const moreElement = document.querySelector( + ".block-more" + ); + if ( + moreElement.offsetTop + -window.innerHeight < t && + document + .querySelector(".lds-ripple") + .classList.contains("u-hide") && + !this.finished + ) { + document + .querySelector(".lds-ripple") + .classList.remove("u-hide"); + this.paged++; + this._fetchData(); + } + }); + } + + _handleNavClick() { + this.on("click", ".db--navItem", (t) => { + const self = t.currentTarget; + if (self.classList.contains("current")) return; + this.status = "done"; + this.type = self.dataset.type; + this._renderGenre(); + document.querySelector(".db--list").innerHTML = ""; + document.querySelector(".lds-ripple").classList.remove("u-hide"); + document + .querySelector(".db--navItem.current") + .classList .remove("current"); + self.classList.add("current"); + this.paged = 1; + this.finished = false; + this.subjects = []; + this._fetchData(); + }); + } + + _create() { + if (document.querySelector(".db--container")) { + const container = document.querySelector( + this.container + ); + if (!container) return; + container.innerHTML = ` +
+
+
+
+
+
+
+
`; + this._renderGenre(); + this._reanderTypes(); + this._fetchData(); + this._handleScroll(); + } + + if (document.querySelector(".js-db")) { + document.querySelectorAll(".js-db").forEach((item) => { + const db = item; + const id = db.dataset.id; + const type = db.dataset.type; + const nodeParent = db.parentNode; + fetch(this.baseAPI + `${type}/${id}`).then((response) => { + response.json().then((t) => { + if (t.data) { + const data = t.data; + const node = document.createElement("div"); + node.classList.add("doulist-item"); + node.innerHTML = `
+
+
+ +
${data.douban_score}
+
${data.card_subtitle}
+
+
`; + nodeParent.replaceWith(node); + } + }); + }); + }); + } + + if (document.querySelector(".db--collection")) { + document + .querySelectorAll(".db--collection") + .forEach((item) => { + this._fetchCollection(item); + }); + } + } + + _fetchCollection(item) { + const type = item.dataset.style ? item.dataset.style : "card"; + fetch( + this.baseAPI + + "/list?type=" + + item.dataset.type + + "&paged=1&start_time=" + + item.dataset.start + + "&end_time=" + + item.dataset.end + ) + .then((response) => response.json()) + .then((t) => { + if (t.length) { + if (type == "card") { + item.innerHTML += t + .map((movie) => { + return `
+
+
Marked ${movie.create_time}
+
${movie.douban_score}
${movie.card_subtitle}
`; + }) + .join(""); + } else { + const result = t.reduce( + (result, item) => { + if ( + Object.prototype.hasOwnProperty.call( + result, + item.create_time + ) + ) { + result[item.create_time].push(item); + } else { + result[item.create_time] = [item]; + } + return result; + }, + {} + ); + let html = ``; + for (let key in result) { + html += `
${key}
`; + html += result[key] + .map((movie) => { + return `
+ +
+ +
${ + movie.douban_score + }
+ ${movie.remark || movie.card_subtitle} +
+
`; + }) + .join(""); + html += `
`; + } + item.innerHTML = html; + } + } + }); + } +} \ No newline at end of file diff --git a/functions.php b/functions.php index 902420f..a438793 100644 --- a/functions.php +++ b/functions.php @@ -27,7 +27,7 @@ function themeConfig($form) { $form->addInput($cnavatar); $donate = new Typecho_Widget_Helper_Form_Element_Text('donate', NULL, 'https://blogcdn.loliko.cn/donate/wx.png', _t('赞赏二维码'), _t('不填写则不显示')); $form->addInput($donate); - $doubanID = new Typecho_Widget_Helper_Form_Element_Text('doubanID', NULL, '322dba2a3a27524b97c06d941d9631d153fc', _t('豆瓣页面必需Token'), _t('从https://node.wpista.com/获得token')); + $doubanID = new Typecho_Widget_Helper_Form_Element_Text('doubanID', NULL, 'https://db.imsun.org/', _t('豆瓣页面必需API,包含"/"'), _t(' ')); $form->addInput($doubanID); $twikoo = new Typecho_Widget_Helper_Form_Element_Textarea('twikoo', NULL, NULL, _t('引用第三方评论'), _t('不填写则不显示')); $form->addInput($twikoo); diff --git a/page-douban.php b/page-douban.php index 02196d0..fa7dd73 100644 --- a/page-douban.php +++ b/page-douban.php @@ -6,333 +6,20 @@ */ if (!defined('__TYPECHO_ROOT_DIR__')) exit; ?> need('header.php'); ?> +

title() ?>

数据来源于豆瓣

-
- -
-
-
-
-
-
-
-
-
+
+
-
need('footer.php'); ?> \ No newline at end of file