【自用】雪球

链接当前页面打开

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

  1. // ==UserScript==
  2. // @name 【自用】雪球
  3. // @match https://xueqiu.com/*
  4. // @version 2021.09.03
  5. // @author heckles
  6. // @description 链接当前页面打开
  7. // @icon https://github.com/favicon.ico
  8. // @homepage https://greasyfork.org/zh-CN/scripts/431835-%E8%87%AA%E7%94%A8-%E9%9B%AA%E7%90%83
  9. // @namespace https://greasyfork.org/users/24050
  10. // ==/UserScript==
  11.  
  12. const cssframe = `
  13. right: 0px;
  14. top: -1px;
  15. position: fixed;
  16. width: 68%;
  17. background-color:#fff;
  18. z-index:999999;
  19. `
  20.  
  21. const cssnewsfbg = `
  22. top: 0px;
  23. left: 0px;
  24. position: fixed;
  25. width: 100%;
  26. background-color:rgba(0,0,0,0.8);
  27. z-index:0;
  28. `
  29.  
  30. var newsframe = document.createElement("iframe");
  31. newsframe.name = "newsframeName";
  32. newsframe.id = "newss";
  33. newsframe.setAttribute("frameborder", "no");
  34. var newsfbg = document.createElement("div");
  35. newsfbg.id = "newsfbg";
  36. document.body.appendChild(newsfbg);
  37. newsfbg.appendChild(newsframe);
  38. if (window.location.href.indexOf("xueqiu.com/S") < 0) {
  39. var WaitXXX = setInterval(function () { //间隔执行
  40. if (document.querySelector("td .name")) {
  41. clearInterval(WaitXXX);
  42. StartJsIndex();
  43. }
  44. }, 1000); //间隔时间,毫秒
  45. }else{
  46. StartJsGp();
  47. }
  48.  
  49. function StartJsIndex() {
  50. console.log("首页");
  51.  
  52. var container = document.querySelector(".user__container"); //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  53. var dir_links1 = "td .name"; //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  54. var dir_links2 = ".home__stock-index__item"; //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  55. var dir_links3 = "div.stock-hot__container.board table.stock-hot__list.board__list tr td a";
  56. var dir_links4 = "div.today-topic__list li a";
  57. var anchors1 = document.querySelectorAll(dir_links1);// + document.querySelectorAll(dir_links2);直接加不起作用
  58. var anchors2 = document.querySelectorAll(dir_links2);
  59. var anchors3 = document.querySelectorAll(dir_links3);
  60. var anchors4 = document.querySelectorAll(dir_links4);
  61. for (var i = 0; i < anchors1.length; i++) {
  62. //anchors[i].target = "newsframeName";
  63. anchors1[i].onclick = function () {
  64. zkgp(this);
  65. return false;
  66. }; //添加函数
  67. }
  68. for (var i = 0; i < anchors2.length; i++) {
  69. //anchors[i].target = "newsframeName";
  70. anchors2[i].onclick = function () {
  71. zkgp(this);
  72. return false;
  73. }; //添加函数
  74. }
  75. for (var i = 0; i < anchors3.length; i++) {
  76. //anchors[i].target = "newsframeName";
  77. anchors3[i].onclick = function () {
  78. zkgp(this);
  79. return false;
  80. }; //添加函数
  81. }
  82. for (var i = 0; i < anchors4.length; i++) {
  83. //anchors[i].target = "newsframeName";
  84. anchors4[i].onclick = function () {
  85. zkgp(this);
  86. return false;
  87. }; //添加函数
  88. }
  89. var zkgp = function (a) {
  90. newsframe.setAttribute("src", a.getAttribute("href"));
  91. container.style.marginLeft = "0%";
  92. newsframe.style.cssText = cssframe + "height:100%;";
  93. newsfbg.style.cssText = cssnewsfbg + "height:100%;";
  94. newsfbg.style.zIndex = "999";
  95.  
  96. newsfbg.onclick = function () {
  97. newsfbg.style.width = "0px";
  98. newsframe.style.width = "0px";
  99. container.style.marginLeft = "auto";
  100. newsframe.setAttribute("src", "");
  101. }
  102. }
  103. }
  104.  
  105. function StartJsGp(){
  106. console.log("详情");
  107. var article = document.querySelector(".container.article__container");//这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  108. var articleBTN = document.querySelector(".status-link");
  109. //articleBTN.target = "newsframeName";
  110.  
  111. articleBTN.onclick = function () {
  112. zkwl(this);
  113. return false;
  114. }; //添加函数;
  115. var zkwl = function (a) {
  116. newsframe.setAttribute("src", a.getAttribute("href"));
  117. article.style.marginLeft = "10%";
  118. newsframe.style.cssText = cssframe + "height:100%;";
  119. newsfbg.style.cssText = cssnewsfbg + "height:100%;";
  120. newsfbg.style.zIndex = "999";
  121.  
  122. newsfbg.onclick = function () {
  123. newsfbg.style.width = "0px";
  124. newsframe.style.width = "0px";
  125. article.style.marginLeft = "auto";
  126. newsframe.setAttribute("src", "");
  127. }
  128. }
  129. }