微博超话图片下载

提供超话内原图下载,优化超话浏览体验

Fra og med 28.03.2023. Se den nyeste version.

  1. // ==UserScript==
  2. // @name 微博超话图片下载
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.4
  5. // @description 提供超话内原图下载,优化超话浏览体验
  6. // @author 乃木流架
  7. // @match https://weibo.com/p/*
  8. // @match https://weibo.com/u/*
  9. // @match https://d.weibo.com/*
  10. // @match https://weibo.com/*
  11. // @icon https://i.jpg.dog/26e8e3a48d8a079e3bca9bae1a96434b.png
  12. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.4/jquery.min.js
  13. // @require https://cdnjs.cloudflare.com/ajax/libs/sweetalert2/11.7.3/sweetalert2.all.js
  14. // @grant GM_addStyle
  15. // @grant GM_setValue
  16. // @grant GM_getValue
  17. // @grant GM_download
  18. // @run-at document-start
  19. // @license MIT
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. ("use strict");
  24. console.log("🏳️‍🌈[微博超话图片下载]脚本开始执行");
  25.  
  26. //自定义用户主页背景图片
  27. //图床:https://jpg.dog/
  28. const urlNew = "https://i.jpg.dog/f5651b662ec09801fdd4a54285038ee1.jpeg";
  29.  
  30. //默认主页背景图片
  31. const urlDefault1 =
  32. "https://ww1.sinaimg.cn/mw2000/70ace9b7ly1ggzusnypoej20yi0yiaop.jpg";
  33. const urlDefault2 =
  34. "https://wx1.sinaimg.cn/mw2000/001WLsZ7ly1gs69906b4pj60u00u0wiu02.jpg";
  35. const urlDefault3 =
  36. "https://wx1.sinaimg.cn/mw2000/007v6V7hly1h9i7kq8c3pj30u00u0wg7.jpg";
  37.  
  38. /**
  39. * @desc 属性改变监听,属性被set时出发watch的方法,类似vue的watch
  40. * @author Jason
  41. * @study https://www.jianshu.com/p/00502d10ea95
  42. * @data 2018-04-27
  43. * @constructor
  44. * @param {object} opts - 构造参数. @default {data:{},watch:{}};
  45. * @argument {object} data - 要绑定的属性
  46. * @argument {object} watch - 要监听的属性的回调
  47. * watch @callback (newVal,oldVal) - 新值与旧值
  48. */
  49. class watcher {
  50. constructor(opts) {
  51. this.$data = this.getBaseType(opts.data) === "Object" ? opts.data : {};
  52. this.$watch = this.getBaseType(opts.watch) === "Object" ? opts.watch : {};
  53. for (let key in opts.data) {
  54. this.setData(key);
  55. }
  56. }
  57.  
  58. getBaseType(target) {
  59. const typeStr = Object.prototype.toString.apply(target);
  60.  
  61. return typeStr.slice(8, -1);
  62. }
  63.  
  64. setData(_key) {
  65. Object.defineProperty(this, _key, {
  66. get: function () {
  67. return this.$data[_key];
  68. },
  69. set: function (val) {
  70. const oldVal = this.$data[_key];
  71. if (oldVal === val) return val;
  72. this.$data[_key] = val;
  73. this.$watch[_key] &&
  74. typeof this.$watch[_key] === "function" &&
  75. this.$watch[_key].call(this, val, oldVal);
  76. return val;
  77. },
  78. });
  79. }
  80. }
  81.  
  82. const Toast = Swal.mixin({
  83. toast: true,
  84. position: "bottom-end",
  85. showConfirmButton: false,
  86. timer: 3000,
  87. timerProgressBar: true,
  88. didOpen: (toast) => {
  89. toast.addEventListener("mouseenter", Swal.stopTimer);
  90. toast.addEventListener("mouseleave", Swal.resumeTimer);
  91. },
  92. });
  93.  
  94. const picImpl = "https://weibo.com/ajax/statuses/show?id=";
  95. const chaohuaImpl =
  96. "https://weibo.com/ajax/profile/topicContent?tabid=231093_-_chaohua";
  97. let length = 15;
  98. let wm = new watcher({
  99. data: {
  100. len: length,
  101. },
  102. watch: {
  103. len(newVal, oldVal) {
  104. // console.log("length: ", length);
  105. console.log("🔢新微博条数:" + newVal);
  106. console.log("🔢旧微博条数:" + oldVal);
  107. if (newVal > length) {
  108. let faces = document.getElementsByClassName("WB_info");
  109. let i = length;
  110. length = faces.length;
  111. if (/d.weibo.com/.test(currLink)) {
  112. while (i < length) {
  113. // console.log("处理链接");
  114. let btn = initBtn();
  115. let at = faces[i].nextElementSibling.children[0];
  116. // console.log(at);
  117. at.href = at.href + "?page_source=hot";
  118. // console.log(at);
  119. faces[i].appendChild(btn);
  120. // console.log(i);
  121. // console.log(faces[i]);
  122. handleBtn(btn);
  123. i++;
  124. }
  125. } else {
  126. while (i < length) {
  127. let btn = initBtn();
  128. faces[i].appendChild(btn);
  129. // console.log(i);
  130. // console.log(faces[i]);
  131. handleBtn(btn);
  132. i++;
  133. }
  134. }
  135. }
  136. },
  137. },
  138. });
  139.  
  140. function sendAjax(type, url, flag) {
  141. let xhr = new XMLHttpRequest();
  142. xhr.open(type, url, flag);
  143. xhr.send();
  144. let res = xhr.responseText;
  145. // console.log(xhr.responseText);
  146. // return JSON.parse(res);
  147. return res;
  148. }
  149.  
  150. function initBtn() {
  151. let div = document.createElement("div");
  152. let img = document.createElement("img");
  153. let a = document.createElement("a");
  154. // img.src = "https://i.jpg.dog/72dbffd3545cb15b148682beaf0fb64a.png";
  155. // img.src = "https://i.jpg.dog/d5380c9048e6ee303f188da9ec574399.png";
  156. img.src =
  157. "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAEMAAABDCAYAAADHyrhzAAAACXBIWXMAAAsTAAALEwEAmpwYAAAFMElEQVR4nO2baYgcRRTHKzGJqFlFvDDRL16RCB6sG3f7vdnxQ+KBB3gEL4R8cVFUZN0se8x7U4giqIj4TZB4bEAJKIpCUBA0+SCaLwoKUYOKmCBoNEYYp6vGWFJzrLs7PTO93V3dk539Q8F8merXv36vjveqhFhWd8iMDp5kZP7MssQLygXvwpL01hm56VSxlGWkWKmkd6UmHNUEM4rhc0VwRDOaoKYYfM34tWZ8WxE+WSngZgtOHM8AKgxbai+Ph1u9eNhmASmCjxTltplxr08cDzITm0/ThAXNeDAugJZgCEua4BWfvA2iG2XGvT7F8JRi+NMVhAAoxzTjrq6C4jPcogl/SgtCcwihVgQvGplfmxkEMzlwhmJ4PysITY3we81DA6mD0NO5TZrhh8wBNIUOVDThhBFiRSogfILb69Of6eL2upH5VU5B6AI8XB+4sn7ZMGHznrP1iWZ4xI1r4zFFUHbU924z0r86URCK8G43HgHflWT+PCM3rtEMO914CMwkNoZo9oYUoXJkKP8PHK5wGDIyNggziadrgh+dGcmwvfEsn4YvdvUc69V2jxMLhmZ4xx2I9GDUgMAvdpccCYTPuTvcgkgXRr3tWDQII/tPdhse2cBQjP9qxvyiYGjGYgpfKQvPsOPHvvBeMbblFEXw21KFYVul4F0X0itge1pGZQVDEe7t7BVCrKjt/pY2jCoQiZe394pCbjhNgzKFwfBspxB5uVdgaMJDNlfbBgYe7BkYtdYfCMKXQ5emb0zGMCg33sIrvAd7DYbd4gfCUIwv9RoMO260gvFxz8FgNIElTU14qBdh6Gnv6qbFlmL4pxdhVDh3U/MulTP4Kl0Aw6Y058OYuuacnoVRxAfmwShJb12vwrBLivmeMe719SoMVfTuWzBmiJX1LFDEugfuVoSfpg7DZuMI3lKMf0SF4ZN3a9A643CkDglHZ6dnhsm0YNjDK3bgr/3X2xBjNoRmGBTly9p5Ggbn9mMLv65hVEEsKB0qhl+j2G+m8KwmGJrwtWhk4dWAviZcwQgCYYvhUWxXhL83gYib7lOEL4hIQBYHIwhEheHGqKcCWqb/NA8NRIXRALKwpqkJxpKCoRj22GT1fBC56+MUrRXBE4EwzNatJ7Q7kugGSDgYLkDYVinAtYEwrOw0FafzBhAROmQ6w0g6NObYedQ8esOJopV8htviwlich7SH4cojQpUajdy4JqkCUjggrWE4BtE+RBpSBM8n8bBwIRMMw1VozDaCb9tmxhsy07lzkzxW1N5DmmG49oiaTbltIqxUwvnQlkAIxubCSAOEPcBrh4PQMErTg+sV419JA1n4HCOHzp79Pe71OQ2Nhh1FvCc0iIY04+NJGtHKQ1opcY9ohGCUw25G5ldpwi9cAOkMwoFHEJRtoUxElW/jmPBomh7iwiPqbUTElSp6dzkwLBCIQxC7YoNoSDE+7RqIi9Coh8dnC2eoWDL2EAvjDjdA4BPN8Gb1RkDS/RPuj3zcsfOACjMugDhphPv/LuTOF65kbOWN4JnMX7Sjt+G+wHSeC+kCPtS9d05gZyNRnJoUDV+lCQ90jzdAWRM8JrKSkfm1ivA5e2kuUxCMH9o1kegGKYLLFMEHqYMgPOAT3im6UdomlQnedX51i/ArRXCvzduKbldpenC9jV/N+GWCY8IRO7VX78andTsxaZXl4EV2X6AJ3tCM34QeXwh+roYewZSt2jm/jZiFzEj/al/iJTYHWSG8uXr/rYj322S0/er2elamt5eXtSwxV/8B8CHKT9TokA8AAAAASUVORK5CYII=";
  158. img.setAttribute(
  159. "style",
  160. "width:12px;height:12px;margin-top:5px;margin-right:2px;"
  161. );
  162. a.innerHTML = "图片下载";
  163. a.setAttribute(
  164. "style",
  165. "padding:0;font-size: 12px;margin-top:1px;color:#333333;margin-top: 3px;"
  166. );
  167. div.appendChild(img);
  168. div.appendChild(a);
  169. div.setAttribute("class", "nogiruka-button");
  170. div.setAttribute(
  171. "style",
  172. "display: inline-flex;position:absolute;box-shadow: 0px 1px 2px rgba(0, 0, 0, 0.1);border:1px solid #d9d9d9;height:21px;width:80px;background-color:#ffffff;font-color:#333333;font-size: 12px;text-align: center;border-radius: 2px;cursor: pointer;margin-left:5px;margin-top:-2px;justify-content: center;"
  173. );
  174. return div;
  175. }
  176.  
  177. let firstLength = 100;
  178. function addBtn() {
  179. let faces = document.getElementsByClassName("WB_info");
  180. let i = 0;
  181. length = faces.length;
  182. if (length < firstLength) {
  183. firstLength = length;
  184. console.log("🔢初始微博条数: " + firstLength);
  185. }
  186.  
  187. while (i < length) {
  188. let btn = initBtn();
  189. faces[i].appendChild(btn);
  190. // console.log(i);
  191. // console.log(faces[i]);
  192. handleBtn(btn);
  193. i++;
  194. }
  195. }
  196.  
  197. function handleBtn(btn) {
  198. btn.addEventListener("click", function (e) {
  199. let info = e.target.parentNode.parentNode;
  200. let from = info.nextElementSibling;
  201. let href = from.firstElementChild.href;
  202. // console.log(info);
  203. // console.log(from);
  204. // console.log(href);
  205. if (/page_source=hot/.test(href) && /d.weibo.com/.test(currLink)) {
  206. window.open(href);
  207. setTimeout(() => {
  208. Toast.fire({
  209. timer: 3000,
  210. icon: "success",
  211. title:
  212. "🌈微博用户: " +
  213. GM_getValue("use") +
  214. '\n📝微博文案: <div id="tex">' +
  215. GM_getValue("tex") +
  216. "</div>💝开始下载图片\n💖图片下载完毕\n📦共计 " +
  217. GM_getValue("picn") +
  218. " 张图片",
  219. });
  220. }, 2000);
  221. // setTimeout(() => {
  222. // // 获取整个页面元素
  223. // var page = document.documentElement;
  224. // // 创建键盘事件对象
  225. // var event = new KeyboardEvent("keydown", { keyCode: 27 });
  226. // // 触发键盘事件
  227. // page.dispatchEvent(event);
  228. // }, 4000);
  229. // return;
  230. } else {
  231. handleUrl(href, false);
  232. }
  233. });
  234. }
  235.  
  236. function handleUrl(href, flag) {
  237. let h = href.split("?")[0];
  238. let mblogid = h.split("/")[h.split("/").length - 1];
  239. let url = picImpl + mblogid;
  240. // console.log(mblogid);
  241. // console.log(url);
  242. let response = JSON.parse(sendAjax("GET", url, flag));
  243. // console.log(response);
  244. handlePic(response);
  245. }
  246.  
  247. let tao = {
  248. us: "",
  249. te: "",
  250. };
  251. function handlePic(response) {
  252. const picInfos = response.pic_infos;
  253. const mblogid = response.mblogid;
  254. // console.log(picInfos);
  255. const picNum = response.pic_num;
  256. GM_setValue("picn", picNum);
  257. const userName = response.user.screen_name;
  258. const text = response.text_raw;
  259. tao.us = userName;
  260. tao.te = text;
  261. GM_setValue("use", userName);
  262. GM_setValue("tex", text);
  263. console.log("🌈微博用户:" + userName + "\n📝微博文案:\n" + text);
  264. // Toast.fire({
  265. // icon: "info",
  266. // title: "🌈微博用户:" + userName + "\n📝微博文案:\n" + text,
  267. // });
  268. let downloadList = [];
  269. if (picInfos) {
  270. // Toast.fire({
  271. // timer: 10000,
  272. // icon: "success",
  273. // title:
  274. // "🌈微博用户:" +
  275. // userName +
  276. // "\n📝微博文案:\n" +
  277. // text +
  278. // "\n💝开始下载图片",
  279. // });
  280. console.log("💝开始下载图片");
  281. let index = 0;
  282. for (const [id, pic] of Object.entries(picInfos)) {
  283. index += 1;
  284. let largePicUrl = pic.largest.url;
  285. let picName = largePicUrl
  286. .split("/")
  287. [largePicUrl.split("/").length - 1].split("?")[0];
  288. let ext = picName.split(".")[1];
  289. let dlName = userName + "-" + mblogid + "-" + index + "." + ext;
  290. downloadList.push({
  291. index: index,
  292. picNum: picNum,
  293. url: largePicUrl,
  294. name: dlName,
  295. headerFlag: true,
  296. });
  297. }
  298. // console.log(downloadList);
  299. handleDownloadList(downloadList);
  300. }
  301. }
  302.  
  303. function handleDownloadList(downloadList) {
  304. for (const item of downloadList) {
  305. downloadWrapper(
  306. item.index,
  307. item.picNum,
  308. item.url,
  309. item.name,
  310. item.headerFlag
  311. );
  312. }
  313. }
  314.  
  315. const pro = {
  316. a: "🌚", //0-25
  317. b: "🌘", //25-50
  318. c: "🌓", //50
  319. d: "🌒", //50-75
  320. e: "🌝", //100
  321. };
  322. function downloadWrapper(index, picNum, url, name, headerFlag) {
  323. let textContent = name + " [0%]";
  324. let percent = 0;
  325. const download = GM_download({
  326. url,
  327. name,
  328. headers: headerFlag
  329. ? {
  330. Referer: "https://weibo.com/",
  331. Origin: "https://weibo.com/",
  332. }
  333. : null,
  334. // saveAs: false,
  335. onprogress: (e) => {
  336. // e = { int done, finalUrl, bool lengthComputable, int loaded, int position, int readyState, response, str responseHeaders, responseText, responseXML, int status, statusText, int total, int totalSize }
  337. percent = (e.done / e.total) * 100;
  338. percent = percent.toFixed(0);
  339. textContent = name + " [" + percent + "%]";
  340. if (percent < 25) {
  341. console.log(pro.a + textContent);
  342. } else if (percent >= 25 && percent < 50) {
  343. console.log(pro.b + textContent);
  344. } else if (percent >= 50 && percent < 75) {
  345. console.log(pro.c + textContent);
  346. } else if (percent >= 75 && percent < 100) {
  347. console.log(pro.d + textContent);
  348. } else {
  349. console.log(pro.e + textContent);
  350. }
  351.  
  352. // console.log(textContent);
  353. },
  354. onload: () => {
  355. // console.log("💖" + name + " 下载完毕");
  356. if (
  357. /page_source=hot/.test(currLink) &&
  358. !/root_comment_id/.test(currLink) &&
  359. /weibo.com/.test(currLink) &&
  360. index == picNum
  361. ) {
  362. console.log("💖图片下载完毕\n" + "📦共计 " + picNum + " 张图片");
  363. window.close();
  364. } else if (index == picNum) {
  365. console.log("💖图片下载完毕\n" + "📦共计 " + picNum + " 张图片");
  366. Toast.fire({
  367. timer: 3000,
  368. icon: "success",
  369. title:
  370. "🌈微博用户: " +
  371. tao.us +
  372. '\n📝微博文案: <div id="tex">' +
  373. tao.te +
  374. "</div>💝开始下载图片\n💖图片下载完毕\n📦共计 " +
  375. picNum +
  376. " 张图片",
  377. });
  378. }
  379. },
  380. onerror: (e) => {
  381. console.log(e);
  382. },
  383. ontimeout: (e) => {
  384. console.log(e);
  385. },
  386. });
  387. }
  388.  
  389. function handleQ() {
  390. //搜索处理
  391. if (document.getElementsByClassName("username")[0]) {
  392. let username = document.getElementsByClassName("username")[0].innerText;
  393. let input = document.getElementsByClassName("W_input")[0];
  394. let q = username + "超话 ";
  395. let ph = document.getElementsByClassName("placeholder")[0];
  396. if (ph != null) {
  397. ph.remove();
  398. }
  399. // console.log(input.value);
  400. if (input.value != q) {
  401. input.value = q;
  402. }
  403. }
  404. }
  405.  
  406. function chaohuaBtn(div, imgdiv) {
  407. //超话按钮添加
  408. //处理超话按钮位置
  409. let tab = document.getElementsByClassName("wbpro-tab2")[0];
  410. tab.childNodes[5].remove();
  411. tab.childNodes[5].remove();
  412.  
  413. //生成超话图标
  414. let img = document.createElement("img");
  415. let p = document.createElement("p");
  416. p.textContent = "全部超话";
  417. p.style.display = "none";
  418. img.className = "icon-link wbpro-textcut nogiruka";
  419. img.setAttribute(
  420. "style",
  421. "padding:5px;width: 22px;height: 22px;margin-top: 6px;color: black;cursor: pointer;"
  422. );
  423. img.src =
  424. "https://h5.sinaimg.cn/upload/100/959/2020/05/09/timeline_card_small_super_default.png";
  425. imgdiv.className = "woo-box-item-inlineBlock";
  426. imgdiv.appendChild(img);
  427. imgdiv.appendChild(p);
  428. //生成我的超话
  429. let divin = document.createElement("div");
  430. let d = document.createElement("div");
  431. div.className = "woo-box-item-inlineBlock";
  432. divin.className = "woo-box-flex woo-box-alignCenter woo-box-justifyCenter";
  433. d.className = "wbpro-textcut";
  434. d.innerHTML = "我的超话";
  435. divin.appendChild(d);
  436. div.appendChild(divin);
  437. //整合按钮
  438. tab.children[3].insertAdjacentElement("beforebegin", imgdiv);
  439. tab.children[3].insertAdjacentElement("beforebegin", div);
  440. }
  441.  
  442. function handleChaohua(again = true) {
  443. // console.log("handleChaohua...");
  444. let tab = document.getElementsByClassName("wbpro-tab2")[0];
  445. let div = document.createElement("div");
  446. let imgdiv = document.createElement("imgdiv");
  447.  
  448. if (again) {
  449. chaohuaBtn(div, imgdiv);
  450. } else {
  451. div = tab.children[3];
  452. imgdiv = tab.children[4];
  453. }
  454.  
  455. //获取超话列表
  456. let data = JSON.parse(sendAjax("GET", chaohuaImpl, false)).data;
  457. // console.log(data);
  458. let res = data.list;
  459. // console.log(data);
  460. let length = res.length;
  461. let chaohuaList = [];
  462. if (res) {
  463. let index = 0;
  464. for (const [id, l] of Object.entries(res)) {
  465. index += 1;
  466. let link = l.link;
  467. let pic = l.pic;
  468. let topic_name = l.topic_name;
  469. let content1 = l.content1;
  470. let content2 = l.content2;
  471. chaohuaList.push({
  472. index: index,
  473. link: link,
  474. pic: pic,
  475. topic_name: topic_name,
  476. content1: content1,
  477. content2: content2,
  478. });
  479. }
  480. // console.log(chaohuaList);
  481. }
  482.  
  483. //为我的超话和超话图标绑定点击事件
  484. imgdiv.addEventListener("click", function () {
  485. window.location.href = chaohuaAll;
  486. });
  487. div.addEventListener("click", function () {
  488. console.log("💝开始处理超话信息");
  489. console.log("🔢超话条数:" + length);
  490. //点击高亮
  491. for (let index = 0; index < tab.children.length; index++) {
  492. tab.children[index].className = "woo-box-item-inlineBlock";
  493. }
  494. div.className = "woo-box-item-inlineBlock cur";
  495. //
  496. wrapper = document.getElementsByClassName(
  497. "vue-recycle-scroller__item-wrapper"
  498. )[0];
  499. wrapper.firstElementChild.insertAdjacentElement(
  500. "beforebegin",
  501. wrapperDiv
  502. );
  503. // console.log(e);
  504. while (wrapper.hasChildNodes()) {
  505. //当wrapper下还存在子节点时 循环继续
  506. wrapper.removeChild(wrapper.firstChild);
  507. }
  508. // console.log("wrapper: ", wrapper);
  509. handleChaohuaList(chaohuaList, length);
  510. });
  511. }
  512.  
  513. function handleChaohuaList(chaohuaList, length) {
  514. // console.log("handleChaohuaList...");
  515.  
  516. for (const item of chaohuaList) {
  517. // console.log("处理超话列表。。。");
  518. // console.log(item);
  519. chaohuaWrapper(
  520. item.index,
  521. item.link,
  522. item.pic,
  523. item.topic_name,
  524. item.content1,
  525. item.content2
  526. );
  527. }
  528. // console.log("wrapperDiv.length: " + wrapperDiv.children.length);
  529. // 添加查看全部超话按钮
  530. if (wrapperDiv.children.length == length) {
  531. // console.log("添加查看全部超话按钮。。。");
  532. let all = document.createElement("div");
  533. let bt = document.createElement("a");
  534. all.className = "W_pages";
  535. all.setAttribute(
  536. "style",
  537. "background-color: white;display: grid;padding: 20px;transform: translateY(" +
  538. length * 92 +
  539. "px);"
  540. );
  541. // a.className = "page next S_txt1 S_line1";
  542. bt.innerHTML = "查看全部超话";
  543. // bt.className = "nogiruka";
  544. // bt.className = "page next S_txt1 S_line1";
  545. bt.href = chaohuaAll;
  546.  
  547. bt.setAttribute(
  548. "style",
  549. "padding: 4px 0;text-align: center;font-weight: 400;background-color: transparent;cursor: pointer;font-size: 15px;display: block;border: 1px solid transparent;color:#fa7d3c"
  550. );
  551. all.appendChild(bt);
  552. wrapperDiv.appendChild(all);
  553. console.log("💖超话信息处理完毕");
  554. // console.log(wrapperDiv);
  555. } else {
  556. // alert("❌出错了,请刷新");
  557. // location.reload();
  558. // return;
  559. handleChaohua((again = false));
  560. console.log("💖超话信息处理完毕");
  561. }
  562. wrapper.appendChild(wrapperDiv);
  563. }
  564.  
  565. let autoplaySigns = localStorage.getItem("autoplaySigns");
  566. if (autoplaySigns != null) {
  567. let userId = autoplaySigns.split('"')[1];
  568. if (userId != GM_getValue("userId")) {
  569. GM_setValue("userId", userId);
  570. }
  571. // GM_setValue("userId", userId);
  572. }
  573.  
  574. console.log("🆔登录用户ID为:" + GM_getValue("userId"));
  575. const chaohuaAll =
  576. "https://weibo.com/u/page/follow/" +
  577. GM_getValue("userId") +
  578. "/231093_-_chaohua";
  579. let wrapper = "";
  580. let wrapperDiv = document.createElement("div");
  581. wrapperDiv.className = "wrapperDiv";
  582. function chaohuaWrapper(index, link, pic, topic_name, content1, content2) {
  583. //
  584. // console.log("chaohuaWrapper...");
  585. let tr = (index - 1) * 92;
  586. // console.log(index);
  587. // console.log(tr);
  588. let st = "background-color: white;transform: translateY(" + tr + "px)";
  589. // console.log(st);
  590. let view = document.createElement("div");
  591. view.className = "vue-recycle-scroller__item-view";
  592. view.setAttribute("style", st);
  593. view.innerHTML =
  594. '<div data-index="0" data-active="true" class="wbpro-scroller-item"><div class="woo-box-flex TopicFeedCard_topicFeedCard_159d4"><div class="woo-box-flex woo-box-alignCenter TopicFeedCard_item_1Ikoi"><a class="ALink_none_1w6rm TopicFeedCard_left_EgdGf" href="' +
  595. link +
  596. "/super_index" +
  597. '" target="_blank"><div class="woo-picture-main woo-picture-square woo-picture-hover TopicFeedCard_pic_1ilsA" style="width: 3.125rem;"><!----><img alt="等比图" src="' +
  598. pic +
  599. '" class="woo-picture-img"><div class="woo-picture-cover"></div><div class="woo-picture-hoverMask"></div><!----></div><div class="woo-box-item-flex TopicFeedCard_con_294Gq TopicFeedCard_f12_avvOy" style="align-self: center;"><div class="TopicFeedCard_cla_1pQ6t TopicFeedCard_fb_1aJkn TopicFeedCard_cut_3akoX">' +
  600. topic_name +
  601. '</div><div class="TopicFeedCard_clb_3j52M TopicFeedCard_cut_3akoX"> ' +
  602. content1 +
  603. ' </div><div class="TopicFeedCard_clb_3j52M">' +
  604. content2 +
  605. '</div></div></a><div class="TopicFeedCard_right_1ygKg"><button class="woo-button-main woo-button-line woo-button-default woo-button-s woo-button-round FollowBtn_s_3J5Ve"><span class="woo-button-wrap"><!----><!----><!----><span class="woo-button-content"> 已关注 </span></span></button></div></div></div></div>';
  606. let view1 = view;
  607. wrapperDiv.appendChild(view1);
  608. // while (view.hasChildNodes()) {
  609. // //当table下还存在子节点时 循环继续
  610. // view.removeChild(view.firstChild);
  611. // }
  612. // console.log(wrapper);
  613. }
  614.  
  615. function handleBack() {
  616. let backMain = document.getElementsByClassName(
  617. "woo-picture-main ProfileHeader_pic_2Coeq"
  618. )[0];
  619. let back = document.getElementsByClassName("woo-picture-img")[0];
  620. if (backMain != null && back != null) {
  621. let url = back.src;
  622. // console.log(url != null);
  623. // console.log(url == urlDefault);
  624. // console.log(url);
  625. // console.log(urlDefault);
  626. if (url != null) {
  627. if (url == urlDefault1 || url == urlDefault2 || url == urlDefault3) {
  628. back.src = urlNew;
  629. }
  630. }
  631. }
  632. }
  633.  
  634. let ba = setInterval(() => {
  635. //更换用户主页背景图片
  636. handleBack();
  637. // console.log("更改用户主页背景图片。。。");
  638. }, 50);
  639. let go1 = true;
  640. let go2 = true;
  641. let tabgo = true;
  642. let currLink = window.location.href;
  643. let jumpLink = "";
  644.  
  645. //全局循环器
  646. setInterval(() => {
  647. //
  648. // console.log("⏳全局循环");
  649. let backMain = document.getElementsByClassName(
  650. "woo-picture-main ProfileHeader_pic_2Coeq"
  651. )[0];
  652. let back = document.getElementsByClassName("woo-picture-img")[0];
  653. jumpLink = window.location.href;
  654. // console.log("currLink: " + currLink);
  655. // console.log("jumpLink: " + jumpLink);
  656. // console.log("window.location.href: " + window.location.href);
  657. //检测链接变化
  658. if (currLink != jumpLink) {
  659. console.log("🔄链接跳转\n🔗" + currLink + "\n👇\n🔗" + jumpLink + "\n");
  660. // [currLink, jumpLink] = [jumpLink, currLink];
  661. // console.log("currLink: " + currLink);
  662. // console.log("jumpLink: " + jumpLink);
  663. currLink = jumpLink;
  664. //监听网页链接变化,刷新页面
  665. setTimeout(() => {
  666. if (/d.weibo.com/.test(jumpLink)) {
  667. addBtn();
  668. }
  669. }, 1000);
  670.  
  671. if (/weibo.com\/u/.test(jumpLink)) {
  672. console.log("✅进入用户主页");
  673. }
  674. }
  675. //设置超话页面所有链接为新标签页打开
  676. // if (/weibo.com\/p/.test(currLink)) {
  677. // // console.log($("a"));
  678. // $("a").attr("target", "_blank");
  679. // }
  680.  
  681. if (/weibo.com\/u/.test(jumpLink) && backMain != null) {
  682. if (
  683. back.src == urlDefault1 ||
  684. back.src == urlDefault2 ||
  685. back.src == urlDefault3
  686. ) {
  687. // $(".woo-picture-main.ProfileHeader_pic_2Coeq").val();
  688. // location.reload();
  689. handleBack();
  690. }
  691. }
  692.  
  693. //伪超话内搜索
  694. handleQ();
  695.  
  696. //去除扫描二维码进入手机超话
  697. let qr = document.getElementById("Pl_Core_PicText__263");
  698. if (qr) {
  699. qr.style.display = 'none';
  700. }
  701.  
  702. //清除背景图片监视
  703. if (go1) {
  704. if (!backMain) {
  705. go1 = false;
  706. clearInterval(ba);
  707. console.log("❎不是用户主页");
  708. }
  709. if (/weibo.com\/u/.test(currLink) && backMain != null) {
  710. if (
  711. back.src != urlDefault1 &&
  712. back.src != urlDefault2 &&
  713. back.src != urlDefault3
  714. ) {
  715. go1 = false;
  716. clearInterval(ba);
  717. console.log("✅背景图片已修改");
  718. }
  719. }
  720. }
  721.  
  722. //我的超话按钮高亮清除
  723. let tab = document.getElementsByClassName("wbpro-tab2")[0];
  724. if (tab != null && tabgo) {
  725. tabgo = false;
  726. for (let index = 0; index < tab.children.length; index++) {
  727. tab.children[index].addEventListener("click", function () {
  728. // console.log("🌟", tab.children[index].innerText, "按钮已高亮");
  729. tab.children[3].className = "woo-box-item-inlineBlock";
  730. });
  731. }
  732. }
  733.  
  734. //超话按钮生成
  735. let home = document.getElementsByClassName("Search_outer_3k7Aq")[0];
  736. let chaohuaimg = document.getElementsByClassName(
  737. "icon-link wbpro-textcut nogiruka"
  738. )[0];
  739. if (home != null) {
  740. if (chaohuaimg != null) {
  741. return;
  742. } else {
  743. console.log("🌼生成超话按钮");
  744. handleChaohua();
  745. }
  746. }
  747.  
  748. //翻页监视
  749. let nextPage = document.getElementsByClassName(
  750. "page next S_txt1 S_line1"
  751. )[0];
  752. // console.log(nextPage);
  753. if (nextPage != null && go2) {
  754. go2 = false;
  755. hr = nextPage.href;
  756. console.log("🚌下一页出现,地址为:" + hr);
  757. nextPage.addEventListener("click", function () {
  758. window.location.href = hr;
  759. });
  760. }
  761.  
  762. //微博条数监控
  763. let temp = document.getElementsByClassName("WB_info").length;
  764. if (temp != length && temp > length) {
  765. wm.len = temp;
  766. }
  767. }, 1000);
  768.  
  769. function hot(currLink) {
  770. // console.log(currLink);
  771. // console.log("page_source=hot...");
  772. if (/page_source=hot/.test(currLink) && !/root_comment_id/.test(currLink)) {
  773. handleUrl(currLink, false);
  774. }
  775. }
  776. hot(currLink);
  777.  
  778. GM_addStyle(`
  779. .swal2-container {
  780. z-index: 99999;
  781. }
  782. #tex{
  783. padding-left: 1.4rem;
  784. }
  785. #tt{
  786. display: content;
  787. visibility: hidden
  788. }
  789. `);
  790. window.onload = function () {
  791. //图片下载按钮生成
  792. setTimeout(() => {
  793. // handleAllChaohua();
  794.  
  795. if (/weibo.com\/p/.test(currLink) || /d.weibo.com/.test(currLink)) {
  796. addBtn();
  797. }
  798. // hot(currLink);
  799. // let home = document.getElementsByClassName("Search_outer_3k7Aq")[0];
  800. // if (home != null) {
  801. // console.log("🌼生成超话按钮");
  802. // handleChaohua();
  803. // }
  804. }, 2000);
  805. };
  806. // Your code here...
  807. })();