【自用】雪球

链接当前页面打开

目前為 2021-09-03 提交的版本,檢視 最新版本

// ==UserScript==
// @name        【自用】雪球
// @match       https://xueqiu.com/*
// @version     2021.09.01
// @author      heckles
// @description 链接当前页面打开
// @icon        https://github.com/favicon.ico
// @namespace https://greasyfork.org/users/24050
// ==/UserScript==

  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");
    var newsfbg = document.createElement("div");
        newsfbg.id = "newsfbg";
    
    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();
    }
}, 1000); //间隔时间,毫秒
}else{
  StartJsGp();
}

function StartJsIndex() {
    console.log("首页");

    var container = document.querySelector(".user__container"); //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
    var dir_links1 = "td .name";                                //这里的规则需要按网站修改    ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
    var dir_links2 = ".home__stock-index__item";                 //这里的规则需要按网站修改    ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
    var dir_links3 = "div.stock-hot__container.board table.stock-hot__list.board__list tr td a";
    var dir_links4 = "div.today-topic__list li a";
    var anchors1 = document.querySelectorAll(dir_links1);// + document.querySelectorAll(dir_links2);直接加不起作用
    var anchors2 = document.querySelectorAll(dir_links2);
    var anchors3 = document.querySelectorAll(dir_links3);
    var anchors4 = document.querySelectorAll(dir_links4);
  
    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++) {
        //anchors[i].target = "newsframeName";
        anchors2[i].onclick = function () {
            zkgp(this);
            return false;
        }; //添加函数
    }
    for (var i = 0; i < anchors3.length; i++) {
        //anchors[i].target = "newsframeName";
        anchors3[i].onclick = function () {
            zkgp(this);
            return false;
        }; //添加函数
    }
    for (var i = 0; i < anchors4.length; i++) {
        //anchors[i].target = "newsframeName";
        anchors4[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";

    newsfbg.onclick = function () {
        newsfbg.style.width = "0px";
        newsframe.style.width = "0px";
        container.style.marginLeft = "auto";
        newsframe.setAttribute("src", "");
        }
    }
}

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