// ==UserScript==
// @name 【自用】雪球
// @match https://xueqiu.com/*
// @version 2021.09.16
// @author heckles
// @description 链接当前页面打开
// @icon https://github.com/favicon.ico
// @homepage https://greasyfork.org/zh-CN/scripts/431835-%E8%87%AA%E7%94%A8-%E9%9B%AA%E7%90%83
// @namespace https://greasyfork.org/users/24050
// ==/UserScript==
const cusCSS = `
/*减淡其他信息*/
.optional__tb {
color:rgba(0,0,0,0.4) !important;
}
/*自选股名称加粗*/
td a.name {
color:rgba(0,0,0,0.65);
font-weight: bold !important;
}
`
const btnanmi =`
/*隐藏复选框元素,使用label标签元素进行切换*/
input[type="checkbox"] {
width: 0;
height: 0;
visibility: hidden;
}
/*创建开关的主体,可移动球块以外的部分*/
label#switchX {
display:inline-block;
width: 38px;
height: 21px;
background-color: rgba(0,0,0,0.2);
border-radius: 12px;
position: relative;
cursor: pointer;
transition: 0.1s;
box-shadow: 0 0 2px #477a8550;
}
/*创建切换球*/
label#switchX::after {
content: "";
width: 11px;
height: 11px;
background-color: rgba(255,255,255,0.6);
position: absolute;
border-radius: 6px;
top: 5px;
left: 5px;
transition: 0.2s;
}
/*当复选框被选中时,球应向右移动*/
input:checked + label#switchX:after {
left: calc(100% - 5px);
transform: translateX(-100%);
background-color: rgba(255,255,255,0.95);
}
/*改变按钮切换时的背景*/
input:checked + label#switchX {
background-color: rgba(0,0,0,0.3);
}
/*磁性效果,就是暂时拉伸,按住鼠标就发现了*/
label#switchX:active:after {
width: 11px;
}
`
function addNewStyle(newStyle) { //增加新样式表
var styleElement = document.getElementById('styles_js');
if (!styleElement) {
styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.id = 'styles_js';
document.getElementsByTagName('head')[0].appendChild(styleElement);
}
styleElement.appendChild(document.createTextNode(newStyle));
}
addNewStyle(cusCSS);
addNewStyle(btnanmi);
const cssframe = `
right: 0px;
top: -1px;
position: fixed;
width: 68%;
background-color:#fff;
z-index:999999;
`
const cssnewsfbg = `
top: 0px;
left: 0px;
position: fixed;
width: 100%;
background-color:rgba(0,0,0,0.8);
z-index:0;
`
var newsframe = document.createElement("iframe");
newsframe.name = "newsframeName";
newsframe.id = "newss";
newsframe.setAttribute("frameborder", "no");
//newsframe.setAttribute("security","restricted");//加这两条,避免被引用页的强制跳转
newsframe.setAttribute("sandbox","allow-same-origin allow-scripts");//加这两条,避免被引用页的强制跳转,允许脚本,但不允许allow-top-navigation,https://xueqiu.com/S/00700/197439434 https://xueqiu.com/S/SZ002594/197460952
newsframe.style.height = "0";
var newsfbg = document.createElement("div");
newsfbg.id = "newsfbg";
newsfbg.style.height = "0";
document.body.appendChild(newsfbg);
newsfbg.appendChild(newsframe);
if (window.location.href.indexOf("xueqiu.com/S") < 0) {
var WaitXXX = setInterval(function () { //间隔执行
console.log("1");
if (document.querySelector("td .name") && document.querySelector("div.today-topic__container.board")) {
console.log("2");
clearInterval(WaitXXX);
StartJsIndex();
//dvdelne();
markL();
layout();
}
}, 1000); //间隔时间,毫秒
} else {
StartJsGp();
}
function layout() {
//var targ = document.querySelector("a[innerHTML='发帖']"); //没法用innerHTML的内容来queryselect,因为目标元素的所有父元素都包含这个内容
//var targ = document.querySelector(".nav__btn--longtext a[href='javascript:;']"); //这样倒是可以
var abr = document.createElement("span");
abr.style.cssText = "margin-left:10px;margin-top:5px;display:inline-block;";
abr.innerHTML = "\<input type=\"checkbox\" name=\"switch\" id=\"switch\"\>\<label id=\"switchX\" for=\"switch\"\>\<\/label\>";
document.querySelector("div.signed_container div.nav__lf").appendChild(abr);
abr.querySelector("#switch").onclick = function () {
var xx = document.querySelector("div.home__col--rt ul.home__business").style.display;
switch (xx) {
case "block":
xx = "none";
break;
case "none":
xx = "block";
break;
default:
xx = "none";
}
console.log(xx);
document.querySelector("div.home__col--rt ul.home__business").style.display = xx;
document.querySelector("div.home__col--rt div.info-report-wrap").style.display = xx;
if(xx = "block"){document.querySelector(".today-topic__container.board").style.marginTop = "0";}
if(xx = "none"){document.querySelector(".today-topic__container.board").style.marginTop = "-15px";}
}
abr.querySelector("#switch").click(); //模拟点击一下
//document.querySelector("div#snb_im i.iconfont.im__expand").click();//模拟点击一下,隐藏聊天
}
function dvdelne() {
var zichiRowtd = document.querySelector("a[href='/S/SZ159967']").parentNode.parentNode.querySelectorAll("td"); //.previousSibling .nextSibling
var zhishuRowtd = document.querySelector("a[href='/S/SH000016']").parentNode.parentNode.querySelectorAll("td");
for (var i = 0; i < zichiRowtd.length; i++) {
zichiRowtd[i].style.borderTop = "2px solid rgba(19, 105, 191, 0.8)"; //querySelectorAll选一群,然后一起设置style不行
}
for (var i = 0; i < zhishuRowtd.length; i++) {
zhishuRowtd[i].style.borderTop = "2px solid rgba(19, 105, 191, 0.8)"; //querySelectorAll选一群,然后一起设置style不行
}
}
function markL() {
document.querySelector("a[href='/S/SZ159967']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SZ159949']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SZ159915']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SH512170']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SH588000']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SH512290']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SH515030']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SH513050']").parentNode.setAttribute("class", "zczq");
document.querySelector("a[href='/S/SH510500']").parentNode.setAttribute("class", "zczq");
addNewStyle("td.zczq{border-left:2px solid rgba(19, 105, 191, 0.8);}");
}
function StartJsIndex() {
console.log("首页");
//替换链接
var getel = function () {
container = document.querySelector(".user__container"); //这里的规则需要按网站修改
dir_links1 = "td .name"; //股票列表里的名称
dir_links2 = ".home__stock-index__item"; //最上面的股指
dir_links3 = "div.stock-hot__container.board table.stock-hot__list.board__list tr td a";//热门话题
dir_links4 = "div.today-topic__list li a";//今日话题
dir_links5 = ".status-link";//网页链接
dir_links6 = ".timeline__expand__control";//展开
anchors1 = document.querySelectorAll(dir_links1); // + document.querySelectorAll(dir_links2);直接加不起作用
anchors2 = document.querySelectorAll(dir_links2);
anchors3 = document.querySelectorAll(dir_links3);
anchors4 = document.querySelectorAll(dir_links4);
anchors5 = document.querySelectorAll(dir_links5);
anchors6 = document.querySelectorAll(dir_links6);
//var anchors5 = document.getElementsByClassName("status-link");
for (var i = 0; i < anchors1.length; i++) {
//anchors[i].target = "newsframeName";
anchors1[i].title="当前页面打开";
anchors1[i].onclick = function () {
zkgp(this);
return false;
}; //添加函数
}
for (var i = 0; i < anchors2.length; i++) {
anchors2[i].title="当前页面打开";
anchors2[i].onclick = function () {
zkgp(this);
return false;
}; //添加函数
}
for (var i = 0; i < anchors3.length; i++) {
anchors3[i].title="当前页面打开";
anchors3[i].onclick = function () {
zkgp(this);
return false;
}; //添加函数
}
for (var i = 0; i < anchors4.length; i++) {
anchors4[i].title="当前页面打开";
anchors4[i].onclick = function () {
zkgp(this);
return false;
}; //添加函数
}
for (var i = 0; i < anchors5.length; i++) {
anchors5[i].title="当前页面打开";
anchors5[i].onclick = function () {
zkgp(this);
return false;
}; //添加函数
}
for (var i = 0; i < anchors6.length; i++) {
anchors6[i].title="已执行";
anchors6[i].onclick = function (){
//setTimeout(function () {
var xxt = this.parentNode.parentNode.querySelector(".status-link");
xxt.title="当前页面打开";
xxt.onclick = function(){//不能直接onclick=zkgp
zkgp(xxt);
return false;
}
//},1*1000); //等1秒钟之后执行
} //添加函数
}
var zkgp = function (a) {
newsframe.setAttribute("src", a.getAttribute("href"));
container.style.marginLeft = "0%";
newsframe.style.cssText = cssframe + "height:100%;";
newsfbg.style.cssText = cssnewsfbg + "height:100%;";
newsfbg.style.zIndex = "999";
var opnlk = document.createElement("a");
opnlk.style.cssText = "position:fixed;top:55px;right:30px;margin:2px 0px 2px 12px;width:70px;height:28px;z-index:99999999;font-size:13px;border:0px;background:transparent;color:#333;";
opnlk.innerHTML = "新页面打开";
opnlk.href = a.getAttribute("href");
opnlk.target = "_blank";
document.body.appendChild(opnlk);
newsfbg.onclick = function () {
newsfbg.style.width = "0px";
newsframe.style.width = "0px";
container.style.marginLeft = "auto";
newsframe.setAttribute("src", "");
opnlk.innerHTML = "";
}
}
}
getel(); //运行一遍
var unread = document.querySelector("a.home-timeline__unread");//加载【未读】后运行一遍
var readmore = document.querySelector("a.home__timeline__more");//加载【更多】后运行一遍
readmore.onclick = unread.onclick = function(){
setTimeout(function(){
getel();
},1*1000); //等1秒钟之后执行
}
window.onscroll = function () { //兼容写法 //只要滚动,就开始
var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; //滚动的数值,取首个为真的
var clientHeight = document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight;
//console.log(document.documentElement.offsetHeight - 194, clientHeight, scrollTop);
if (scrollTop >= (document.documentElement.offsetHeight - 194) - clientHeight) { // body的滚动高度>=html总高度-可视化窗口高度
setTimeout(function () {
getel();
}, 1 * 1000); //等1秒钟之后执行
}
}
}
function StartJsGp() {
console.log("详情");
var article = document.querySelector(".container.article__container"); //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
var articleBTN = document.querySelector(".status-link");
//articleBTN.target = "newsframeName";
articleBTN.onclick = function () {
zkwl(this);
return false;
}; //添加函数;
var zkwl = function (a) {
newsframe.setAttribute("src", a.getAttribute("href"));
article.style.marginLeft = "10%";
newsframe.style.cssText = cssframe + "height:100%;";
newsfbg.style.cssText = cssnewsfbg + "height:100%;";
newsfbg.style.zIndex = "999";
newsfbg.onclick = function () {
newsfbg.style.width = "0px";
newsframe.style.width = "0px";
article.style.marginLeft = "auto";
newsframe.setAttribute("src", "");
}
}
}