// ==UserScript== // @name PSN中文网功能增强 // @namespace https://swsoyee.github.io // @version 0.9.11 // @description 数折价格走势图,显示人民币价格,奖杯统计和筛选,发帖字数统计和即时预览,楼主高亮,自动翻页,屏蔽黑名单用户发言,被@用户的发言内容显示等多项功能优化P9体验 // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADIAAAAyCAMAAAAp4XiDAAAAMFBMVEVHcEw0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNs0mNuEOyNSAAAAD3RSTlMAQMAQ4PCApCBQcDBg0JD74B98AAABN0lEQVRIx+2WQRaDIAxECSACWLn/bdsCIkNQ2XXT2bTyHEx+glGIv4STU3KNRccp6dNh4qTM4VDLrGVRxbLGaa3ZQSVQulVJl5JFlh3cLdNyk/xe2IXz4DqYLhZ4mWtHd4/SLY/QQwKmWmGcmUfHb4O1mu8BIPGw4Hg1TEvySQGWoBcItgxndmsbhtJd6baukIKnt525W4anygNECVc1UD8uVbRNbumZNl6UmkagHeRJfX0BdM5NXgA+ZKESpiJ9tRFftZEvue2cS6cKOrGk/IOLTLUcaXuZHrZDq3FB2IonOBCHIy8Bs1Zzo1MxVH+m8fQ+nFeCQM3MWwEsWsy8e8Di7meA5Bb5MDYCt4SnUbP3lv1xOuWuOi3j5kJ5tPiZKahbi54anNRaaG7YElFKQBHR/9PjN3oD6fkt9WKF9rgAAAAASUVORK5CYII= // @author InfinityLoop, mordom0404, Nathaniel_Wu // @include *psnine.com/* // @include *d7vg.com/* // @require http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js // @require https://code.highcharts.com/highcharts.js // @require https://code.highcharts.com/modules/histogram-bellcurve.js // @require https://unpkg.com/tippy.js@3/dist/tippy.all.min.js // @license MIT // @supportURL https://github.com/swsoyee/psnine-night-mode-CSS/issues/new // @compatible chrome // @compatible firefox // @compatible edge // @grant GM_addStyle // @downloadURL none // ==/UserScript== (function () { 'use strict'; var settings = { // 功能0-1.1:恢复导航部的新闻链接 addNews: false, // 设置为false默认关闭 // 功能0-3设置:鼠标滑过黑条即可显示内容 hoverUnmark: true, // 设置为false则选中才显示 // 功能0-5设置:是否开启自动签到 autoCheckIn: true, // 功能0-6: 自动翻页 autoPaging: 0, // 自动往后翻的页数 // 功能0-7:个人主页下显示所有游戏 autoPagingInHomepage: true, // 功能1-4:回复内容回溯 replyTraceback: true, // 功能1-1设置:高亮发帖楼主功能 highlightBack: '#3890ff', // 高亮背景色 highlightFront: '#ffffff', // 高亮字体颜色 // 功能1-2设置:高亮具体ID功能(默认管理员id) // 注:此部分功能源于@mordom0404的P9工具包: // https://greasyfork.org/zh-CN/scripts/29343-p9%E5%B7%A5%E5%85%B7%E5%8C%85 highlightSpecificID: ['mechille', 'sai8808', 'jimmyleo', 'jimmyleohk'], // 需要高亮的ID数组 highlightSpecificBack: '#d9534f', // 高亮背景色 highlightSpecificFront: '#ffffff', // 高亮字体颜色 // 功能1-6设置:屏蔽黑名单中的用户发言内容 blockList: [], // 请在左侧输入用户ID,用逗号进行分割,如: ['use_a', 'user_b', 'user_c'] 以此类推 // 功能1-10设置:问答根据回答状态对标题着色 qaHighlightTitle: true, // 功能1-11设置:鼠标悬浮于头像显示个人奖杯卡 hoverHomepage: true, // 功能2-2设置:汇率设置 dollarHKRatio: 0.88, // 港币汇率 dollarRatio: 6.9, // 美元汇率 poundRatio: 7.8, // 英镑汇率 yenRatio: 0.06, // 日元汇率 // 功能4-3设置:汇总以获得和未获得奖杯是否默认折叠 foldTropySummary: false, // true则默认折叠,false则默认展开 // 功能5-1设置:是否在`游戏`页面启用降低无白金游戏的图标透明度 filterNonePlatinumAlpha: 0.2, // 透密 [0, 1] 不透明,如果设置为1则关闭该功能 //夜间模式 nightMode: false, // 约战页面去掉发起人头像 removeHeaderInBattle: false, }; Highcharts.setOptions({ lang: { contextButtonTitle: '图表导出菜单', decimalPoint: '.', downloadJPEG: '下载JPEG图片', downloadPDF: '下载PDF文件', downloadPNG: '下载PNG文件', downloadSVG: '下载SVG文件', drillUpText: '返回 {series.name}', loading: '加载中', months: [ '一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月', ], noData: '没有数据', numericSymbols: ['千', '兆', 'G', 'T', 'P', 'E'], printChart: '打印图表', resetZoom: '恢复缩放', resetZoomTitle: '恢复图表', shortMonths: [ '1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月', ], thousandsSep: ',', weekdays: ['周一', '周二', '周三', '周四', '周五', '周六', '周日'], }, }); if (window.localStorage) { if (window.localStorage['psnine-night-mode-CSS-settings']) { $.extend( settings, JSON.parse(window.localStorage['psnine-night-mode-CSS-settings']) ); //用storage中的配置项覆盖默认设置 } } else { console.log('浏览器不支持localStorage,使用默认配置项'); } // 全局优化 /* * 页面右下角追加点击跳转到页面底部按钮 */ const toPageBottom = () => { $('.bottombar').append("B"); $('#scrollbottom').click(() => { $('body,html').animate({ scrollTop: document.body.clientHeight, }, 500 ); }); } /* * 恢复Header部的新闻链接 * @param isOn 是否开启功能 */ const addNews = (isOn) => { if (isOn) { $('#pcmenu > li:nth-child(1)').before( "
  • 新闻
  • " ); } } // 功能0-2:夜间模式 if (settings.nightMode) { $('body').append(` `); } /* * 功能:黑条文字鼠标悬浮显示 * param: isOn 是否开启功能 */ const showMarkMessage = (isOn) => { if (isOn) { window.addEventListener('load', () => { $('.mark').hover( function () { $(this).css({ color: "rgb(255,255,255)" }); }, function () { $(this).css({ color: $(this).css('background-color') }); } ); }) } } showMarkMessage(settings.hoverUnmark); /* * 自动签到功能 * @param isOn 是否开启功能 */ const automaticSignIn = (isOn) => { // 如果签到按钮存在页面上 if (isOn && $('[class$=yuan]').length > 0) { $('[class$=yuan]').click(); } } automaticSignIn(settings.autoCheckIn); /* 获取当前页面的后一页页码和链接 * @return nextPage 后一页页码 * @return nextPageLink 后一页的链接 */ const getNextPageInfo = () => { // 获取下一页页码 const nextPage = Number($('.page > ul > .current:last').text()) + 1; // 如果地址已经有地址信息 let nextPageLink = ''; if (/page/.test(window.location.href)) { nextPageLink = window.location.href.replace( /page=.+/, 'page=' + nextPage ); } else { nextPageLink = window.location.href + '&page=' + nextPage; } return { nextPage, nextPageLink } } GM_addStyle( `#loadingMessage { position : absolute; bottom : 0px; position : fixed; right : 1px !important; display : none; color : white; }` ); /* * 功能:自动翻页 * @param pagingSetting 自动翻页的页数 */ const autoPaging = (pagingSetting) => { if (pagingSetting > 0) { let isbool = true; //触发开关,防止多次调用事件 let autoPagingLimitCount = 0; $(window).scroll(function () { //当内容滚动到底部时加载新的内容 if ( $(this).scrollTop() + $(window).height() + 700 >= $(document).height() && $(this).scrollTop() > 700 && isbool == true && autoPagingLimitCount < settings.autoPaging ) { isbool = false; // 获取下一页页码和链接 const { nextPage, nextPageLink } = getNextPageInfo(); // 加载页面并且插入 $('#loadingMessage').text(`加载第${nextPage}页...`).show(); $('.page:last').after(`
    `); $.get( nextPageLink, {}, (data) => { const $response = $('
    ').html(data); $(`.loadPage${nextPage}`) .append($response.find('.list')) .append($response.find('.page')); isbool = true; autoPagingLimitCount++; // 各个页面的功能追加 if (/\/qa/.test(window.location.href)) { addColorToQaTitle(settings.qaHighlightTitle); } addHighlightOnID(); filterUserPost(); addHoverProfile(); }, 'html' ); setTimeout(() => { $('#loadingMessage').fadeOut(); }, 2000); } }); } } // 功能0-7:个人主页下显示所有游戏 if (settings.autoPagingInHomepage) { let isbool2 = true; //触发开关,防止多次调用事件 // 插入加载提示信息 $('body').append("
    "); if ( /psnid\/[A-Za-z0-9_-]+$/.test(window.location.href) && $('tbody').length > 2 ) { var gamePageIndex = 2; $(window).scroll(function () { if ( $(this).scrollTop() + $(window).height() + 700 >= $(document).height() && $(this).scrollTop() > 700 && isbool2 == true ) { isbool2 = false; var gamePage = window.location.href + '/psngame?page=' + gamePageIndex; // 加载页面并且插入 $('#loadingMessage').text(`加载第${gamePageIndex}页...`).show(); $.get( gamePage, {}, (data) => { var $response = $('
    ').html(data); var nextGameContent = $response.find('tbody > tr'); if (nextGameContent.length > 0) { $('tbody > tr:last').after(nextGameContent); isbool2 = true; gamePageIndex++; } else { $('#loadingMessage').text('没有更多游戏了...'); } }, 'html' ); setTimeout(() => { $('#loadingMessage').fadeOut(); }, 2000); } }); } } // 帖子优化 /* * 功能:对发帖楼主增加“楼主”标志 * @param userId 用户(楼主)ID */ const addOPBadge = (userId) => { $('.psnnode').map((i, n) => { // 匹配楼主ID,变更CSS if ($(n).text() == userId) { $(n).after('楼主'); } }); } if ( /(gene|trade|topic)\//.test(window.location.href) & !/comment/.test(window.location.href) ) { // 获取楼主ID const authorId = $('.title2').text(); addOPBadge(authorId); } /* * 功能:对关注用户进行ID高亮功能函数 */ const addHighlightOnID = () => { settings.highlightSpecificID.map((i, n) => { $(`.meta>[href="${window.location.href.match('(.*)\\.com')[0]}/psnid/${i}"]`).css({ 'background-color': settings.highlightSpecificBack, color: settings.highlightSpecificFront, }); }); } addHighlightOnID(); // 功能1-3:主题中存在 -插图- 一项时,提供预览悬浮窗 $("a[target='_blank']").html((i, url) => { if (url == ' -插图- ') { const xOffset = 5; const yOffset = 5; const imgUrl = $(this).attr('href'); $(this).hover( (e) => { $('body').append( $( `` ) ); $('#hoverImage') .css({ position: 'absolute', border: '1px solid #ccc', display: 'none', padding: '5px', background: '#333', }) .css('top', e.pageY - xOffset + 'px') .css('left', e.pageX + yOffset + 'px') .fadeIn(500); }, () => { $('#hoverImage').remove(); } ); $(this).mousemove((e) => { $('#hoverImage') .css('top', e.pageY - xOffset + 'px') .css('left', e.pageX + yOffset + 'px'); }); } }); /* * 功能:回复内容回溯,仅支持机因、主题 * @param isOn 是否开启功能 */ const showReplyContent = (isOn) => { if (isOn) { GM_addStyle( `.replyTraceback { background-color: rgb(0, 0, 0, 0.05) !important; padding: 10px !important; color: rgb(160, 160, 160, 1) !important; border-bottom: 1px solid !important; }` ); // 悬浮框内容左对齐样式 GM_addStyle(` .tippy-content { text-align: left; }` ); // 每一层楼的回复框 const allSource = $('.post .ml64 > .content'); // 每一层楼的回复者用户名 const userId = $('.post > .ml64 > [class$=meta]'); // 每一层的头像 const avator = $('.post > a.l'); for (let floor = allSource.length - 1; floor > 0; floor--) { // 层内内容里包含链接(B的发言中是否有A) const content = allSource.eq(floor).find('a'); if (content.length > 0) { for (let userNum = 0; userNum < content.length; userNum++) { // 对每一个链接的文本内容判断 const linkContent = content.eq(userNum).text().match('@(.+)'); // 链接里是@用户生成的链接, linkContent为用户名(B的发言中有A) if (linkContent !== null) { // 从本层的上一层开始,回溯所@的用户的最近回复(找最近的一条A的发言) let traceIdFirst = -1; let traceIdTrue = -1; for (let traceId = floor - 1; traceId >= 0; traceId--) { // 如果回溯到了的话,选取内容 // 回溯层用户名 const thisUserID = userId.eq(traceId).find('.psnnode:eq(0)').text(); if (thisUserID.toLowerCase() === linkContent[1].toLowerCase()) { // 判断回溯中的@(A的发言中有是否有B) if ( allSource.eq(traceId).text() === userId.eq(floor).find('.psnnode:eq(0)').text() ) { traceIdTrue = traceId; break; } else if (traceIdFirst == -1) { traceIdFirst = traceId; } } } let outputID = -1; if (traceIdTrue !== -1) { outputID = traceIdTrue; } else if (traceIdFirst != -1) { outputID = traceIdFirst; } // 输出 if (outputID !== -1) { const replyContentsText = allSource.eq(outputID).text(); const replyContents = replyContentsText.length > 45 ? `${replyContentsText.substring(0, 45)}......` : replyContentsText; const avatorImg = avator.eq(outputID).find('img:eq(0)').attr('src'); allSource.eq(floor).before(`
    ${linkContent[1]} ${replyContents}
    `); // 如果内容超过45个字符,则增加悬浮显示全文内容功能 replyContentsText.length > 45 ? tippy(`.responserContent_${floor}_${outputID}`, { content: replyContentsText, animateFill: false, maxWidth: '500px', }) : null; } } } } } } } /* * 功能:增加帖子楼层信息 */ const addFloorIndex = () => { let baseFloorIndex = 0; let subFloorIndex = -1; $('span[class^=r]').map((i, el) => { if (i > 0) { if ($(el).attr('class') === 'r') { $(el).children('a:last') .after(`  #${++baseFloorIndex}`); subFloorIndex = -1; } else { $(el).children('a:last') .after( `  #${baseFloorIndex}${subFloorIndex--}` ); } } }); } /* * 功能:层内逆序显示 * @param isOn 是否开启该功能 */ const reverseSubReply = (isOn) => { $('div.btn.btn-white.font12').click(); const blocks = $('div.sonlistmark.ml64.mt10:not([style="display:none;"])'); blocks.map((index, block) => { const reversedBlock = $($(block).find('li').get().reverse()); $(block).find('.sonlist').remove(); $(block).append('