【自用】雪球

链接当前页面打开

  1. // ==UserScript==
  2. // @name 【自用】雪球
  3. // @match https://xueqiu.com/*
  4. // @version 2021.10.29
  5. // @author heckles
  6. // @description 链接当前页面打开
  7. // @icon https://github.com/favicon.ico
  8. // @homepage https://gf.qytechs.cn/zh-CN/scripts/431835-%E8%87%AA%E7%94%A8-%E9%9B%AA%E7%90%83
  9. // @namespace https://gf.qytechs.cn/users/24050
  10. // ==/UserScript==
  11.  
  12.  
  13. //1.1定义添加临时css的函数
  14. function addStyle_imp(newStyle) { //增加新样式表【固定的】
  15. var styleElement = document.getElementById('imp');
  16. if (!styleElement) {
  17. styleElement = document.createElement('style');
  18. styleElement.type = 'text/css';
  19. styleElement.id = 'imp';
  20. document.getElementsByTagName('head')[0].appendChild(styleElement);
  21. }
  22. styleElement.appendChild(document.createTextNode(newStyle));
  23. }
  24.  
  25.  
  26. //1.2.1设置固定的css
  27. const cusCSS = `
  28. /*减淡其他信息*/
  29. .optional__tb {
  30. color:rgba(0,0,0,0.4) !important;
  31. }
  32. /*自选股名称加粗*/
  33. td a.name {
  34. color:rgba(0,0,0,0.65);
  35. font-weight: bold !important;
  36. }
  37. .nav.stickyFixed.nav__dynamic{
  38. background: #1369bf !important;
  39. }
  40.  
  41. `
  42. const btnanmi =`
  43. /*隐藏复选框元素,使用label标签元素进行切换*/
  44. #switch_ads,
  45. #switch_imp{
  46. width: 0;
  47. height: 0;
  48. visibility: hidden;
  49. }
  50. /*创建开关的主体,可移动球块以外的部分*/
  51. label.switchX {
  52. display:inline-block;
  53. vertical-align: middle;
  54. width: 38px;
  55. height: 21px;
  56. background-color: rgba(0,0,0,0.2);
  57. border-radius: 12px;
  58. position: relative;
  59. cursor: pointer;
  60. transition: 0.1s;
  61. box-shadow: 0 0 2px #477a8550;
  62. }
  63. /*创建切换球*/
  64. label.switchX::after {
  65. content: "";
  66. width: 11px;
  67. height: 11px;
  68. background-color: rgba(255,255,255,0.6);
  69. position: absolute;
  70. border-radius: 6px;
  71. top: 5px;
  72. left: 5px;
  73. transition: 0.2s;
  74. }
  75. /*当复选框被选中时,球应向右移动*/
  76. input:checked + label.switchX:after {
  77. left: calc(100% - 5px);
  78. transform: translateX(-100%);
  79. background-color: rgba(255,255,255,0.95);
  80. }
  81. /*改变按钮切换时的背景*/
  82. input:checked + label.switchX {
  83. background-color: rgba(0,0,0,0.3);
  84. }
  85. /*磁性效果,就是暂时拉伸,按住鼠标就发现了*/
  86. label.switchX:active:after {
  87. width: 11px;
  88. }
  89. `
  90. //1.2.2添加持续生效的css
  91. function addPermernantStyle(newStyle) { //增加新样式表【固定的】
  92. var styleElement = document.getElementById('styles_js');
  93. if (!styleElement) {
  94. styleElement = document.createElement('style');
  95. styleElement.type = 'text/css';
  96. styleElement.id = 'styles_js';
  97. document.getElementsByTagName('head')[0].appendChild(styleElement);
  98. }
  99. styleElement.appendChild(document.createTextNode(newStyle));
  100. }
  101. addPermernantStyle(cusCSS);
  102. addPermernantStyle(btnanmi);
  103.  
  104. //1.3.3设置用于当前页面显示的iframe及配套bg
  105. const cssframe = `
  106. right: 0px;
  107. top: -1px;
  108. position: fixed;
  109. width: 68%;
  110. background-color:#fff;
  111. z-index:999999;
  112. `
  113. const cssnewsfbg = `
  114. top: 0px;
  115. left: 0px;
  116. position: fixed;
  117. width: 100%;
  118. background-color:rgba(0,0,0,0.8);
  119. z-index:0;
  120. `
  121.  
  122.  
  123. //创建iframe
  124. var newsframe = document.createElement("iframe");
  125. newsframe.name = "newsframeName";
  126. newsframe.id = "newss";
  127. newsframe.setAttribute("frameborder", "no");
  128. //newsframe.setAttribute("security","restricted");//加这两条,避免被引用页的强制跳转
  129. newsframe.setAttribute("sandbox","allow-same-origin allow-scripts");//加这两条,避免被引用页的强制跳转,允许脚本,但不允许allow-top-navigation,https://xueqiu.com/S/00700/197439434 https://xueqiu.com/S/SZ002594/197460952
  130. newsframe.style.height = "0";
  131. var newsfbg = document.createElement("div");
  132. newsfbg.id = "newsfbg";
  133. newsfbg.style.height = "0";
  134.  
  135. document.body.appendChild(newsfbg);
  136. newsfbg.appendChild(newsframe);
  137.  
  138. //2开始执行了【判断目标元素已经加载】
  139. if (window.location.href.indexOf("xueqiu.com/S") < 0) {
  140. var Waitforindex = setInterval(function () { //间隔执行
  141. console.log("间隔1秒尝试");
  142. if (document.querySelector("td .name") && document.querySelector("div.today-topic__container.board")) {
  143. console.log("开始执行各函数");
  144. clearInterval(Waitforindex);
  145. StartJsIndex();
  146. //dvdelne();
  147. StartmarkL();
  148. layout();
  149. }
  150. }, 1000); //间隔时间,毫秒
  151. } else {
  152. StartJsGp();
  153. }
  154. //2.1定义按钮(用于切换布局,隐藏/显示垃圾信息)
  155. function layout() {
  156. //var targ = document.querySelector("a[innerHTML='发帖']"); //没法用innerHTML的内容来queryselect,因为目标元素的所有父元素都包含这个内容
  157. //var targ = document.querySelector(".nav__btn--longtext a[href='javascript:;']"); //这样倒是可以
  158. var adremove = document.createElement("span");
  159. adremove.style.cssText = "margin-left:10px;display:inline-block;";
  160. adremove.innerHTML = "\<input type=\"checkbox\" name=\"switch\" id=\"switch_ads\" class=\"switch\"\>\<label class=\"switchX\" for=\"switch_ads\"\>\<\/label\>";
  161. document.querySelector("div.signed_container div.nav__lf").appendChild(adremove);
  162. adremove.querySelector("#switch_ads").onclick = function () {
  163. getel();//偶尔失效时临时救急用
  164. var xx = document.querySelector("div.home__col--rt ul.home__business").style.display;
  165. switch (xx) {
  166. case "block":
  167. xx = "none";
  168. break;
  169. case "none":
  170. xx = "block";
  171. break;
  172. default:
  173. xx = "none";
  174. }
  175. document.querySelector("div.home__col--rt ul.home__business").style.display = xx;
  176. document.querySelector("div.home__col--rt div.info-report-wrap").style.display = xx;
  177. if(xx = "block"){document.querySelector(".today-topic__container.board").style.marginTop = "0";}
  178. if(xx = "none"){document.querySelector(".today-topic__container.board").style.marginTop = "-15px";}
  179.  
  180. }
  181. adremove.querySelector("#switch_ads").click(); //模拟点击一下
  182. //document.querySelector("div#snb_im i.iconfont.im__expand").click();//模拟点击一下,隐藏聊天
  183. }
  184. //2.2定义分隔线,不好看,暂时备用
  185. function dvdelne() {
  186. var zichiRowtd = document.querySelector("a[href='/S/SZ159967']").parentNode.parentNode.querySelectorAll("td"); //.previousSibling .nextSibling
  187. var zhishuRowtd = document.querySelector("a[href='/S/SH000016']").parentNode.parentNode.querySelectorAll("td");
  188. for (var i = 0; i < zichiRowtd.length; i++) {
  189. zichiRowtd[i].style.borderTop = "2px solid rgba(19, 105, 191, 0.8)"; //querySelectorAll选一群,然后一起设置style不行
  190. }
  191. for (var i = 0; i < zhishuRowtd.length; i++) {
  192. zhishuRowtd[i].style.borderTop = "2px solid rgba(19, 105, 191, 0.8)"; //querySelectorAll选一群,然后一起设置style不行
  193. }
  194. }
  195. //2.3给持仓股加标识
  196. function StartmarkL() {
  197. //先定义一个加class的函数
  198. function markL () {
  199. document.querySelector("a[href='/S/SZ159967']").parentNode.setAttribute("class", "zczq");
  200. document.querySelector("a[href='/S/SZ159949']").parentNode.setAttribute("class", "zczq");
  201. document.querySelector("a[href='/S/SZ159915']").parentNode.setAttribute("class", "zczq");
  202. document.querySelector("a[href='/S/SH512170']").parentNode.setAttribute("class", "zczq");
  203. document.querySelector("a[href='/S/SH588000']").parentNode.setAttribute("class", "zczq");
  204. document.querySelector("a[href='/S/SH512290']").parentNode.setAttribute("class", "zczq");
  205. document.querySelector("a[href='/S/SH515030']").parentNode.setAttribute("class", "zczq");
  206. document.querySelector("a[href='/S/SH513050']").parentNode.setAttribute("class", "zczq");
  207. //document.querySelector("a[href='/S/SH510500']").parentNode.setAttribute("class", "zczq");
  208. addPermernantStyle("td.zczq{border-left:2px solid rgba(19, 105, 191, 0.8);}");
  209. getel();
  210. }
  211. //执行一次
  212. markL();
  213. //定义一个【等待>>执行】函数
  214. function waitX(selector,funcNAME) {
  215. var markX = setInterval(function(){ //间隔执行
  216. if (document.querySelector(selector) ) {
  217. clearInterval(markX);
  218. return false;
  219. }else{
  220. eval(funcNAME+'()');//通过y来实现,function func()或者func()会报错,function func(){}
  221. }
  222. }, 1000); //间隔时间,毫秒
  223. }
  224. //给选定的元素增加事件,点击后执行【等待>>执行】函数
  225. document.querySelector("div#optional.optional div.optional__tabs__controls a").onclick = function(){waitX(".zczq","markL");};//自选股点击后
  226. document.querySelector("tr.sortable th.optional__reload").onclick = function(){waitX(".zczq","markL");};//刷新点击后
  227. document.querySelector("tr.sortable th.optional__category").onclick = function(){waitX(".zczq","markL");};//分组选择后
  228.  
  229. }
  230.  
  231. //2.4修改首页
  232. function StartJsIndex() {
  233. console.log("开始修改首页");
  234. var alllist = document.querySelector("div.home-timeline div.home-timeline-tabs a");//先选“全部”,要不unred和readmore可能没有
  235. alllist.click();
  236. document.querySelector("div#optional.optional div.optional__tabs__controls a").click();
  237. //定义替换链接的函数,开放给全局,要不layout的函数调用不了
  238. getel = function () {
  239. container = document.querySelector(".user__container"); //这里的规则需要按网站修改
  240. dir_links1 = "td .name"; //股票列表里的名称
  241. dir_links2 = ".home__stock-index__item"; //最上面的股指
  242. dir_links3 = "div.stock-hot__container.board table.stock-hot__list.board__list tr td a";//热门话题
  243. dir_links4 = "div.today-topic__list li a";//今日话题
  244. dir_links5 = ".status-link";//网页链接(或有)
  245. dir_links6 = ".timeline__expand__control";//展开(或有)
  246. dir_links7 = ".timeline__live td a";//7x24的链接(或有)
  247. anchors1 = document.querySelectorAll(dir_links1); // + document.querySelectorAll(dir_links2);直接加不起作用
  248. anchors2 = document.querySelectorAll(dir_links2);
  249. anchors3 = document.querySelectorAll(dir_links3);
  250. anchors4 = document.querySelectorAll(dir_links4);
  251. anchors5 = document.querySelectorAll(dir_links5);
  252. anchors6 = document.querySelectorAll(dir_links6);
  253. anchors7 = document.querySelectorAll(dir_links7);
  254. //var anchors5 = document.getElementsByClassName("status-link");
  255.  
  256. for (var i = 0; i < anchors1.length; i++) {
  257. //anchors[i].target = "newsframeName";
  258. anchors1[i].title="当前页面打开";
  259. anchors1[i].onclick = function () {
  260. zkgp(this);
  261. return false;
  262. }; //添加函数
  263. }
  264. for (var i = 0; i < anchors2.length; i++) {
  265. anchors2[i].title="当前页面打开";
  266. anchors2[i].onclick = function () {
  267. zkgp(this);
  268. return false;
  269. }; //添加函数
  270. }
  271. for (var i = 0; i < anchors3.length; i++) {
  272. anchors3[i].title="当前页面打开";
  273. anchors3[i].onclick = function () {
  274. zkgp(this);
  275. return false;
  276. }; //添加函数
  277. }
  278. for (var i = 0; i < anchors4.length; i++) {
  279. anchors4[i].title="当前页面打开";
  280. anchors4[i].onclick = function () {
  281. zkgp(this);
  282. return false;
  283. }; //添加函数
  284. }
  285. for (var i = 0; i < anchors5.length; i++) {
  286. anchors5[i].title="当前页面打开";
  287. anchors5[i].onclick = function () {
  288. zkgp(this);
  289. return false;
  290. }; //添加函数
  291. }
  292. for (var i = 0; i < anchors6.length; i++) {
  293. anchors6[i].title="已执行";
  294. anchors6[i].onclick = function (){
  295. //setTimeout(function () {
  296. var xxt = this.parentNode.parentNode.querySelector(".status-link");
  297. xxt.title="当前页面打开";
  298. xxt.onclick = function(){//不能直接onclick=zkgp
  299. zkgp(xxt);
  300. return false;
  301. }
  302. //},1*1000); //等1秒钟之后执行
  303. } //添加函数
  304. }
  305. for (var i = 0; i < anchors7.length; i++) {
  306. anchors7[i].title="当前页面打开";
  307. anchors7[i].onclick = function () {
  308. zkgp(this);
  309. return false;
  310. }; //添加函数
  311. }
  312. //定义点击后执行展开页面的函数
  313. var zkgp = function (a) {
  314. newsframe.setAttribute("src", a.getAttribute("href"));
  315. container.style.marginLeft = "0%";
  316. newsframe.style.cssText = cssframe + "height:100%;";
  317. newsfbg.style.cssText = cssnewsfbg + "height:100%;";
  318. newsfbg.style.zIndex = "999";
  319. var opnlk = document.createElement("a");
  320. 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;";
  321. opnlk.innerHTML = "新页面打开";
  322. opnlk.href = a.getAttribute("href");
  323. opnlk.target = "_blank";
  324. document.body.appendChild(opnlk);
  325. document.body.style.overflow = "hidden";//禁止父元素滚动,比fixed强
  326. newsfbg.onclick = function () {
  327. newsfbg.style.width = "0px";
  328. newsframe.style.width = "0px";
  329. container.style.marginLeft = "auto";
  330. newsframe.setAttribute("src", "");
  331. opnlk.innerHTML = "";
  332. document.body.style.overflow = "";//恢复父元素滚动
  333. }
  334. }
  335. }
  336. //等关键元素加载后,开始替换
  337. var WaitforAlllist = setInterval(function () { //间隔执行,等alllist点击加载完毕(选取两个关键元素)
  338. if (document.querySelector(".status-link") && document.querySelector("a.home-timeline__unread")) {
  339. clearInterval(WaitforAlllist);
  340. getel();
  341. var unread = document.querySelector("a.home-timeline__unread");//加载【未读】后运行一遍
  342. var readmore = document.querySelector("a.home__timeline__more");//加载【更多】后运行一遍
  343. readmore.onclick = function(){
  344. setTimeout(function(){
  345. getel();
  346. },2*1000); //等1秒钟之后执行
  347. }
  348. unread.onclick = function(){
  349. setTimeout(function(){
  350. getel();
  351. },2*1000); //等1秒钟之后执行
  352. }
  353. }
  354. }, 1000); //间隔时间,毫秒
  355. //向下滚动会增加元素,同步修改
  356. window.onscroll = function () { //兼容写法 //只要滚动,就开始
  357. var scrollTop = document.body.scrollTop || document.documentElement.scrollTop; //滚动的数值,取首个为真的
  358. var clientHeight = document.documentElement.clientHeight || document.body.clientHeight || window.innerHeight;
  359. //console.log(document.documentElement.offsetHeight - 194, clientHeight, scrollTop);
  360. if (scrollTop >= (document.documentElement.offsetHeight - 194) - clientHeight) { // body的滚动高度>=html总高度-可视化窗口高度
  361. setTimeout(function () {
  362. getel();
  363. readmore.click();
  364. }, 1 * 1000); //等1秒钟之后执行
  365. }
  366. }
  367. //7x24那边增加一个只显示重要信息的开关,同时为了避免切换后空白,模拟滚动,且即使反复切换也只执行一次
  368. var seven24 = document.querySelector("a.home__timeline__live__control");
  369. seven24.onclick = getel();
  370. var onlyimp = document.createElement("span");
  371. onlyimp.style.cssText = "margin-left:150px;margin-top:5px;display:inline-block;";
  372. onlyimp.innerHTML = "\<input type=\"checkbox\" name=\"switch\" id=\"switch_imp\" class=\"switch\"\>\<label class=\"switchX\" for=\"switch_imp\"\>\<\/label\> ";
  373. seven24.parentNode.appendChild(onlyimp);
  374. onlyimp.querySelector("#switch_imp").onclick = function () {
  375. getel();
  376. if(!document.getElementById("imp")){
  377. addStyle_imp("div.timeline__live table.home__timeline-live__tb tr:not([class=\"highlight\"]){display:none;}");
  378. }else{
  379. document.getElementById("imp").remove();
  380. }
  381. }
  382. document.getElementById("switch_imp").addEventListener("click", function(event){
  383. setTimeout("window.scrollBy(0,-10);",500);//500毫秒之后往下滚动1,模拟scroll,触发加载新内容
  384. setTimeout("window.scrollBy(0,10);",600);//往上滚动1
  385. setTimeout("window.scrollBy(0,-10);",700);//往下滚动1
  386. setTimeout("window.scrollBy(0,10);",1000);//往上滚动1
  387. getel();
  388. }, {once: true});//添加监听,只执行一次!!!!
  389. }
  390. //2.5个股详情页
  391. function StartJsGp() {
  392. console.log("修改详情页");
  393. var article = document.querySelector(".container.article__container"); //这里的规则需要按网站修改 ◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀◀
  394. var articleBTN = document.querySelector(".status-link");
  395. //articleBTN.target = "newsframeName";
  396. articleBTN.onclick = function () {
  397. zkwl(this);
  398. return false;
  399. }; //添加函数;
  400. var zkwl = function (a) {
  401. newsframe.setAttribute("src", a.getAttribute("href"));
  402. article.style.marginLeft = "10%";
  403. newsframe.style.cssText = cssframe + "height:100%;";
  404. newsfbg.style.cssText = cssnewsfbg + "height:100%;";
  405. newsfbg.style.zIndex = "999";
  406. newsfbg.onclick = function () {
  407. newsfbg.style.width = "0px";
  408. newsframe.style.width = "0px";
  409. article.style.marginLeft = "auto";
  410. newsframe.setAttribute("src", "");
  411. }
  412. }
  413.  
  414. }

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址