// ==UserScript==
// @name 海角天涯-解锁海角社区资源
// @namespace tianya365.top
// @homepage https://vip.tianya365.top
// @version 1.2.0
// @description 无限制解锁收费资源,包括钻石贴、金币贴,下载视频,复制视频链接,自动展开帖子
// @icon data:image/vnd.microsoft.icon;base64,iVBORw0KGgoAAAANSUhEUgAAAEoAAABKCAYAAAAc0MJxAAAKSUlEQVR4Xu2cCZQU1RVA7x8G2VE2WWUbMSiCBDQqiAYVUAkIohIwyCaYnATZHAYwsgnICLLlIMQIRiISECTsgsMSRDGAsguMgkQWCWgiqzow/XPe/OlUdXdNdxXUBKH7nTMHqv5+6/3/33u/uhTRJFWnoGip4D4UtdBUUYoSUctcJolacwrFITSfaUUGAZYxVu3Lq/vKMSFVpyQlMULDLxUkXSZjv6huak22UswOBBjmBCwSVJp+XMHrCopeVMuXaWENZ3Q2nRinFtiHEApqgO6vYKxSOGvaZTp4r93WENABnmWsmhAsawEZoNsoxfx4mWqx4OXA0rTjJfU3yWtApeoUlcRWBcVjVRBP6RpO6SzqM0HtzwGVlKZnAR3jCYKHsc4MpKvOiv66mkpGiMXF7uYBUE5W2Q11FtcrUnXvpCQmeq0gnvIHAjyj1AC9VCkeiqeBex2r1ixSKk3vVlDba+F4yq9hj4A6oaBkPA3c61g1nFRJaVp7LRiP+ROgXD71BKgEKJcEXGZLaFQClEsCLrPlm0Yt6wqbDsGkD+DfZ1325kecLV9AtawNCzuDUnDie5i/A0athgP/+RGTiNE1T6DKFYM/PGwA2GXqBli737rzTid4uE5onknr4cU15l54+bz6KM0cPyOBoUsP2BOo6qVgX1pkp7vPgz9vNvd/Ug529oOkMJjZAbiQ8VZ7EY6eusxAVb0GvhgYHdSoFjCwqX8DqzQS/nXav/outCZPGpUXqKfmweuboVQRODAIil91od2JLFdxJBy70kB1vw1ebecfJKmpwgtmnbrU4ptG/eUTszbVKmsNSdzt9z6DwycjhylpTmtWuIvefwmczrrUmMATqNJFYVzL3E7bBirTLjkJMnqE7mgnv4ca6fDtd/4NtHAy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4ZJoRFSSVHzgnSZJ9BeZtokbmDoGJ57LO3Rq5RwdpkcX/mLihW0JgBJQubNWbDP632ZHrJSyNBkeiGuFrPNI7sk7he4etheC7Xu97FArrcyydAuXyCCVAJUC4JuMyW0KgEKJcEXGZLaFQClEsCLrMlfirrAlTOT2VVmt6rIOztSxel4yiLhkwBtUJB8zgat+ehaliZ+ECEC2yBAH0UA3V1FWB/vH8KKS9eWqN1NjWCH7GZDnRzATces8wIpKvu5t34fvo6lcx2pbgmHknkqU1wQp+jLuPVQetHBGn6QQVLEl/9MdhyvvKjaEW6Wi7XkZ9uU7wU77Byv0bWl5fU/+KekT9LeVa3VQV4Q3FlfEbS61Ki4bSWj46lq8X2ss4f/UvTVZNglBSIF+3K/bzkrAA8T7r6MiIUHJW4fLA0iYeU5v4r+oOlsArN0mgfLP0vox/zX2L4nPIAAAAASUVORK5CYII=
// @author tianya365.top
// @exclude https://*.tianya365.top/*
// @exclude https://*hjedd.top/*
// @exclude https://hj*.icu/*
// @include https://hj*.*/*
// @include https://*.hj*.*/*
// @include https://hai*.top/*
// @match https://haijiao.com/*
// @match https://www.haijiao.com/*
// @match *://*/post/details*
// @connect *
// @run-at document-start
// @grant none
// @antifeature payment
// @charset UTF-8
// ==/UserScript==
(function () {
'use strict';
let version = '1.2.0';
let newVersion = '';
let m3u8_url = '';
let play_url = '';
let hasPic = false;
let video = null;
let topic = null;
let server = window.localStorage.getItem('hjty_server');
let freeToken = window.localStorage.getItem('hjty_free_token');
if (server == null) {
server = 'https://vip.tianya365.top';
window.localStorage.setItem('hjty_server', server);
}
if (freeToken == null) {
freeToken = '5d011923520d412aa3fbe30b3dcfed85'
window.localStorage.setItem('hjty_free_token', freeToken);
}
function importJs(src, onload) {
let script = document.createElement("script");
script.setAttribute("type", "text/javascript");
script.src = src;
script.onload = onload;
document.getElementsByTagName('head')[0].appendChild(script);
}
function loadStyle() {
$('head').append(`
<style>
.hjty-dialog-mask{position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color: rgba(0, 0, 0, 0.5);z-index: 3000;}
.hjty-dialog{position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);background-color: #ffffff;box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);padding: 20px;font-size: 14px;
border: 1px solid #f1f1f1;
border-radius: 5px;
width: 250px;}
.hjty-dialog-title{font-size: 16px;font-weight: bold;margin-bottom: 10px;text-align: center;}
.hjty-dialog-content p{color: #333333;margin-bottom: 10px;}
.hjty-dialog-content ul{list-style: none;padding: 0;margin: 0;}
.hjty-dialog-content ul li{
margin-bottom: 5px;
border: 2px solid #d5d5d5;
padding: 3px 10px;
border-radius: 4px;
background: #f7f7f7;
cursor: pointer;
}
.hjty-dialog-content ul li.active{border-color: #409eff;background: #ecf5ff;}
.hjty-dialog-content ul li span.status{display: inline-block;width: 10px;height: 10px;border-radius: 50%;margin-right: 5px;background-color: #a9a9a9;}
.hjty-dialog-content ul li span.status-success{background-color: #67c23a;}
.hjty-dialog-content ul li span.status-fail{background-color: #f56c6c;}
.hjty-dialog-content ul li span.timeout{color: #999999;font-size: 12px;float: right;margin-top: 1px;}
.hjty-dialog-footer{margin-top: 20px;text-align: center;}
.hjty-dialog-btn{padding: 5px 10px;background-color: #409eff;color: #ffffff;border: none;border-radius: 4px;cursor: pointer;}
#play-box {height: 100%;display: flex;align-items: center;background-color: #000;}
.van-popup.van-popup--center.play-box {width: 100%;height: 100%;max-width: 100%;}
#bbs_float_menu{z-index:1!important;}
#body.el-popup-parent--hidden{overflow: auto;}
.van-list .van-list__loading,
.sell-btn:before,
.el-message-box,
.v-modal,
.containeradvertising,
.ishide,
.el-message-box__wrapper,
#tidio-chat{display: none !important;}
</style
`);
}
function importCss(href) {
let link = document.createElement("link");
link.setAttribute("rel", "stylesheet");
link.href = href;
document.getElementsByTagName('head')[0].appendChild(link);
}
function checkUrl(url) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
const startTime = Date.now();
const timeoutId = setTimeout(() => {
resolve(null);
}, 5000);
xhr.open('HEAD', url, true);
xhr.onload = function() {
clearTimeout(timeoutId);
if (xhr.status >= 200 && xhr.status < 400) {
const responseTime = Date.now() - startTime;
resolve({ url: url, time: responseTime });
} else {
resolve(null);
}
};
xhr.onerror = function() {
clearTimeout(timeoutId);
resolve(null);
};
xhr.send();
});
}
function switchServer() {
$('body').append(`
<div class="hjty-dialog-mask">
<div class="hjty-dialog">
<div class="hjty-dialog-title">海角天涯提示</div>
<div class="hjty-dialog-content">
<p>请选择服务器节点</p>
<ul>
<li data-url="https://vip.tianya365.top"><span class="status"></span> 服务器1 <span class="timeout">测速中</span></li>
<li data-url="https://haijiao.tianya365.top"><span class="status"></span> 服务器2 <span class="timeout">测速中</span></li>
<li data-url="https://new.tianya365.top"><span class="status"></span> 服务器3 <span class="timeout">测速中</span></li>
<li data-url="https://hj.tianya365.top"><span class="status"></span> 服务器4 <span class="timeout">测速中</span></li>
</ul>
</div>
<div class="hjty-dialog-footer">
<button class="hjty-dialog-btn">确定</button>
</div>
</div>
</div>
`);
$('.hjty-dialog-content ul li').each(function() {
const url = $(this).attr('data-url');
if (server === url) {
$(this).addClass('active');
} else {
$(this).removeClass('active');
}
checkUrl(url + '/login').then(result => {
if (result) {
$(this).find('.status').addClass('status-success');
$(this).find('.timeout').html(`${result.time}ms`);
} else {
$(this).find('.status').addClass('status-fail');
$(this).find('.timeout').html('超时');
}
})
});
$('.hjty-dialog-content ul li').click(function() {
$('.hjty-dialog-content ul li').not($(this)).removeClass('active');
$(this).addClass('active');
server = $(this).attr('data-url');
window.localStorage.setItem('hjty_server', server);
});
$('.hjty-dialog-btn').click(function() {
location.reload()
});
}
window.onload = function () {
loadStyle();
checkUrl(server).then(result => {
if (!result) {
switchServer();
} else {
importCss(server + '/static/libs/vant/lib/index.css');
importJs(server + '/static/libs/axios/axios.min.js');
importJs(server + '/js/base64.min.js');
importJs(server + '/static/libs/vue/vue.global.prod.js', function () {
importJs(server + '/static/libs/vant/lib/vant.js', function () {
init()
});
});
}
})
}
const decrypt = function (data) {
return JSON.parse(window.Base64.decode(window.Base64.decode(window.Base64.decode(data))));
}
const encrypt = function (data) {
return window.Base64.encode(window.Base64.encode(window.Base64.encode(JSON.stringify(data))));
}
function formatTitle(data) {
data = decrypt(data);
data.results.forEach(item => {
const tips = [];
tips.push('money_type' in item ? ['', '💰', '💎'][item.money_type] : '普');
item.hasVideo && tips.push('🎥');
item.hasAudio && tips.push('🎵');
item.title = `${tips.join(' ')} ${item.title}`;
});
return encrypt(data);
}
function init() {
$('body').append(`
<div id="hjty-app">
<van-dialog v-model:show="dialogLogin"
:before-close="userLogin"
title="登录海角天涯"
confirm-button-text="登录"
show-cancel-button="true"
close-on-click-overlay="true"
cancel-button-text="注册"
theme="round-button">
<van-form style="padding: 10px 15px">
<van-field
v-model="username"
name="账号"
label="账号"
placeholder="请输入账号"
:rules="[{ required: true, message: '请填写账号' }]"
></van-field>
<van-field
v-model="password"
type="password"
name="密码"
label="密码"
placeholder="请输入密码"
:rules="[{ required: true, message: '请填写密码' }]"
></van-field>
</van-form>
</van-dialog>
<div style="touch-action: none">
<van-floating-bubble
axis="xy"
icon="lock"
magnetic="x"
@click="unlock"
v-model:offset="offset"
></van-floating-bubble>
</div>
<div>
<van-action-sheet
v-model:show="actionShow"
:actions="actions"
@select="onSelect"
cancel-text="关闭"
description="帖子解锁成功,下滑查看更多操作"
></van-action-sheet>
</div>
<div>
<van-popup v-model:show="showPlayer" :closeable="true" class="play-box" @click-close-icon="onPlayerClose">
<div id="play-box">
<iframe :src="play_url" style="display:block;border:0;width: 100%;height: 500px" allow="autoplay; encrypted-media" allowfullscreen></iframe>
</div>
</van-popup>
</div>
</div>`);
axios.defaults.timeout = 10000;
Vue.createApp({
data() {
return {
showPlayer: false,
dialogLogin: false,
dialogResult: false,
actionShow: false,
play_url: '',
username: '',
password: '',
offset: {},
actions: []
};
},
mounted() {
if (!getUserToken()) {
this.dialogLogin = true;
} else {
this.checkUpdate();
}
this.offset = {x: window.innerWidth - 72, y: window.innerHeight / 2};
},
methods: {
unlock() {
if (newVersion !== '') {
this.showUpdate();
return;
}
if (!getUserToken()) {
this.dialogLogin = true;
return;
}
deleteCookie('NOTLOGIN');
const pid = this.getPid();
if (!pid) {
vant.showDialog({
title: '海角天涯',
message: '当前账号:' + window.localStorage.getItem('hjty_user_name') + '\n如需解锁帖子,请进入帖子再操作',
theme: 'round-button',
confirmButtonText: '退出登录',
cancelButtonText: '关闭',
showCancelButton: true,
}).then(action => {
if (action === 'confirm') {
window.localStorage.setItem('hjty_user_token', '');
window.localStorage.setItem('hjty_user_name', '');
vant.showSuccessToast('退出成功');
location.reload();
}
}).catch(error => {});
return;
}
if (m3u8_url !== '') {
this.actionShow = true;
return;
}
vant.showLoadingToast({
message: '解锁中...',
forbidClick: true,
duration: 0,
});
this.getTopic(pid).then((data) => {
this.showTopic(data, pid);
}).catch((err) => {
vant.closeToast();
vant.showFailToast(err);
});
},
showActions() {
this.actions = [
{
name: '播放视频(站内)',
key: 'play',
subname: '如无法在线播放,可尝试其他在线播放器,或下载后再观看'
},
{
name: '复制视频地址',
key: 'copy',
subname: '可复制视频地址到其他地方播放或下载'
},
{
name: '在线播放器1',
key: 'open',
subname: '电脑端和手机端均可正常播放',
url: 'http://tool.liumingye.cn/m3u8/#' + m3u8_url
},
{
name: '在线播放器2',
subname: '手机端可能无法播放',
key: 'open',
url: 'https://www.hlsplayer.net/embed?type=m3u8&src=' + encodeURIComponent(m3u8_url)
},
{
name: '在线播放器3',
key: 'open',
subname: '无法播放免费视频,手机端可能无法播放',
url: 'https://m3u8player.org/'
},
{
name: '视频下载通道1',
key: 'open',
subname: '【推荐】支持自动下载和在线播放',
url: 'https://getm3u8.com/?source=' + m3u8_url + '&title=' + topic['title']
},
{
name: '视频下载通道2',
key: 'open',
subname: '免费视频可能无法下载,推荐在电脑端操作',
url: 'https://blog.luckly-mjw.cn/tool-show/m3u8-downloader/index.html?source=' + m3u8_url + '&title=' + topic['title']
},
{
name: '视频下载通道3',
key: 'open',
subname: '需要手动点击下载,推荐在电脑端操作',
url: 'https://tools.thatwind.com/tool/m3u8downloader#m3u8=' + encodeURIComponent(m3u8_url)
},
{
name: '海角天涯官网',
key: 'open',
subname: '点击访问',
url: server + '/'
},
{
name: '切换节点',
key: 'switch',
subname: '点击切换其他服务器节点'
},
{
name: '退出登录',
subname: '当前账号:'+ window.localStorage.getItem('hjty_user_name'),
key: 'logout',
},
];
this.actionShow = true;
},
onSelect(item) {
switch (item.key) {
case 'play':
this.play_url = play_url;
this.showPlayer = true;
vant.showToast('视频加载中,请稍等...');
break;
case 'open':
window.open(item.url);
break;
case 'switch':
switchServer();
break;
case 'logout':
window.localStorage.setItem('hjty_user_token', '');
window.localStorage.setItem('hjty_user_name', '');
vant.showSuccessToast('退出成功');
location.reload();
break;
case 'copy':
copyText(m3u8_url).then(() => {
vant.showSuccessToast('复制成功');
}).catch(() => {
vant.showFailToast('复制失败');
});
}
},
getAttachments(data, pid) {
return new Promise((resolve, reject) => {
let html = '';
data['attachments'].forEach(item => {
switch (item.category) {
case 'video':
video = item;
break;
case 'audio':
html += '<p style="text-align: center"><audio src="' + item['remoteUrl'] + '" controls="true" id="showaudio"></audio></p>'
break;
case 'images':
hasPic = true;
if (!data['content'].includes(item['remoteUrl'])) {
html += '<p><img data-url="'+item['remoteUrl']+'" src="/images/common/project/loading.gif" alt="" data-id="' + item.id + '" lazy="loaded"></p>'
}
break;
}
});
resolve(html);
});
},
showTopic(data, pid) {
if (data['attachments']) {
this.getAttachments(data, pid).then(html => {
if (html) {
if ($('.sell-btn').length) {
$('.sell-btn').replaceWith('<div id="hjsell-container" class="hjsell-container"><div class="hssell-content">' + html + '</div></div>');
} else {
$('#hjsell-container .hssell-content').html(html);
}
if (!document.getElementById('hjsell-container')) {
vant.showFailToast('请等待页面加载完成!');
return;
}
window.scrollTo({
top: document.getElementById('hjsell-container').getBoundingClientRect().top + window.scrollY - 100,
behavior: 'smooth'
});
if (hasPic) {
this.showImages();
}
}
if (video !== null) {
if (!data['sale'] || data['sale']['money_type'] === 0 || data['sale']['is_buy']) {
this.getVideo(video, pid);
} else {
this.queryTopic(pid);
}
} else {
vant.closeToast();
vant.showSuccessToast('解锁成功');
}
});
} else {
vant.showFailToast('没有可解锁的内容');
}
},
queryTopic(pid) {
axios.get(server + '/api/topic/' + pid + '?v=' + version, {
headers: {
'token': getUserToken()
}
}).then(res => {
vant.closeToast();
if (res.data.code) {
if (res.data.msg === '有新版本') {
newVersion = res.data.data;
this.showUpdate();
return ;
}
if (res.data.data['m3u8_url'] !== '') {
m3u8_url = server + res.data.data['m3u8_url'];
play_url = server + '/play?url=' + window.Base64.encode(m3u8_url);
this.showActions();
} else {
vant.showFailToast('没有可解锁的内容');
}
} else {
vant.showDialog({
title: '解锁失败',
message: res.data.msg,
theme: 'round-button',
confirmButtonText: res.data.data['confirmButtonText'],
cancelButtonText: res.data.data['cancelButtonText'],
showCancelButton: !!res.data.data['cancelButtonText'],
}).then(action => {
if (action === 'confirm') {
if (res.data.data['confirmButtonText'] === '重新登录') {
window.localStorage.setItem('hjty_user_token', '');
this.dialogLogin = true;
} else if (res.data.data['confirmButtonText'] === '打开官网') {
window.open(server + '/');
}
}
}).catch(error => {});
return false;
}
}).catch(() => {
vant.closeToast();
vant.showConfirmDialog({
title: '解锁失败',
message: '服务器连接出错,是否切换到其他节点?',
theme: 'round-button',
beforeClose: (action) => {
if (action === 'confirm') {
switchServer();
}
return true;
}
});
});
},
showImages() {
document.querySelectorAll('#hjsell-container img').forEach(img => {
axios.get(img.dataset.url).then(res => {
img.src = imageDecode(res.data);
});
});
},
getVideo(item, pid) {
const uid = /uid=([^;]+)/.exec(document.cookie);
const token = /token=([^;]+)/.exec(document.cookie);
axios.post('/api/attachment', JSON.stringify({
id: item.id,
resource_id: pid,
resource_type: 'topic',
line: ''
}), {
headers: {
'X-User-Id': uid && token ? uid[1] : '172561377002',
'X-User-Token': uid && token ? token[1] : freeToken
}
}).then(res => {
vant.closeToast();
let data = {};
if (res.data.isEncrypted) {
data = JSON.parse(window.Base64.decode(window.Base64.decode(window.Base64.decode(res.data.data))));
} else {
data = res.data.data;
}
if (!data['remoteUrl'].startsWith('http')) {
m3u8_url = play_url = window.location.origin + data.remoteUrl;
} else {
m3u8_url = play_url = data.remoteUrl;
}
play_url = server + '/play?url=' + window.Base64.encode(play_url);
this.showActions();
}).catch(() => {
axios.get(server + '/acc').then(res => {
if (res.data.code) {
freeToken = res.data.data;
window.localStorage.setItem('hjty_free_token', freeToken);
vant.showFailToast('网络错误: 请重试')
} else {
vant.showFailToast('网络错误: 2')
}
}).catch(() => {
vant.showFailToast('网络错误: 2')
});
});
},
getTopic(pid) {
return new Promise((resolve, reject) => {
axios.get('/api/topic/' + pid).then(res => {
if (res.data.isEncrypted) {
topic = JSON.parse(window.Base64.decode(window.Base64.decode(window.Base64.decode(res.data.data))));
} else {
topic = res.data.data;
}
resolve(topic);
}).catch(() => {
reject('网络错误: 3')
});
})
},
onPlayerClose() {
this.play_url = '';
},
userLogin(action) {
if (action === 'confirm') {
if (!this.username || !this.password) {
vant.showFailToast('请填写账号和密码');
return false;
}
return new Promise((resolve) => {
axios.post(server + '/api/login', {
username: this.username,
password: this.password
}).then(res => {
if (res.data.code) {
vant.showDialog({
title: '登录失败',
message: res.data.msg,
theme: 'round-button',
});
resolve(false);
} else {
window.localStorage.setItem('hjty_user_token', res.data.token);
window.localStorage.setItem('hjty_user_name', this.username);
this.dialogLogin = false;
vant.showDialog({
title: '登录成功',
message: res.data.msg,
theme: 'round-button',
}).then(() => {
resolve(true);
})
}
});
});
} else if(action === 'cancel') {
window.open(server + '/reg');
} else {
this.username = '';
this.password = '';
return true;
}
},
getPid() {
if (/\/post\/details.*pid=\d+/.test(location.href)) {
let match = location.href.match(/\/post\/details.*pid=(\d+)/i);
return parseInt(match[1]);
}
return false;
},
showUpdate() {
vant.showDialog({
title: '新版本(' + newVersion + ')',
message: '检测到新版本,请更新后再使用!',
theme: 'round-button',
confirmButtonText: '立即更新',
}).then(() => {
location.href = server + '/js/script.user.js?v=' + Math.random();
});
},
checkUpdate() {
axios.get(server + '/api/update?v=' + version, {
headers: {
'token': getUserToken()
}
}).then(res => {
if (res.data.msg === '有新版本') {
newVersion = res.data.data;
this.showUpdate();
}
}).catch(() => {
vant.closeToast();
vant.showConfirmDialog({
title: '版本检查失败',
message: '服务器连接出错,是否切换到其他节点?',
theme: 'round-button',
beforeClose: (action) => {
if (action === 'confirm') {
switchServer();
}
return true;
}
});
});
}
},
}).use(vant).mount('#hjty-app');
}
function getUserToken() {
return window.localStorage.getItem('hjty_user_token');
}
function deleteCookie(name) {
// 设置 cookie 过期时间为过去的时间
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/';
}
function imageDecode(t) {
const e = "ABCD*EFGHIJKLMNOPQRSTUVWX#YZabcdefghijklmnopqrstuvwxyz1234567890";
let o, i, a, r, s, c, u, l = "", d = 0;
function n(e) {
let t, n = "", o = 0, i = 0, a = 0;
while (o < e.length)
i = e.charCodeAt(o),
i < 128 ? (n += String.fromCharCode(i),
o++) : i > 191 && i < 224 ? (a = e.charCodeAt(o + 1),
n += String.fromCharCode((31 & i) << 6 | 63 & a),
o += 2) : (a = e.charCodeAt(o + 1),
t = e.charCodeAt(o + 2),
n += String.fromCharCode((15 & i) << 12 | (63 & a) << 6 | 63 & t),
o += 3);
return n
}
t = t.replace(/[^A-Za-z0-9*#]/g, "");
while (d < t.length)
r = e.indexOf(t.charAt(d++)),
s = e.indexOf(t.charAt(d++)),
c = e.indexOf(t.charAt(d++)),
u = e.indexOf(t.charAt(d++)),
o = r << 2 | s >> 4,
i = (15 & s) << 4 | c >> 2,
a = (3 & c) << 6 | u,
l += String.fromCharCode(o),
64 !== c && (l += String.fromCharCode(i)),
64 !== u && (l += String.fromCharCode(a));
let reg = new RegExp('', "g");
l = l.replace(reg, '');
return l = n(l),
l
}
function copyText(text) {
return new Promise((resolve, reject) => {
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(text)
.then(() => {
resolve();
})
.catch(err => {
reject(err);
});
} else {
const textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'fixed';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
try {
const success = document.execCommand('copy');
if (success) {
resolve();
} else {
reject();
}
} catch (err) {
reject(err);
}
document.body.removeChild(textarea);
}
});
}
(function () {
const originOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (method, url) {
if (/\/api\/topic\/(hot\/topics\?|node\/(topics|news)|idol_list)/.test(url)) {
const xhr = this;
const getter = Object.getOwnPropertyDescriptor(
XMLHttpRequest.prototype,
"response"
).get;
Object.defineProperty(xhr, "responseText", {
get: () => {
let result = getter.call(xhr);
try {
let res = JSON.parse(result);
res.data = formatTitle(res.data);
return JSON.stringify(res);
} catch (e) {
return result;
}
},
});
} else if (/\/api\/topic\/\d+/.test(url) && /tianya365/.test(url) === false) {
m3u8_url = '';
}
originOpen.apply(this, arguments);
};
})();
})();