【自用】雪球

链接当前页面打开

目前为 2021-09-13 提交的版本。查看 最新版本

// ==UserScript==
// @name        【自用】雪球
// @match       https://xueqiu.com/*
// @version     2021.09.13
// @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;
}
`

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);

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-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 () { //间隔执行
        if (document.querySelector("td .name")) {
            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("button");
            abr.style.cssText = "margin:2px 0px 2px 12px;width:70px;height:28px;z-index:99999999;font-size:14px;border:0px;background:transparent;color:#fff;";
            abr.innerHTML = "切换布局";
    document.querySelector("div.signed_container div.nav__lf").appendChild(abr);
    abr.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;
    };
    abr.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";
        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);
        //var anchors5 = document.getElementsByClassName("status-link");

        for (var i = 0; i < anchors1.length; i++) {
            //anchors[i].target = "newsframeName";
            anchors1[i].onclick = function () {
                zkgp(this);
                return false;
            }; //添加函数
        }
        for (var i = 0; i < anchors2.length; i++) {
            anchors2[i].onclick = function () {
                zkgp(this);
                return false;
            }; //添加函数
        }
        for (var i = 0; i < anchors3.length; i++) {
            anchors3[i].onclick = function () {
                zkgp(this);
                return false;
            }; //添加函数
        }
        for (var i = 0; i < anchors4.length; i++) {
            anchors4[i].onclick = function () {
                zkgp(this);
                return false;
            }; //添加函数
        }
        for (var i = 0; i < anchors5.length; i++) {
            anchors5[i].onclick = function () {
                zkgp(this);
                return false;
            }; //添加函数
        }

        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(); //运行一遍

    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", "");
        }
    }

}