// ==UserScript==
// @name 【自用】雪球
// @match https://xueqiu.com/*
// @version 2021.10.29
// @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
// @downloadURL https://update.greasyfork.icu/scripts/431835/%E3%80%90%E8%87%AA%E7%94%A8%E3%80%91%E9%9B%AA%E7%90%83.user.js
// @updateURL https://update.greasyfork.icu/scripts/431835/%E3%80%90%E8%87%AA%E7%94%A8%E3%80%91%E9%9B%AA%E7%90%83.meta.js
// ==/UserScript==
//1.1定义添加临时css的函数
function addStyle_imp(newStyle) { //增加新样式表【固定的】
var styleElement = document.getElementById('imp');
if (!styleElement) {
styleElement = document.createElement('style');
styleElement.type = 'text/css';
styleElement.id = 'imp';
document.getElementsByTagName('head')[0].appendChild(styleElement);
}
styleElement.appendChild(document.createTextNode(newStyle));
}
//1.2.1设置固定的css
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;
}
.nav.stickyFixed.nav__dynamic{
background: #1369bf !important;
}
`
const btnanmi =`
/*隐藏复选框元素,使用label标签元素进行切换*/
#switch_ads,
#switch_imp{
width: 0;
height: 0;
visibility: hidden;
}
/*创建开关的主体,可移动球块以外的部分*/
label.switchX {
display:inline-block;
vertical-align: middle;
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;
}
`
//1.2.2添加持续生效的css
function addPermernantStyle(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));
}
addPermernantStyle(cusCSS);
addPermernantStyle(btnanmi);
//1.3.3设置用于当前页面显示的iframe及配套bg
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;
`
//创建iframe
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);
//2开始执行了【判断目标元素已经加载】
if (window.location.href.indexOf("xueqiu.com/S") < 0) {
var Waitforindex = setInterval(function () { //间隔执行
console.log("间隔1秒尝试");
if (document.querySelector("td .name") && document.querySelector("div.today-topic__container.board")) {
console.log("开始执行各函数");
clearInterval(Waitforindex);
StartJsIndex();
//dvdelne();
StartmarkL();
layout();
}
}, 1000); //间隔时间,毫秒
} else {
StartJsGp();
}
//2.1定义按钮(用于切换布局,隐藏/显示垃圾信息)
function layout() {
//var targ = document.querySelector("a[innerHTML='发帖']"); //没法用innerHTML的内容来queryselect,因为目标元素的所有父元素都包含这个内容
//var targ = document.querySelector(".nav__btn--longtext a[href='javascript:;']"); //这样倒是可以
var adremove = document.createElement("span");
adremove.style.cssText = "margin-left:10px;display:inline-block;";
adremove.innerHTML = "\\