// ==UserScript== // @name PSN中文网功能增强 // @namespace https://swsoyee.github.io // @version 0.21 // @description PSN中文网的数折价格可视化,奖杯统计,楼主高亮,增加被@用户的留言内容等 // @author InfinityLoop // @match *psnine.com/* // @match *d7vg.com/* // @require http://cdn.staticfile.org/jquery/2.1.4/jquery.min.js // @require http://code.highcharts.com/highcharts.js // @grant GM_addStyle // @downloadURL none // ==/UserScript== (function() { 'use strict'; // 高亮发帖楼主 GM_addStyle (`.highlightAuthor {background-color: #3890ff !important;}`) if( /(gene|trade|topic)\//.test(window.location.href)) { var author = document.querySelector("a.title2").textContent var responsed = document.querySelectorAll("a.psnnode") for (var index = 0; index < responsed.length; index++) { if(responsed[index].innerText == author) { responsed[index].className += " highlightAuthor" } } } // 回复内容回溯 (效率原因只返回所@用户的最近一条回复) GM_addStyle (`.replyTraceback {background-color: rgb(0, 0, 0, 0.1) !important; padding: 10px !important; color: #999 !important; border: 1px solid !important;}`) // 匹配@的字符串 var reg = /@(.+?)\s/g // 每一层楼的回复外框 (1 ~ N + 1) var allSourceOutside = document.getElementsByClassName("ml64") // 每一层楼的回复框(1 ~ N+1) floor var allSource = document.getElementsByClassName("content pb10") // 每一层楼的回复者名字(2 ~ N+2) traceId var userId = document.getElementsByClassName("meta") // 没tag的帖子会少一层meta,所以要对meta[0]做处理 var numberOffset = 0 if( userId[0].getElementsByClassName("node").length > 0) { numberOffset = 2 } else { numberOffset = 1 } for(var floor = 1; floor < allSource.length; floor++ ) { // 层内内容里包含链接 var content = allSource[floor].querySelectorAll("a") if(content.length > 0) { for(var userNum = 0; userNum < content.length; userNum++ ){ // 对每一个链接的文本内容判断 var linkContent = content[userNum].innerText.match("@(.+)") // 链接里是@用户生成的链接, linkContent为用户名 if(linkContent != null) { var replayBox = document.createElement("div") replayBox.setAttribute("class", "replyTraceback") // 层主ID var floorUserId = userId[floor + numberOffset].getElementsByClassName("psnnode")[0].innerText // 从本层开始,回溯所@的用户的最近回复 for(var traceId = floor + 1; traceId > 1; traceId-- ){ // 如果回溯到了的话,选取内容 // 本层用户名 // console.log("?") var thisUserID = userId[traceId].getElementsByClassName("psnnode")[0].innerText // console.log(thisUserID) if( thisUserID == linkContent[1]){ // console.log("---") // console.log("回溯到的发言者" + linkContent[1]) // console.log("回溯到的发言内容" + allSource[traceId - numberOffset].innerText) // console.log("层主发言内容里的ID" + thisUserID) // console.log("层主ID" + floorUserId) replayBox.innerHTML = allSource[traceId - numberOffset].innerText + " ------ " + linkContent[1] allSourceOutside[floor].insertBefore(replayBox, allSource[floor]) break; } } } } } } // 商城价格走势图 if( /dd/.test(window.location.href) ) { // 日期转换函数 function converntTime(value) { var timeArray = value.replace('年','-').replace('月','-').replace('日','').split("-") timeArray[0] = "20" + timeArray[0] timeArray[1] = Number(timeArray[1]) - 1 return Date.UTC(timeArray[0], timeArray[1], timeArray[2]) } // 获取X轴的日期 var xContents = document.querySelectorAll("p.dd_text") var xValue = []; var today = new Date() var todayArray = Date.UTC(today.getYear() + 1900, today.getMonth(), today.getDate()) for(var xindex = 3; xindex < xContents.length; xindex+=4 ){ var tamp = xContents[xindex].innerText.split(" ~ ") tamp[0] = converntTime(tamp[0]) tamp[1] = converntTime(tamp[1]) xValue = [tamp[0], tamp[0], tamp[1], tamp[1]].concat(xValue) } //获取价格 var y = document.querySelectorAll(".dd_price") var yValueNormal = []; var yValuePlus = []; for(var yindex = 0; yindex < y.length; yindex++ ){ var yPriceOld = y[yindex].querySelector(".dd_price_old").innerText var yPriceNormal = y[yindex].querySelector(".dd_price_off").innerText var yPricePlus = y[yindex].querySelector(".dd_price_plus") yValueNormal = [yPriceOld, yPriceNormal, yPriceNormal, yPriceOld].concat(yValueNormal) var pricePlusTamp = "" if( yPricePlus == null ){ pricePlusTamp = yPriceNormal } else { pricePlusTamp = yPricePlus.innerText } yValuePlus = [yPriceOld, pricePlusTamp, pricePlusTamp, yPriceOld].concat(yValuePlus) } // 普通价格数据 var xForPlotNormal = new Array() var xForPlotPlus = new Array() // 判断地区 var replaceString = "" if( yValueNormal[0].search("HK\\$") > -1 ){ replaceString = "HK$" } else if( yValueNormal[0].search("\\$") > -1 ){ replaceString = "$" } else if( yValueNormal[0].search("\\£") > -1 ){ replaceString = "£" } else { replaceString = "¥" } for(var i = 0; i < xValue.length; i++ ){ xForPlotNormal[i] = [xValue[i], Number(yValueNormal[i].replace(replaceString, ""))] xForPlotPlus[i] = [xValue[i], Number(yValuePlus[i].replace(replaceString, ""))] } // 修正最后一组数据 if( xForPlotNormal[xForPlotNormal.length - 1][0] > todayArray ){ xForPlotNormal.pop() xForPlotPlus.pop() xForPlotNormal[xForPlotNormal.length - 1][0] = todayArray xForPlotPlus[xForPlotPlus.length - 1][0] = todayArray } else { xForPlotNormal.push([todayArray, xForPlotNormal[xForPlotNormal.length - 1][1]]) xForPlotPlus.push([todayArray, xForPlotPlus[xForPlotPlus.length - 1][1]]) } // 插入页面 $(".pd10").append (`
`); var chart = { type: 'areaspline', backgroundColor: 'rgba(0,0,0,0)' }; var title = { text: '价格变动走势图', style: { color: '#808080' } }; var xAxis = { type: 'datetime', dateTimeLabelFormats: { day: '%e. %b', month: '%b \'%y', year: '%Y' }, title: { text: 'Date' } }; var yAxis = { title: { text: '价格' }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }; var tooltip = { headerFormat: '{series.name}