什么值得买SMZDM - 自动签到、翻页

值得买自动签到、自动无缝翻页

目前為 2021-02-04 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name 什么值得买SMZDM - 自动签到、翻页
  3. // @version 0.9
  4. // @author Siukei
  5. // @description 值得买自动签到、自动无缝翻页
  6. // @match *://*.smzdm.com/*
  7. // @icon https://www.smzdm.com/favicon.ico
  8. // @grant GM_xmlhttpRequest
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_unregisterMenuCommand
  11. // @grant GM_openInTab
  12. // @grant GM_getValue
  13. // @grant GM_setValue
  14. // @grant GM_notification
  15. // @license GPL-3.0 License
  16. // @run-at document-end
  17. // @namespace https://www.smzdm.com
  18. // ==/UserScript==
  19.  
  20. (function () {
  21. // 默认 ID 为 0
  22. var curSite = {
  23. SiteTypeID: 1,
  24. pager: {
  25. nextLink: '//*[@id="commentTabBlockNew"]/ul[2]/li[@class="pagedown"]/a[@href]',
  26. pageElement: 'css;div#commentTabBlockNew > ul > li[id^="li_comment_"]',
  27. HT_insert: ['css;ul.comment_listBox', 2],
  28. replaceE: '//*[@id="commentTabBlockNew"]/ul[2]',
  29. }
  30. , pageUrl: '' // 下一页url
  31. };
  32.  
  33. pageLoading();
  34.  
  35. // 自动翻页
  36. function pageLoading() {
  37. if (window.location.href.indexOf('smzdm.com/p/') == -1) {
  38. return;
  39. }
  40. if (curSite.SiteTypeID > 0) {
  41. commentShowAll();
  42. // 删除无效信息
  43. let comments = document.querySelectorAll('li.comment_list');
  44. for (var i = 0; i < comments.length; i++) {
  45. let comment = comments[i];
  46. if (!checkContent(comment)) {
  47. comment.remove();
  48. }
  49. }
  50. windowScroll(function (direction, e) {
  51. if (direction === "down") { // 下滑才准备翻页
  52. let page = document.querySelector('#commentTabBlockNew > ul.pagination');
  53. if (isInViewPortOfOne(page)) {
  54. ShowPager.loadMorePage();
  55. }
  56. }
  57. });
  58. }
  59. }
  60.  
  61. //判断元素是否出现在窗口内
  62. function isInViewPortOfOne(el) {
  63. // viewPortHeight 兼容所有浏览器写法
  64. let viewPortHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
  65. let offsetTop = el.offsetTop
  66. let scrollTop = document.documentElement.scrollTop
  67. let top = offsetTop - scrollTop
  68. // console.log('top', top)
  69. // 这里有个+100是为了提前加载+ 100
  70. return top <= viewPortHeight + 120
  71. }
  72.  
  73. // 滚动条事件
  74. function windowScroll(fn1) {
  75. var beforeScrollTop = document.documentElement.scrollTop,
  76. fn = fn1 || function () { };
  77. setTimeout(function () { // 延时执行,避免刚载入到页面就触发翻页事件
  78. window.addEventListener("scroll", function (e) {
  79. var afterScrollTop = document.documentElement.scrollTop,
  80. delta = afterScrollTop - beforeScrollTop;
  81. if (delta == 0) return false;
  82. fn(delta > 0 ? "down" : "up", e);
  83. beforeScrollTop = afterScrollTop;
  84. }, false);
  85. }, 1000)
  86. }
  87.  
  88. //自动展开隐藏评论
  89. function commentShowAll() {
  90. let showAll = document.querySelectorAll('.comment_showAll a');
  91. for (var i = 0; i < showAll.length; i++) {
  92. showAll[i].click();
  93. }
  94. }
  95.  
  96. function checkContent(comment) {
  97. let span = comment.querySelector('div.comment_conWrap > div.comment_con > p > span');
  98. let cont = span.textContent;
  99. return cont.indexOf('此用户') == -1 && cont.indexOf('我参与了') == -1;
  100. }
  101.  
  102. var ShowPager = { // 修改自 https://gf.qytechs.cn/scripts/14178
  103. getFullHref: function (e) {
  104. if (e == null) return '';
  105. "string" != typeof e && (e = e.getAttribute("href"));
  106. var t = this.getFullHref.a;
  107. return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
  108. },
  109. createDocumentByString: function (e) {
  110. if (e) {
  111. if ("HTML" !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, "application/xhtml+xml");
  112. var t;
  113. try {
  114. t = (new DOMParser).parseFromString(e, "text/html");
  115. } catch (e) {
  116. }
  117. if (t) return t;
  118. if (document.implementation.createHTMLDocument) t = document.implementation.createHTMLDocument("ADocument"); else try {
  119. (t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)),
  120. t.documentElement.appendChild(t.createElement("head")), t.documentElement.appendChild(t.createElement("body"));
  121. } catch (e) {
  122. }
  123. if (t) {
  124. var r = document.createRange();
  125. r.selectNodeContents(document.body);
  126. var n = r.createContextualFragment(e);
  127. t.body.appendChild(n);
  128. for (var a, o = {
  129. TITLE: !0,
  130. META: !0,
  131. LINK: !0,
  132. STYLE: !0,
  133. BASE: !0
  134. }, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
  135. return t;
  136. }
  137. } else console.error("没有找到要转成DOM的字符串");
  138. },
  139. loadMorePage: function () {
  140. if (curSite.pager) {
  141. let curPageEle = getElementByXpath(curSite.pager.nextLink);
  142. // console.log(curPageEle);
  143. var url = this.getFullHref(curPageEle);
  144. //console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
  145. if (url === '') return;
  146. if (curSite.pageUrl === url) return;// 不会重复加载相同的页面
  147. curSite.pageUrl = url;
  148. console.log(url);
  149. // 读取下一页的数据
  150. // curSite.pager.startFilter && curSite.pager.startFilter();
  151. GM_xmlhttpRequest({
  152. url: url,
  153. method: "GET",
  154. timeout: 5000,
  155. onload: function (response) {
  156. try {
  157. var newBody = ShowPager.createDocumentByString(response.responseText);
  158. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
  159. let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
  160. if (pageElems.length >= 0) {
  161. let addTo = "beforeend";
  162. // 插入新页面元素
  163. pageElems.forEach(function (one) {
  164. if (checkContent(one)) {
  165. toElement.insertAdjacentElement(addTo, one);
  166. }
  167. });
  168. // 替换待替换元素
  169. try {
  170. let oriE = getAllElements(curSite.pager.replaceE);
  171. let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
  172. if (oriE.length === repE.length) {
  173. for (var i = 0; i < oriE.length; i++) {
  174. oriE[i].outerHTML = repE[i].outerHTML;
  175. }
  176. }
  177. } catch (e) {
  178. console.log(e);
  179. }
  180. commentShowAll();
  181. }
  182. } catch (e) {
  183. console.log(e);
  184. }
  185. }
  186. });
  187. }
  188. },
  189. };
  190.  
  191.  
  192. function getElementByXpath(e, t, r) {
  193. r = r || document, t = t || r;
  194. try {
  195. return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  196. } catch (t) {
  197. return void console.error("无效的xpath");
  198. }
  199. }
  200.  
  201.  
  202. function getAllElements(e, t, r, n, o) {
  203. let getAllElementsByXpath = function (e, t, r) {
  204. return r = r || document, t = t || r, r.evaluate(e, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  205. }
  206.  
  207. var i, s = [];
  208. if (!e) return s;
  209. if (r = r || document, n = n || window, o = o || void 0, t = t || r, "string" == typeof e) i = 0 === e.search(/^css;/i) ? function getAllElementsByCSS(e, t) {
  210. return (t || document).querySelectorAll(e);
  211. }(e.slice(4), t) : getAllElementsByXpath(e, t, r); else {
  212. if (!(i = e(r, n, o))) return s;
  213. if (i.nodeType) return s[0] = i, s;
  214. }
  215. return function makeArray(e) {
  216. var t, r, n, o = [];
  217. if (e.pop) {
  218. for (t = 0, r = e.length; t < r; t++) (n = e[t]) && (n.nodeType ? o.push(n) : o = o.concat(makeArray(n)));
  219. return a()(o);
  220. }
  221. if (e.item) {
  222. for (t = e.length; t;) o[--t] = e[t];
  223. return o;
  224. }
  225. if (e.iterateNext) {
  226. for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
  227. return o;
  228. }
  229. }(i);
  230. }
  231.  
  232.  
  233. autoSign();
  234.  
  235. //自动签到
  236. function autoSign() {
  237. let checkinStr = 'smzdm_checkin';
  238. let now = new Date().getDate();
  239. // 首页,主动点击按钮
  240. if (/www\.smzdm\.com(\/|)$/.test(window.location.href)) {
  241. var btn = document.getElementsByClassName('J_punch')[0];
  242. if (/签到(得|领|拿)积分/.test(btn.text)) {
  243. btn.click();
  244. GM_setValue(checkinStr, now);
  245. }
  246. } else {
  247. let checkin = GM_getValue(checkinStr);
  248. if (checkin == now) {
  249. return;
  250. }
  251. // 非首页,内嵌脚本签到
  252. var url = 'https://zhiyou.smzdm.com/user/checkin/jsonp_checkin'
  253. var embed_script = document.createElement('script');
  254. embed_script.setAttribute('src', url);
  255. // 把script标签加入head,此时调用开始
  256. document.getElementsByTagName('head')[0].appendChild(embed_script);
  257. GM_setValue(checkinStr, now);
  258. }
  259. }
  260. })();

QingJ © 2025

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