飞星发布助手
// ==UserScript==
// @name 飞星发布助手
// @namespace https://scriptcat.org/zh-CN/users/161051
// @version 1.1.4
// @description 为UPMee添加指定的CSS样式,并在对账号按照粉丝数排序
// @author myz
// @match *://*/*
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// console.log('=================lazbao-MYZ=====================');
// 监听fetch请求,拦截特定接口的响应
const originalFetch = window.fetch;
window.fetch = async function(...args) {
const response = await originalFetch.apply(this, args);
const url = args[0];
//console.log('=================lazbao-MYZ===================== fetch', url);
if (typeof url === 'string' && url.includes('/api/media/list')) {
let data;
try {
data = await response.clone().json();
if (data && data.data && data.data.list) {
// 按照fans降序排序
data.data.list.sort((a, b) => b.fans - a.fans);
// 将排序后的数据重新包装成响应
return new Response(JSON.stringify(data), {
status: response.status,
statusText: response.statusText,
headers: response.headers
});
}
} catch (error) {
console.error('处理响应数据时出错:', error);
}
}
return response;
};
// 拦截XMLHttpRequest
const originalOpen = XMLHttpRequest.prototype.open;
const originalSend = XMLHttpRequest.prototype.send;
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
this.url = url;
return originalOpen.apply(this, arguments);
};
XMLHttpRequest.prototype.send = function(data) {
const xhr = this;
const originalOnLoad = xhr.onload;
xhr.onload = function() {
//console.log('=================lazbao-MYZ===================== xhr', xhr.url);
if (xhr.url.includes('/api/media/list')) {
try {
//console.log('=================lazbao-MYZ===================== xhr.responseText', xhr.responseText);
let response = JSON.parse(xhr.responseText);
//console.log('=================lazbao-MYZ===================== response', response);
if (response && response.list) {
// 按照fans降序排序
response.list.sort((a, b) => b.fans - a.fans);
// 将排序后的数据重新设置为响应文本
// xhr.responseText = JSON.stringify(response);
// 将排序后的数据重新设置为响应文本
Object.defineProperty(xhr, 'response', {
get: function() {
return JSON.stringify(response);
}
});
Object.defineProperty(xhr, 'responseText', {
get: function() {
return JSON.stringify(response);
}
});
}
} catch (error) {
console.error('处理响应数据时出错:', error);
}
}
// 调用原始的onload处理程序
if (originalOnLoad) {
originalOnLoad.apply(xhr, arguments);
}
};
return originalSend.apply(this, arguments);
};
function removeArrow(){
if(window.location.href.includes('www.upmee.cc/item/account?')){
// 延迟1秒后点击feature__list__arrow元素
setTimeout(() => {
const arrowElement = document.querySelector('.feature__list__arrow');
if (arrowElement) {
arrowElement.click();
} else {
console.log('未找到 feature__list__arrow 元素');
}
}, 1000);
}
}
// 监听URL变化(包括hash变化)
window.addEventListener('hashchange', removeArrow);
window.addEventListener('popstate', removeArrow);
// 等待页面加载完成后再执行样式修改
window.addEventListener('load', function() {
if(window.location.href.includes('www.upmee.cc')){
// 创建一个style元素
const style = document.createElement('style');
// 定义要添加的CSS样式
const css = `
.account .card__logo{
display: none !important;
}
.account .feature__list{
display: none !important;
}
.account .card__addbutton{
display: none !important;
}
.account .main__account{
padding: 0 !important;
}
.account .card__accounts{
width: 1440px !important;
padding: 0 0 0 20px !important;
}
.account .main__account__list__card .card__logo{
width: 100px !important;
}
.account .main__account__list__card{
height: 530px !important;
max-height: 530px !important;
}
.account .arco-scrollbar-container{
height: 520px !important;
max-height: 520px !important;
width: 1400px !important;
}
.account .account__contain {
align-items: flex-end !important;
flex-wrap: wrap !important;
width: 1400px !important;
}
.account .card__accounts__profile {
zoom: 1;
width: 250px !important;
min-width: 250px !important;
margin-top: 10px !important;
}
.account .card__accounts__profile .remark__input + div {
color: #ff9900 !important;
font-weight: bold !important;
}
`;
// 将CSS样式添加到style元素中
style.innerHTML = css;
// 将style元素添加到页面的head部分
document.head.appendChild(style);
}
});
})();