Skip to content

Commit

Permalink
feat: 新增房间VIP到期时间提醒
Browse files Browse the repository at this point in the history
  • Loading branch information
qianjiachun committed Dec 19, 2024
1 parent 398564d commit 79f3215
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function initPkg() {
initPkg_AccountList();
initPkg_ChatTools();
initPkg_MonthCost();
initPkg_RoomVip();
initPkg_WeeklyPanel();
initPkg_DanmakuCollect();
}
Expand Down
9 changes: 9 additions & 0 deletions src/packages/RoomVip/RoomVip.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.room-vip {
-moz-user-select:none;/*火狐*/
-webkit-user-select:none;/*webkit浏览器*/
-ms-user-select:none;/*IE10*/
-khtml-user-select:none;/*早期浏览器*/
user-select:none;
vertical-align: middle;
float: left;
}
46 changes: 46 additions & 0 deletions src/packages/RoomVip/RoomVip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const roomVipExpireDayLimit = 3;
function initPkg_RoomVip() {
setRoomVipExpireDays();
}

function initPkg_RoomVip_Dom() {
let a = document.createElement("span");
a.className = "room-vip";
a.innerHTML = `
距VIP到期 <span id="room-vip-expire-days">**</span> 天
`;
let b = document.getElementsByClassName("PlayerToolbar-Wealth")[0];
b.insertBefore(a, b.childNodes[0]);
}

function setRoomVipExpireDays() {
fetch("https://www.douyu.com/member/platform_task/effect_list", {
method: "GET",
mode: "no-cors",
cache: "default",
credentials: "include"
})
.then((res) => {
return res.text();
})
.then(async (doc) => {
doc = new DOMParser().parseFromString(doc, "text/html");
const enterEffectDom = doc.getElementsByClassName("enter-wraper is-effect");
if (!enterEffectDom) return;
if (enterEffectDom.length == 0) return;
const showEffectMoreDom = enterEffectDom[0].getElementsByClassName("show-effect-more");
if (!showEffectMoreDom) return;
if (showEffectMoreDom.length == 0) return;
for (let i = 0; i < showEffectMoreDom.length; i++) {
const detail = JSON.parse(showEffectMoreDom[i].getAttribute("data-detail"));
if (String(detail.show_id_list) !== String(rid)) continue;
const expireTime = detail.expire_time * 1000;
const days = Math.floor((expireTime - Date.now()) / (1000 * 60 * 60 * 24));
initPkg_RoomVip_Dom();
document.getElementById("room-vip-expire-days").innerText = days;
}
})
.catch((err) => {
console.log("请求失败!", err);
});
}

0 comments on commit 79f3215

Please sign in to comment.