From e4241c5dcc7e4e26d510e64810fb68e9dce02774 Mon Sep 17 00:00:00 2001 From: sve1r Date: Sat, 29 Oct 2022 12:02:02 +0800 Subject: [PATCH] =?UTF-8?q?=20=20=E6=9B=B4=E6=96=B0=20=E5=BE=AE=E5=8D=9A?= =?UTF-8?q?=E5=8E=BB=E5=B9=BF=E5=91=8A=E8=84=9A=E6=9C=AC=20(powered=20by?= =?UTF-8?q?=20@zmqcherish)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Rewrite/AdBlock/Weibo.conf | 4 +- Scripts/AdBlock/Weibo/weibo_launch.js | 19 +- Scripts/AdBlock/Weibo/weibo_main.js | 609 +++++++------------------- 3 files changed, 173 insertions(+), 459 deletions(-) diff --git a/Rewrite/AdBlock/Weibo.conf b/Rewrite/AdBlock/Weibo.conf index b2dbaa6..a8da0ca 100644 --- a/Rewrite/AdBlock/Weibo.conf +++ b/Rewrite/AdBlock/Weibo.conf @@ -29,11 +29,13 @@ # 【08.23更新】 删除微博详情页超话新帖和新用户相关提示 # 【09.02更新】 删除初次打开搜索页的轮播图 # 【09.12更新】 修复超话无法签到bug +# 【10.11更新】 移除首页新版广告 +# 【10.24更新】 移除用户页新版广告 hostname = api.weibo.cn, mapi.weibo.com, *.uve.weibo.com, new.vip.weibo.cn, # 微博去广告以及去除各部分推广模块 - cherish -^https?://m?api\.weibo\.c(n|om)/2/(cardlist|searchall|page|messageflow|statuses/(unread_)?friends(/|_)timeline|groups/timeline|statuses/(container_timeline|unread_hot_timeline|extend|video_mixtimeline|unread_topic_timeline)|profile/(me|statuses)|video/(community_tab|remind_info|tiny_stream_video_list)|checkin/show|\!/live/media_homelist|comments/build_comments|container/get_item|search/(finder|container_timeline|container_discover)) url script-response-body https://cdn.jsdelivr.net/gh/zmqcherish/proxy-script@main/weibo_main.js +^https?://m?api\.weibo\.c(n|om)/2/(cardlist|searchall|page|messageflow|statuses/(unread_)?friends(/|_)timeline|groups/timeline|statuses/(container_timeline|unread_hot_timeline|extend|video_mixtimeline|unread_topic_timeline)|profile/(me|container_timeline)|video/(community_tab|remind_info|tiny_stream_video_list)|checkin/show|\!/live/media_homelist|comments/build_comments|container/get_item|search/(finder|container_timeline|container_discover)) url script-response-body https://cdn.jsdelivr.net/gh/zmqcherish/proxy-script@main/weibo_main.js # 删除微博开屏广告 - cherish ^https?://(sdk|wb)app\.uve\.weibo\.com(/interface/sdk/sdkad.php|/wbapplua/wbpullad.lua) url script-response-body https://cdn.jsdelivr.net/gh/zmqcherish/proxy-script@main/weibo_launch.js diff --git a/Scripts/AdBlock/Weibo/weibo_launch.js b/Scripts/AdBlock/Weibo/weibo_launch.js index f293ba3..902d5ae 100644 --- a/Scripts/AdBlock/Weibo/weibo_launch.js +++ b/Scripts/AdBlock/Weibo/weibo_launch.js @@ -3,17 +3,24 @@ const launchAdUrl1 = '/interface/sdk/sdkad.php'; const launchAdUrl2 = '/wbapplua/wbpullad.lua'; +// function needModify(url) { +// if(url.indexOf(launchAdUrl1) > -1 || url.indexOf(launchAdUrl2) > -1) { +// return true; +// } +// return false; +// } + function modifyMain(url, data) { - if (url.indexOf(launchAdUrl1) > -1) { - let temp = data.match(/\{.*}/); - if (!temp) return data; + if(url.indexOf(launchAdUrl1) > -1) { + let temp = data.match(/\{.*\}/); + if(!temp) return data; data = JSON.parse(temp); if (data.ads) data.ads = []; if (data.background_delay_display_time) data.background_delay_display_time = 60 * 60 * 24 * 1000; if (data.show_push_splash_ad) data.show_push_splash_ad = false; return JSON.stringify(data) + 'OK'; } - if (url.indexOf(launchAdUrl2) > -1) { + if(url.indexOf(launchAdUrl2) > -1) { data = JSON.parse(data); if (data.cached_ad && data.cached_ad.ads) { data.cached_ad.ads = []; @@ -25,6 +32,8 @@ function modifyMain(url, data) { var body = $response.body; var url = $request.url; +// if(needModify(url)) { body = modifyMain(url, body); +// } -$done({body}); \ No newline at end of file +$done({ body }); \ No newline at end of file diff --git a/Scripts/AdBlock/Weibo/weibo_main.js b/Scripts/AdBlock/Weibo/weibo_main.js index 7fefc79..6abe47a 100644 --- a/Scripts/AdBlock/Weibo/weibo_main.js +++ b/Scripts/AdBlock/Weibo/weibo_main.js @@ -1,4 +1,4 @@ -const version = 'v0912.1'; +const version = 'v1024.1'; const $ = new Env("微博去广告"); let storeMainConfig = $.getdata('mainConfig'); @@ -40,30 +40,30 @@ const mainConfig = storeMainConfig ? JSON.parse(storeMainConfig) : { //菜单配置 const itemMenusConfig = storeItemMenusConfig ? JSON.parse(storeItemMenusConfig) : { - creator_task: false, //转发任务 - mblog_menus_custom: false, //寄微博 - mblog_menus_video_later: true, //可能是稍后再看?没出现过 - mblog_menus_comment_manager: true, //评论管理 - mblog_menus_avatar_widget: false, //头像挂件 + creator_task:false, //转发任务 + mblog_menus_custom:false, //寄微博 + mblog_menus_video_later:true, //可能是稍后再看?没出现过 + mblog_menus_comment_manager:true, //评论管理 + mblog_menus_avatar_widget:false, //头像挂件 mblog_menus_card_bg: false, //卡片背景 - mblog_menus_long_picture: true, //生成长图 - mblog_menus_delete: true, //删除 - mblog_menus_edit: true, //编辑 - mblog_menus_edit_history: true, //编辑记录 - mblog_menus_edit_video: true, //编辑视频 - mblog_menus_sticking: true, //置顶 - mblog_menus_open_reward: true, //赞赏 - mblog_menus_novelty: false, //新鲜事投稿 - mblog_menus_favorite: true, //收藏 - mblog_menus_promote: true, //推广 - mblog_menus_modify_visible: true, //设置分享范围 - mblog_menus_copy_url: true, //复制链接 - mblog_menus_follow: true, //关注 - mblog_menus_video_feedback: true, //播放反馈 - mblog_menus_shield: true, //屏蔽 - mblog_menus_report: true, //投诉 - mblog_menus_apeal: true, //申诉 - mblog_menus_home: true //返回首页 + mblog_menus_long_picture:true, //生成长图 + mblog_menus_delete:true, //删除 + mblog_menus_edit:true, //编辑 + mblog_menus_edit_history:true, //编辑记录 + mblog_menus_edit_video:true, //编辑视频 + mblog_menus_sticking:true, //置顶 + mblog_menus_open_reward:true, //赞赏 + mblog_menus_novelty:false, //新鲜事投稿 + mblog_menus_favorite:true, //收藏 + mblog_menus_promote:true, //推广 + mblog_menus_modify_visible:true, //设置分享范围 + mblog_menus_copy_url:true, //复制链接 + mblog_menus_follow:true, //关注 + mblog_menus_video_feedback:true, //播放反馈 + mblog_menus_shield:true, //屏蔽 + mblog_menus_report:true, //投诉 + mblog_menus_apeal:true, //申诉 + mblog_menus_home:true //返回首页 } const modifyCardsUrls = ['/cardlist', 'video/community_tab', '/searchall']; @@ -77,7 +77,7 @@ const otherUrls = { '/live/media_homelist': 'removeMediaHomelist', //首页直播 '/comments/build_comments': 'removeComments', //微博详情页评论区相关内容 '/container/get_item': 'containerHandler', //列表相关 - '/profile/statuses': 'userHandler', //用户主页 + '/profile/container_timeline': 'userHandler', //用户主页 '/video/tiny_stream_video_list': 'nextVideoHandler', //取消自动播放下一个视频 '/2/statuses/video_mixtimeline': 'nextVideoHandler', '/!/client/light_skin': 'tabSkinHandler', @@ -88,21 +88,23 @@ const otherUrls = { '/2/messageflow': 'removeMsgAd', '/2/page?': 'removePage', //超话签到的按钮 /2/page/button 加?区别 '/statuses/unread_topic_timeline': 'topicHandler', //超话tab + '/statuses/container_timeline': 'removeMain', } + function getModifyMethod(url) { for (const s of modifyCardsUrls) { - if (url.indexOf(s) > -1) { + if(url.indexOf(s) > -1) { return 'removeCards'; } } for (const s of modifyStatusesUrls) { - if (url.indexOf(s) > -1) { + if(url.indexOf(s) > -1) { return 'removeTimeLine'; } } - for (const [path, method] of Object.entries(otherUrls)) { - if (url.indexOf(path) > -1) { + for(const [path, method] of Object.entries(otherUrls)) { + if(url.indexOf(path) > -1) { return method; } } @@ -111,56 +113,64 @@ function getModifyMethod(url) { function isAd(data) { - if (!data) { + if(!data) { return false; } - if (data.mblogtypename == '广告' || data.mblogtypename == '热推') { - return true - } - ; - if (data.promotion && data.promotion.type == 'ad') { - return true - } - ; + if(data.mblogtypename == '广告' || data.mblogtypename == '热推') {return true}; + if(data.promotion && data.promotion.type == 'ad') {return true}; return false; } + +function removeMain(data) { + if(!data.items) { + return data; + } + let newItems = []; + for (let item of data.items) { + if(!isAd(item.data)) { + newItems.push(item); + } + } + data.items = newItems; + log('removeMain success'); + return data; +} + function topicHandler(data) { const cards = data.cards; if (!cards) return data; - if (!mainConfig.removeUnfollowTopic && !mainConfig.removeUnusedPart) return data; + if(!mainConfig.removeUnfollowTopic && !mainConfig.removeUnusedPart) return data; let newCards = []; - for (let c of cards) { + for(let c of cards) { let addFlag = true; - if (c.mblog) { + if(c.mblog) { let btns = c.mblog.buttons; - if (mainConfig.removeUnfollowTopic && btns) { - if (btns[0].type == 'follow') { + if(mainConfig.removeUnfollowTopic && btns) { + if(btns[0].type == 'follow') { addFlag = false; } } } else { - if (!mainConfig.removeUnusedPart) { + if(!mainConfig.removeUnusedPart) { continue; } - if (c.itemid == 'bottom_mix_activity') { + if(c.itemid == 'bottom_mix_activity') { addFlag = false; - } else if (c?.top?.title == '正在活跃') { + } else if(c?.top?.title == '正在活跃') { addFlag = false; - } else if (c.card_type == 200 && c.group) { + } else if(c.card_type == 200 && c.group) { addFlag = false; } else { let cGroup = c.card_group; - if (!cGroup) { - continue; - } + if(!cGroup) {continue;} let cGroup0 = cGroup[0]; - if (['guess_like_title', 'cats_top_title', 'chaohua_home_readpost_samecity_title'].indexOf(cGroup0.itemid) > -1) { + if(['guess_like_title', 'cats_top_title' ,'chaohua_home_readpost_samecity_title'].indexOf(cGroup0.itemid) > -1) { addFlag = false; - } else if (cGroup.length > 1) { + } else if(cGroup.length > 1) { let newCardGroup = []; - for (let cg of cGroup) { - if (['chaohua_discovery_banner_1', 'bottom_mix_activity'].indexOf(cg.itemid) == -1) { + for(let cg of cGroup) { + if(['chaohua_discovery_banner_1', 'bottom_mix_activity'].indexOf(cg.itemid) == -1) { newCardGroup.push(cg); } } @@ -168,7 +178,7 @@ function topicHandler(data) { } } } - if (addFlag) { + if(addFlag) { newCards.push(c); } } @@ -180,14 +190,10 @@ function topicHandler(data) { function removeSearchMain(data) { let channels = data.channelInfo.channels; - if (!channels) { - return data; - } - for (let channel of channels) { + if (!channels) {return data;} + for(let channel of channels) { let payload = channel.payload; - if (!payload) { - continue; - } + if (!payload) {continue;} removeSearch(payload) } log('remove_search main success'); @@ -196,25 +202,25 @@ function removeSearchMain(data) { function checkSearchWindow(item) { - if (!mainConfig.removeSearchWindow) return false; - if (item.category != 'card') return false; + if(!mainConfig.removeSearchWindow) return false; + if(item.category != 'card') return false; return item.data?.itemid == 'finder_window' || item.data?.itemid == 'more_frame'; } //发现页 function removeSearch(data) { - if (!data.items) { + if(!data.items) { return data; } let newItems = []; for (let item of data.items) { - if (item.category == 'feed') { - if (!isAd(item.data)) { + if(item.category == 'feed') { + if(!isAd(item.data)) { newItems.push(item); } } else { - if (!checkSearchWindow(item)) { + if(!checkSearchWindow(item)) { newItems.push(item); } } @@ -226,12 +232,12 @@ function removeSearch(data) { function removeMsgAd(data) { - if (!data.messages) { + if(!data.messages) { return; } let newMsgs = []; for (let msg of data.messages) { - if (msg.msg_card?.ad_tag) { + if(msg.msg_card?.ad_tag) { continue; } newMsgs.push(msg) @@ -240,13 +246,13 @@ function removeMsgAd(data) { return data; } -function removePage(data) { +function removePage(data){ removeCards(data); // 删除热搜列表置顶条目 if (mainConfig.removePinedTrending && data.cards && data.cards.length > 0) { if (data.cards[0].card_group) { - data.cards[0].card_group = data.cards[0].card_group.filter(c => !c.itemid.includes("t:51")); + data.cards[0].card_group = data.cards[0].card_group.filter(c=>!c.itemid.includes("t:51")); } } @@ -254,17 +260,17 @@ function removePage(data) { } function removeCards(data) { - if (!data.cards) { + if(!data.cards) { return; } let newCards = []; for (const card of data.cards) { let cardGroup = card.card_group; - if (cardGroup && cardGroup.length > 0) { + if(cardGroup && cardGroup.length > 0) { let newGroup = []; for (const group of cardGroup) { let cardType = group.card_type; - if (cardType != 118) { + if(cardType != 118) { newGroup.push(group); } } @@ -272,8 +278,8 @@ function removeCards(data) { newCards.push(card); } else { let cardType = card.card_type; - if ([9, 165].indexOf(cardType) > -1) { - if (!isAd(card.mblog)) { + if([9,165].indexOf(cardType) > -1) { + if(!isAd(card.mblog)) { newCards.push(card); } } else { @@ -286,13 +292,13 @@ function removeCards(data) { function lvZhouHandler(data) { - if (!mainConfig.removeLvZhou) return; - if (!data) return; + if(!mainConfig.removeLvZhou) return; + if(!data) return; let struct = data.common_struct; - if (!struct) return; + if(!struct) return; let newStruct = []; for (const s of struct) { - if (s.name != '绿洲') { + if(s.name != '绿洲') { newStruct.push(s); } } @@ -302,12 +308,12 @@ function lvZhouHandler(data) { function isBlock(data) { let blockIds = mainConfig.blockIds || []; - if (blockIds.length === 0) { + if(blockIds.length === 0) { return false; } let uid = data.user.id; for (const blockId of blockIds) { - if (blockId == uid) { + if(blockId == uid) { return true; } } @@ -316,18 +322,18 @@ function isBlock(data) { function removeTimeLine(data) { for (const s of ["ad", "advertises", "trends"]) { - if (data[s]) { + if(data[s]) { delete data[s]; } } - if (!data.statuses) { + if(!data.statuses) { return; } let newStatuses = []; for (const s of data.statuses) { - if (!isAd(s)) { + if(!isAd(s)) { lvZhouHandler(s); - if (!isBlock(s)) { + if(!isBlock(s)) { newStatuses.push(s); } } @@ -337,7 +343,7 @@ function removeTimeLine(data) { function removeHomeVip(data) { - if (!data.header) { + if(!data.header) { return data; } // let vipCenter = data.header.vipCenter; @@ -345,7 +351,7 @@ function removeHomeVip(data) { // vipCenter.icon = ''; // vipCenter.title.content = '会员中心'; // } - if (data.header.vipView) { + if(data.header.vipView) { data.header.vipView = null; } return data; @@ -366,37 +372,37 @@ function removeVideoRemind(data) { //微博详情页 function itemExtendHandler(data) { - if (mainConfig.removeRelate || mainConfig.removeGood) { - if (data.trend && data.trend.titles) { + if(mainConfig.removeRelate || mainConfig.removeGood) { + if(data.trend && data.trend.titles) { let title = data.trend.titles.title; - if (mainConfig.removeRelate && title === '相关推荐') { + if(mainConfig.removeRelate && title === '相关推荐') { delete data.trend; } else if (mainConfig.removeGood && title === '博主好物种草') { delete data.trend; } } } - if (mainConfig.removeFollow) { - if (data.follow_data) { + if(mainConfig.removeFollow) { + if(data.follow_data) { data.follow_data = null; } } - if (mainConfig.removeRewardItem) { - if (data.reward_info) { + if(mainConfig.removeRewardItem) { + if(data.reward_info) { data.reward_info = null; } } //删除超话新帖和新用户通知 - if (data.page_alerts) { + if(data.page_alerts) { data.page_alerts = null; } //广告 暂时判断逻辑根据图片 https://h5.sinaimg.cn/upload/1007/25/2018/05/03/timeline_icon_ad_delete.png try { let picUrl = data.trend.extra_struct.extBtnInfo.btn_picurl; - if (picUrl.indexOf('timeline_icon_ad_delete') > -1) { + if(picUrl.indexOf('timeline_icon_ad_delete') > -1) { delete data.trend; } } catch (error) { @@ -404,16 +410,16 @@ function itemExtendHandler(data) { } - if (mainConfig.modifyMenus && data.custom_action_list) { + if(mainConfig.modifyMenus && data.custom_action_list) { let newActions = []; for (const item of data.custom_action_list) { let _t = item.type; let add = itemMenusConfig[_t] - if (add === undefined) { + if(add === undefined) { newActions.push(item); - } else if (_t === 'mblog_menus_copy_url') { + } else if(_t === 'mblog_menus_copy_url') { newActions.unshift(item); - } else if (add) { + } else if(add) { newActions.push(item); } } @@ -424,7 +430,7 @@ function itemExtendHandler(data) { function updateFollowOrder(item) { try { for (let d of item.items) { - if (d.itemId === 'mainnums_friends') { + if(d.itemId === 'mainnums_friends') { let s = d.click.modules[0].scheme; d.click.modules[0].scheme = s.replace('231093_-_selfrecomm', '231093_-_selffollowed'); log('updateFollowOrder success'); @@ -439,21 +445,19 @@ function updateFollowOrder(item) { function updateProfileSkin(item, k) { try { let profileSkin = mainConfig[k]; - if (!profileSkin) { - return; - } + if(!profileSkin) {return;} let i = 0; for (let d of item.items) { - if (!d.image) { + if(!d.image) { continue; } try { dm = d.image.style.darkMode - if (dm != 'alpha') { + if(dm != 'alpha') { d.image.style.darkMode = 'alpha' } d.image.iconUrl = profileSkin[i++]; - if (d.dot) { + if(d.dot) { d.dot = []; } } catch (error) { @@ -468,14 +472,14 @@ function updateProfileSkin(item, k) { function removeHome(data) { - if (!data.items) { + if(!data.items) { return data; } let newItems = []; for (let item of data.items) { let itemId = item.itemId; - if (itemId == 'profileme_mine') { - if (mainConfig.removeHomeVip) { + if(itemId == 'profileme_mine') { + if(mainConfig.removeHomeVip) { item = removeHomeVip(item); } updateFollowOrder(item); @@ -484,15 +488,15 @@ function removeHome(data) { updateProfileSkin(item, 'profileSkin1'); newItems.push(item); } else if (itemId == '100505_-_newcreator') { - if (item.type == 'grid') { + if(item.type == 'grid') { updateProfileSkin(item, 'profileSkin2'); newItems.push(item); } else { - if (!mainConfig.removeHomeCreatorTask) { + if(!mainConfig.removeHomeCreatorTask) { newItems.push(item); } } - } else if (['mine_attent_title', '100505_-_meattent_pic', '100505_-_newusertask', '100505_-_vipkaitong', '100505_-_hongbao2022', '100505_-_adphoto'].indexOf(itemId) > -1) { + } else if(['mine_attent_title', '100505_-_meattent_pic', '100505_-_newusertask', '100505_-_vipkaitong', '100505_-_hongbao2022', '100505_-_adphoto'].indexOf(itemId) > -1) { continue; } else if (itemId.match(/100505_-_meattent_-_\d+/)) { continue; @@ -514,7 +518,7 @@ function removeCheckin(data) { //首页直播 function removeMediaHomelist(data) { - if (mainConfig.removeLiveMedia) { + if(mainConfig.removeLiveMedia) { log('remove 首页直播'); data.data = {}; } @@ -523,15 +527,15 @@ function removeMediaHomelist(data) { //评论区相关和推荐内容 function removeComments(data) { let delType = ['广告']; - if (mainConfig.removeRelateItem) delType.push('相关内容'); - if (mainConfig.removeRecommendItem) delType.push(...['推荐', '热推']); + if(mainConfig.removeRelateItem) delType.push('相关内容'); + if(mainConfig.removeRecommendItem) delType.push(...['推荐', '热推']); // if(delType.length === 0) return; let items = data.datas || []; - if (items.length === 0) return; + if(items.length === 0) return; let newItems = []; for (const item of items) { let adType = item.adType || ''; - if (delType.indexOf(adType) == -1) { + if(delType.indexOf(adType) == -1) { newItems.push(item); } } @@ -542,17 +546,17 @@ function removeComments(data) { //处理感兴趣的超话和超话里的好友 function containerHandler(data) { - if (mainConfig.removeInterestFriendInTopic) { - if (data.card_type_name === '超话里的好友') { + if(mainConfig.removeInterestFriendInTopic) { + if(data.card_type_name === '超话里的好友') { log('remove 超话里的好友'); data.card_group = []; } } - if (mainConfig.removeInterestTopic && data.itemid) { - if (data.itemid.indexOf('infeed_may_interest_in') > -1) { + if(mainConfig.removeInterestTopic && data.itemid) { + if(data.itemid.indexOf('infeed_may_interest_in') > -1) { log('remove 感兴趣的超话'); data.card_group = []; - } else if (data.itemid.indexOf('infeed_friends_recommend') > -1) { + } else if(data.itemid.indexOf('infeed_friends_recommend') > -1) { log('remove 超话好友关注'); data.card_group = []; } @@ -561,30 +565,37 @@ function containerHandler(data) { //可能感兴趣的人 function userHandler(data) { - if (!mainConfig.removeInterestUser) { - return; + data = removeMain(data); + if(!mainConfig.removeInterestUser) { + return data; } - let items = data.cards || []; - if (items.length === 0) { - return; + + if(!data.items) { + return data; } let newItems = []; - for (const item of items) { - if (item.itemid == 'INTEREST_PEOPLE') { - log('remove 感兴趣的人'); - } else { - if (!isAd(item.mblog)) { - lvZhouHandler(item.mblog); - newItems.push(item); + for (let item of data.items) { + let isAdd = true; + if(item.category == 'group') { + try { + if(item.items[0]['data']['desc'] == '可能感兴趣的人') { + isAdd = false; + } + } catch (error) { } } + if(isAdd) { + newItems.push(item); + } } - data.cards = newItems; + data.items = newItems; + log('removeMain sub success'); + return data; } function nextVideoHandler(data) { - if (mainConfig.removeNextVideo) { + if(mainConfig.removeNextVideo) { data.statuses = []; data.tab_list = []; console.log('nextVideoHandler'); @@ -595,8 +606,8 @@ function tabSkinHandler(data) { try { let iconVersion = mainConfig.tabIconVersion; data['data']['canUse'] = 1 - if (!iconVersion || !mainConfig.tabIconPath) return; - if (iconVersion < 100) return; + if(!iconVersion || !mainConfig.tabIconPath) return; + if(iconVersion < 100) return; let skinList = data['data']['list'] for (let skin of skinList) { @@ -626,326 +637,18 @@ function skinPreviewHandler(data) { // } function log(data) { - if (mainConfig.isDebug) { + if(mainConfig.isDebug) { console.log(data); } } -function Env(t, e) { - class s { - constructor(t) { - this.env = t - } - - send(t, e = "GET") { - t = "string" == typeof t ? {url: t} : t; - let s = this.get; - return "POST" === e && (s = this.post), new Promise((e, i) => { - s.call(this, t, (t, s, r) => { - t ? i(t) : e(s) - }) - }) - } - - get(t) { - return this.send.call(this.env, t) - } - - post(t) { - return this.send.call(this.env, t, "POST") - } - } - - return new class { - constructor(t, e) { - this.name = t, this.http = new s(this), this.data = null, this.dataFile = "box.dat", this.logs = [], this.isMute = !1, this.isNeedRewrite = !1, this.logSeparator = "\n", this.encoding = "utf-8", this.startTime = (new Date).getTime(), Object.assign(this, e), this.log("", `🔔${this.name}, 开始!`) - } - - isNode() { - return "undefined" != typeof module && !!module.exports - } - - isQuanX() { - return "undefined" != typeof $task - } - - isSurge() { - return "undefined" != typeof $httpClient && "undefined" == typeof $loon - } - - isLoon() { - return "undefined" != typeof $loon - } - - isShadowrocket() { - return "undefined" != typeof $rocket - } - - isStash() { - return "undefined" != typeof $environment && $environment["stash-version"] - } - - toObj(t, e = null) { - try { - return JSON.parse(t) - } catch { - return e - } - } - - toStr(t, e = null) { - try { - return JSON.stringify(t) - } catch { - return e - } - } - - getjson(t, e) { - let s = e; - const i = this.getdata(t); - if (i) try { - s = JSON.parse(this.getdata(t)) - } catch { - } - return s - } - - setjson(t, e) { - try { - return this.setdata(JSON.stringify(t), e) - } catch { - return !1 - } - } - - getScript(t) { - return new Promise(e => { - this.get({url: t}, (t, s, i) => e(i)) - }) - } - - runScript(t, e) { - return new Promise(s => { - let i = this.getdata("@chavy_boxjs_userCfgs.httpapi"); - i = i ? i.replace(/\n/g, "").trim() : i; - let r = this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout"); - r = r ? 1 * r : 20, r = e && e.timeout ? e.timeout : r; - const [o, n] = i.split("@"), a = { - url: `http://${n}/v1/scripting/evaluate`, - body: {script_text: t, mock_type: "cron", timeout: r}, - headers: {"X-Key": o, Accept: "*/*"} - }; - this.post(a, (t, e, i) => s(i)) - }).catch(t => this.logErr(t)) - } - - loaddata() { - if (!this.isNode()) return {}; - { - this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); - const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), - s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e); - if (!s && !i) return {}; - { - const i = s ? t : e; - try { - return JSON.parse(this.fs.readFileSync(i)) - } catch (t) { - return {} - } - } - } - } - - writedata() { - if (this.isNode()) { - this.fs = this.fs ? this.fs : require("fs"), this.path = this.path ? this.path : require("path"); - const t = this.path.resolve(this.dataFile), e = this.path.resolve(process.cwd(), this.dataFile), - s = this.fs.existsSync(t), i = !s && this.fs.existsSync(e), r = JSON.stringify(this.data); - s ? this.fs.writeFileSync(t, r) : i ? this.fs.writeFileSync(e, r) : this.fs.writeFileSync(t, r) - } - } - - lodash_get(t, e, s) { - const i = e.replace(/\[(\d+)\]/g, ".$1").split("."); - let r = t; - for (const t of i) if (r = Object(r)[t], void 0 === r) return s; - return r - } - - lodash_set(t, e, s) { - return Object(t) !== t ? t : (Array.isArray(e) || (e = e.toString().match(/[^.[\]]+/g) || []), e.slice(0, -1).reduce((t, s, i) => Object(t[s]) === t[s] ? t[s] : t[s] = Math.abs(e[i + 1]) >> 0 == +e[i + 1] ? [] : {}, t)[e[e.length - 1]] = s, t) - } - - getdata(t) { - let e = this.getval(t); - if (/^@/.test(t)) { - const [, s, i] = /^@(.*?)\.(.*?)$/.exec(t), r = s ? this.getval(s) : ""; - if (r) try { - const t = JSON.parse(r); - e = t ? this.lodash_get(t, i, "") : e - } catch (t) { - e = "" - } - } - return e - } - - setdata(t, e) { - let s = !1; - if (/^@/.test(e)) { - const [, i, r] = /^@(.*?)\.(.*?)$/.exec(e), o = this.getval(i), - n = i ? "null" === o ? null : o || "{}" : "{}"; - try { - const e = JSON.parse(n); - this.lodash_set(e, r, t), s = this.setval(JSON.stringify(e), i) - } catch (e) { - const o = {}; - this.lodash_set(o, r, t), s = this.setval(JSON.stringify(o), i) - } - } else s = this.setval(t, e); - return s - } - - getval(t) { - return this.isSurge() || this.isLoon() ? $persistentStore.read(t) : this.isQuanX() ? $prefs.valueForKey(t) : this.isNode() ? (this.data = this.loaddata(), this.data[t]) : this.data && this.data[t] || null - } - - setval(t, e) { - return this.isSurge() || this.isLoon() ? $persistentStore.write(t, e) : this.isQuanX() ? $prefs.setValueForKey(t, e) : this.isNode() ? (this.data = this.loaddata(), this.data[e] = t, this.writedata(), !0) : this.data && this.data[e] || null - } - - initGotEnv(t) { - this.got = this.got ? this.got : require("got"), this.cktough = this.cktough ? this.cktough : require("tough-cookie"), this.ckjar = this.ckjar ? this.ckjar : new this.cktough.CookieJar, t && (t.headers = t.headers ? t.headers : {}, void 0 === t.headers.Cookie && void 0 === t.cookieJar && (t.cookieJar = this.ckjar)) - } - - get(t, e = (() => { - })) { - if (t.headers && (delete t.headers["Content-Type"], delete t.headers["Content-Length"]), this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, {"X-Surge-Skip-Scripting": !1})), $httpClient.get(t, (t, s, i) => { - !t && s && (s.body = i, s.statusCode = s.status ? s.status : s.statusCode, s.status = s.statusCode), e(t, s, i) - }); else if (this.isQuanX()) this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, {hints: !1})), $task.fetch(t).then(t => { - const {statusCode: s, statusCode: i, headers: r, body: o} = t; - e(null, {status: s, statusCode: i, headers: r, body: o}, o) - }, t => e(t && t.error || "UndefinedError")); else if (this.isNode()) { - let s = require("iconv-lite"); - this.initGotEnv(t), this.got(t).on("redirect", (t, e) => { - try { - if (t.headers["set-cookie"]) { - const s = t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString(); - s && this.ckjar.setCookieSync(s, null), e.cookieJar = this.ckjar - } - } catch (t) { - this.logErr(t) - } - }).then(t => { - const {statusCode: i, statusCode: r, headers: o, rawBody: n} = t, a = s.decode(n, this.encoding); - e(null, {status: i, statusCode: r, headers: o, rawBody: n, body: a}, a) - }, t => { - const {message: i, response: r} = t; - e(i, r, r && s.decode(r.rawBody, this.encoding)) - }) - } - } - - post(t, e = (() => { - })) { - const s = t.method ? t.method.toLocaleLowerCase() : "post"; - if (t.body && t.headers && !t.headers["Content-Type"] && (t.headers["Content-Type"] = "application/x-www-form-urlencoded"), t.headers && delete t.headers["Content-Length"], this.isSurge() || this.isLoon()) this.isSurge() && this.isNeedRewrite && (t.headers = t.headers || {}, Object.assign(t.headers, {"X-Surge-Skip-Scripting": !1})), $httpClient[s](t, (t, s, i) => { - !t && s && (s.body = i, s.statusCode = s.status ? s.status : s.statusCode, s.status = s.statusCode), e(t, s, i) - }); else if (this.isQuanX()) t.method = s, this.isNeedRewrite && (t.opts = t.opts || {}, Object.assign(t.opts, {hints: !1})), $task.fetch(t).then(t => { - const {statusCode: s, statusCode: i, headers: r, body: o} = t; - e(null, {status: s, statusCode: i, headers: r, body: o}, o) - }, t => e(t && t.error || "UndefinedError")); else if (this.isNode()) { - let i = require("iconv-lite"); - this.initGotEnv(t); - const {url: r, ...o} = t; - this.got[s](r, o).then(t => { - const {statusCode: s, statusCode: r, headers: o, rawBody: n} = t, a = i.decode(n, this.encoding); - e(null, {status: s, statusCode: r, headers: o, rawBody: n, body: a}, a) - }, t => { - const {message: s, response: r} = t; - e(s, r, r && i.decode(r.rawBody, this.encoding)) - }) - } - } - - time(t, e = null) { - const s = e ? new Date(e) : new Date; - let i = { - "M+": s.getMonth() + 1, - "d+": s.getDate(), - "H+": s.getHours(), - "m+": s.getMinutes(), - "s+": s.getSeconds(), - "q+": Math.floor((s.getMonth() + 3) / 3), - S: s.getMilliseconds() - }; - /(y+)/.test(t) && (t = t.replace(RegExp.$1, (s.getFullYear() + "").substr(4 - RegExp.$1.length))); - for (let e in i) new RegExp("(" + e + ")").test(t) && (t = t.replace(RegExp.$1, 1 == RegExp.$1.length ? i[e] : ("00" + i[e]).substr(("" + i[e]).length))); - return t - } - - queryStr(t) { - let e = ""; - for (const s in t) { - let i = t[s]; - null != i && "" !== i && ("object" == typeof i && (i = JSON.stringify(i)), e += `${s}=${i}&`) - } - return e = e.substring(0, e.length - 1), e - } - - msg(e = t, s = "", i = "", r) { - const o = t => { - if (!t) return t; - if ("string" == typeof t) return this.isLoon() ? t : this.isQuanX() ? {"open-url": t} : this.isSurge() ? {url: t} : void 0; - if ("object" == typeof t) { - if (this.isLoon()) { - let e = t.openUrl || t.url || t["open-url"], s = t.mediaUrl || t["media-url"]; - return {openUrl: e, mediaUrl: s} - } - if (this.isQuanX()) { - let e = t["open-url"] || t.url || t.openUrl, s = t["media-url"] || t.mediaUrl, - i = t["update-pasteboard"] || t.updatePasteboard; - return {"open-url": e, "media-url": s, "update-pasteboard": i} - } - if (this.isSurge()) { - let e = t.url || t.openUrl || t["open-url"]; - return {url: e} - } - } - }; - if (this.isMute || (this.isSurge() || this.isLoon() ? $notification.post(e, s, i, o(r)) : this.isQuanX() && $notify(e, s, i, o(r))), !this.isMuteLog) { - let t = ["", "==============📣系统通知📣=============="]; - t.push(e), s && t.push(s), i && t.push(i), console.log(t.join("\n")), this.logs = this.logs.concat(t) - } - } - - log(...t) { - t.length > 0 && (this.logs = [...this.logs, ...t]), console.log(t.join(this.logSeparator)) - } - - logErr(t, e) { - const s = !this.isSurge() && !this.isQuanX() && !this.isLoon(); - s ? this.log("", `❗️${this.name}, 错误!`, t.stack) : this.log("", `❗️${this.name}, 错误!`, t) - } - - wait(t) { - return new Promise(e => setTimeout(e, t)) - } - - done(t = {}) { - const e = (new Date).getTime(), s = (e - this.startTime) / 1e3; - this.log("", `🔔${this.name}, 结束! 🕛 ${s} 秒`), this.log(), this.isSurge() || this.isQuanX() || this.isLoon() ? $done(t) : this.isNode() && process.exit(1) - } - }(t, e) -} +function Env(t,e){class s{constructor(t){this.env=t}send(t,e="GET"){t="string"==typeof t?{url:t}:t;let s=this.get;return"POST"===e&&(s=this.post),new Promise((e,i)=>{s.call(this,t,(t,s,r)=>{t?i(t):e(s)})})}get(t){return this.send.call(this.env,t)}post(t){return this.send.call(this.env,t,"POST")}}return new class{constructor(t,e){this.name=t,this.http=new s(this),this.data=null,this.dataFile="box.dat",this.logs=[],this.isMute=!1,this.isNeedRewrite=!1,this.logSeparator="\n",this.encoding="utf-8",this.startTime=(new Date).getTime(),Object.assign(this,e),this.log("",`🔔${this.name}, 开始!`)}isNode(){return"undefined"!=typeof module&&!!module.exports}isQuanX(){return"undefined"!=typeof $task}isSurge(){return"undefined"!=typeof $httpClient&&"undefined"==typeof $loon}isLoon(){return"undefined"!=typeof $loon}isShadowrocket(){return"undefined"!=typeof $rocket}isStash(){return"undefined"!=typeof $environment&&$environment["stash-version"]}toObj(t,e=null){try{return JSON.parse(t)}catch{return e}}toStr(t,e=null){try{return JSON.stringify(t)}catch{return e}}getjson(t,e){let s=e;const i=this.getdata(t);if(i)try{s=JSON.parse(this.getdata(t))}catch{}return s}setjson(t,e){try{return this.setdata(JSON.stringify(t),e)}catch{return!1}}getScript(t){return new Promise(e=>{this.get({url:t},(t,s,i)=>e(i))})}runScript(t,e){return new Promise(s=>{let i=this.getdata("@chavy_boxjs_userCfgs.httpapi");i=i?i.replace(/\n/g,"").trim():i;let r=this.getdata("@chavy_boxjs_userCfgs.httpapi_timeout");r=r?1*r:20,r=e&&e.timeout?e.timeout:r;const[o,n]=i.split("@"),a={url:`http://${n}/v1/scripting/evaluate`,body:{script_text:t,mock_type:"cron",timeout:r},headers:{"X-Key":o,Accept:"*/*"}};this.post(a,(t,e,i)=>s(i))}).catch(t=>this.logErr(t))}loaddata(){if(!this.isNode())return{};{this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e);if(!s&&!i)return{};{const i=s?t:e;try{return JSON.parse(this.fs.readFileSync(i))}catch(t){return{}}}}}writedata(){if(this.isNode()){this.fs=this.fs?this.fs:require("fs"),this.path=this.path?this.path:require("path");const t=this.path.resolve(this.dataFile),e=this.path.resolve(process.cwd(),this.dataFile),s=this.fs.existsSync(t),i=!s&&this.fs.existsSync(e),r=JSON.stringify(this.data);s?this.fs.writeFileSync(t,r):i?this.fs.writeFileSync(e,r):this.fs.writeFileSync(t,r)}}lodash_get(t,e,s){const i=e.replace(/\[(\d+)\]/g,".$1").split(".");let r=t;for(const t of i)if(r=Object(r)[t],void 0===r)return s;return r}lodash_set(t,e,s){return Object(t)!==t?t:(Array.isArray(e)||(e=e.toString().match(/[^.[\]]+/g)||[]),e.slice(0,-1).reduce((t,s,i)=>Object(t[s])===t[s]?t[s]:t[s]=Math.abs(e[i+1])>>0==+e[i+1]?[]:{},t)[e[e.length-1]]=s,t)}getdata(t){let e=this.getval(t);if(/^@/.test(t)){const[,s,i]=/^@(.*?)\.(.*?)$/.exec(t),r=s?this.getval(s):"";if(r)try{const t=JSON.parse(r);e=t?this.lodash_get(t,i,""):e}catch(t){e=""}}return e}setdata(t,e){let s=!1;if(/^@/.test(e)){const[,i,r]=/^@(.*?)\.(.*?)$/.exec(e),o=this.getval(i),n=i?"null"===o?null:o||"{}":"{}";try{const e=JSON.parse(n);this.lodash_set(e,r,t),s=this.setval(JSON.stringify(e),i)}catch(e){const o={};this.lodash_set(o,r,t),s=this.setval(JSON.stringify(o),i)}}else s=this.setval(t,e);return s}getval(t){return this.isSurge()||this.isLoon()?$persistentStore.read(t):this.isQuanX()?$prefs.valueForKey(t):this.isNode()?(this.data=this.loaddata(),this.data[t]):this.data&&this.data[t]||null}setval(t,e){return this.isSurge()||this.isLoon()?$persistentStore.write(t,e):this.isQuanX()?$prefs.setValueForKey(t,e):this.isNode()?(this.data=this.loaddata(),this.data[e]=t,this.writedata(),!0):this.data&&this.data[e]||null}initGotEnv(t){this.got=this.got?this.got:require("got"),this.cktough=this.cktough?this.cktough:require("tough-cookie"),this.ckjar=this.ckjar?this.ckjar:new this.cktough.CookieJar,t&&(t.headers=t.headers?t.headers:{},void 0===t.headers.Cookie&&void 0===t.cookieJar&&(t.cookieJar=this.ckjar))}get(t,e=(()=>{})){if(t.headers&&(delete t.headers["Content-Type"],delete t.headers["Content-Length"]),this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient.get(t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let s=require("iconv-lite");this.initGotEnv(t),this.got(t).on("redirect",(t,e)=>{try{if(t.headers["set-cookie"]){const s=t.headers["set-cookie"].map(this.cktough.Cookie.parse).toString();s&&this.ckjar.setCookieSync(s,null),e.cookieJar=this.ckjar}}catch(t){this.logErr(t)}}).then(t=>{const{statusCode:i,statusCode:r,headers:o,rawBody:n}=t,a=s.decode(n,this.encoding);e(null,{status:i,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:i,response:r}=t;e(i,r,r&&s.decode(r.rawBody,this.encoding))})}}post(t,e=(()=>{})){const s=t.method?t.method.toLocaleLowerCase():"post";if(t.body&&t.headers&&!t.headers["Content-Type"]&&(t.headers["Content-Type"]="application/x-www-form-urlencoded"),t.headers&&delete t.headers["Content-Length"],this.isSurge()||this.isLoon())this.isSurge()&&this.isNeedRewrite&&(t.headers=t.headers||{},Object.assign(t.headers,{"X-Surge-Skip-Scripting":!1})),$httpClient[s](t,(t,s,i)=>{!t&&s&&(s.body=i,s.statusCode=s.status?s.status:s.statusCode,s.status=s.statusCode),e(t,s,i)});else if(this.isQuanX())t.method=s,this.isNeedRewrite&&(t.opts=t.opts||{},Object.assign(t.opts,{hints:!1})),$task.fetch(t).then(t=>{const{statusCode:s,statusCode:i,headers:r,body:o}=t;e(null,{status:s,statusCode:i,headers:r,body:o},o)},t=>e(t&&t.error||"UndefinedError"));else if(this.isNode()){let i=require("iconv-lite");this.initGotEnv(t);const{url:r,...o}=t;this.got[s](r,o).then(t=>{const{statusCode:s,statusCode:r,headers:o,rawBody:n}=t,a=i.decode(n,this.encoding);e(null,{status:s,statusCode:r,headers:o,rawBody:n,body:a},a)},t=>{const{message:s,response:r}=t;e(s,r,r&&i.decode(r.rawBody,this.encoding))})}}time(t,e=null){const s=e?new Date(e):new Date;let i={"M+":s.getMonth()+1,"d+":s.getDate(),"H+":s.getHours(),"m+":s.getMinutes(),"s+":s.getSeconds(),"q+":Math.floor((s.getMonth()+3)/3),S:s.getMilliseconds()};/(y+)/.test(t)&&(t=t.replace(RegExp.$1,(s.getFullYear()+"").substr(4-RegExp.$1.length)));for(let e in i)new RegExp("("+e+")").test(t)&&(t=t.replace(RegExp.$1,1==RegExp.$1.length?i[e]:("00"+i[e]).substr((""+i[e]).length)));return t}queryStr(t){let e="";for(const s in t){let i=t[s];null!=i&&""!==i&&("object"==typeof i&&(i=JSON.stringify(i)),e+=`${s}=${i}&`)}return e=e.substring(0,e.length-1),e}msg(e=t,s="",i="",r){const o=t=>{if(!t)return t;if("string"==typeof t)return this.isLoon()?t:this.isQuanX()?{"open-url":t}:this.isSurge()?{url:t}:void 0;if("object"==typeof t){if(this.isLoon()){let e=t.openUrl||t.url||t["open-url"],s=t.mediaUrl||t["media-url"];return{openUrl:e,mediaUrl:s}}if(this.isQuanX()){let e=t["open-url"]||t.url||t.openUrl,s=t["media-url"]||t.mediaUrl,i=t["update-pasteboard"]||t.updatePasteboard;return{"open-url":e,"media-url":s,"update-pasteboard":i}}if(this.isSurge()){let e=t.url||t.openUrl||t["open-url"];return{url:e}}}};if(this.isMute||(this.isSurge()||this.isLoon()?$notification.post(e,s,i,o(r)):this.isQuanX()&&$notify(e,s,i,o(r))),!this.isMuteLog){let t=["","==============📣系统通知📣=============="];t.push(e),s&&t.push(s),i&&t.push(i),console.log(t.join("\n")),this.logs=this.logs.concat(t)}}log(...t){t.length>0&&(this.logs=[...this.logs,...t]),console.log(t.join(this.logSeparator))}logErr(t,e){const s=!this.isSurge()&&!this.isQuanX()&&!this.isLoon();s?this.log("",`❗️${this.name}, 错误!`,t.stack):this.log("",`❗️${this.name}, 错误!`,t)}wait(t){return new Promise(e=>setTimeout(e,t))}done(t={}){const e=(new Date).getTime(),s=(e-this.startTime)/1e3;this.log("",`🔔${this.name}, 结束! 🕛 ${s} 秒`),this.log(),this.isSurge()||this.isQuanX()||this.isLoon()?$done(t):this.isNode()&&process.exit(1)}}(t,e)} var body = $response.body; var url = $request.url; let method = getModifyMethod(url); -if (method) { +if(method) { log(method); var func = eval(method); let data = JSON.parse(body); @@ -953,4 +656,4 @@ if (method) { body = JSON.stringify(data); } -$.done({body}); \ No newline at end of file +$.done({ body }); \ No newline at end of file