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

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

目前为 2020-11-20 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 什么值得买SMZDM - 自动签到、翻页
  3. // @version 0.8
  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. return span.textContent.indexOf('此用户') == -1;
  99. }
  100.  
  101. var ShowPager = { // 修改自 https://gf.qytechs.cn/scripts/14178
  102. getFullHref: function (e) {
  103. if (e == null) return '';
  104. "string" != typeof e && (e = e.getAttribute("href"));
  105. var t = this.getFullHref.a;
  106. return t || (this.getFullHref.a = t = document.createElement("a")), t.href = e, t.href;
  107. },
  108. createDocumentByString: function (e) {
  109. if (e) {
  110. if ("HTML" !== document.documentElement.nodeName) return (new DOMParser).parseFromString(e, "application/xhtml+xml");
  111. var t;
  112. try {
  113. t = (new DOMParser).parseFromString(e, "text/html");
  114. } catch (e) {
  115. }
  116. if (t) return t;
  117. if (document.implementation.createHTMLDocument) t = document.implementation.createHTMLDocument("ADocument"); else try {
  118. (t = document.cloneNode(!1)).appendChild(t.importNode(document.documentElement, !1)),
  119. t.documentElement.appendChild(t.createElement("head")), t.documentElement.appendChild(t.createElement("body"));
  120. } catch (e) {
  121. }
  122. if (t) {
  123. var r = document.createRange();
  124. r.selectNodeContents(document.body);
  125. var n = r.createContextualFragment(e);
  126. t.body.appendChild(n);
  127. for (var a, o = {
  128. TITLE: !0,
  129. META: !0,
  130. LINK: !0,
  131. STYLE: !0,
  132. BASE: !0
  133. }, i = t.body, s = i.childNodes, c = s.length - 1; c >= 0; c--) o[(a = s[c]).nodeName] && i.removeChild(a);
  134. return t;
  135. }
  136. } else console.error("没有找到要转成DOM的字符串");
  137. },
  138. loadMorePage: function () {
  139. if (curSite.pager) {
  140. let curPageEle = getElementByXpath(curSite.pager.nextLink);
  141. // console.log(curPageEle);
  142. var url = this.getFullHref(curPageEle);
  143. //console.log(`${url} ${curPageEle} ${curSite.pageUrl}`);
  144. if (url === '') return;
  145. if (curSite.pageUrl === url) return;// 不会重复加载相同的页面
  146. curSite.pageUrl = url;
  147. console.log(url);
  148. // 读取下一页的数据
  149. // curSite.pager.startFilter && curSite.pager.startFilter();
  150. GM_xmlhttpRequest({
  151. url: url,
  152. method: "GET",
  153. timeout: 5000,
  154. onload: function (response) {
  155. try {
  156. var newBody = ShowPager.createDocumentByString(response.responseText);
  157. let pageElems = getAllElements(curSite.pager.pageElement, newBody, newBody);
  158. let toElement = getAllElements(curSite.pager.HT_insert[0])[0];
  159. if (pageElems.length >= 0) {
  160. let addTo = "beforeend";
  161. // 插入新页面元素
  162. pageElems.forEach(function (one) {
  163. if (checkContent(one)) {
  164. toElement.insertAdjacentElement(addTo, one);
  165. }
  166. });
  167. // 替换待替换元素
  168. try {
  169. let oriE = getAllElements(curSite.pager.replaceE);
  170. let repE = getAllElements(curSite.pager.replaceE, newBody, newBody);
  171. if (oriE.length === repE.length) {
  172. for (var i = 0; i < oriE.length; i++) {
  173. oriE[i].outerHTML = repE[i].outerHTML;
  174. }
  175. }
  176. } catch (e) {
  177. console.log(e);
  178. }
  179. commentShowAll();
  180. }
  181. } catch (e) {
  182. console.log(e);
  183. }
  184. }
  185. });
  186. }
  187. },
  188. };
  189.  
  190.  
  191. function getElementByXpath(e, t, r) {
  192. r = r || document, t = t || r;
  193. try {
  194. return r.evaluate(e, t, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  195. } catch (t) {
  196. return void console.error("无效的xpath");
  197. }
  198. }
  199.  
  200.  
  201. function getAllElements(e, t, r, n, o) {
  202. let getAllElementsByXpath = function (e, t, r) {
  203. return r = r || document, t = t || r, r.evaluate(e, t, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  204. }
  205.  
  206. var i, s = [];
  207. if (!e) return s;
  208. 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) {
  209. return (t || document).querySelectorAll(e);
  210. }(e.slice(4), t) : getAllElementsByXpath(e, t, r); else {
  211. if (!(i = e(r, n, o))) return s;
  212. if (i.nodeType) return s[0] = i, s;
  213. }
  214. return function makeArray(e) {
  215. var t, r, n, o = [];
  216. if (e.pop) {
  217. for (t = 0, r = e.length; t < r; t++) (n = e[t]) && (n.nodeType ? o.push(n) : o = o.concat(makeArray(n)));
  218. return a()(o);
  219. }
  220. if (e.item) {
  221. for (t = e.length; t;) o[--t] = e[t];
  222. return o;
  223. }
  224. if (e.iterateNext) {
  225. for (t = e.snapshotLength; t;) o[--t] = e.snapshotItem(t);
  226. return o;
  227. }
  228. }(i);
  229. }
  230.  
  231.  
  232. autoSign();
  233.  
  234. //自动签到
  235. function autoSign() {
  236. let checkinStr = 'smzdm_checkin';
  237. let now = new Date().getDate();
  238. // 首页,主动点击按钮
  239. if (/www\.smzdm\.com(\/|)$/.test(window.location.href)) {
  240. var btn = document.getElementsByClassName('J_punch')[0];
  241. if (/签到(得|领|拿)积分/.test(btn.text)) {
  242. btn.click();
  243. GM_setValue(checkinStr, now);
  244. }
  245. } else {
  246. let checkin = GM_getValue(checkinStr);
  247. if (checkin == now) {
  248. return;
  249. }
  250. // 非首页,内嵌脚本签到
  251. var url = 'https://zhiyou.smzdm.com/user/checkin/jsonp_checkin'
  252. var embed_script = document.createElement('script');
  253. embed_script.setAttribute('src', url);
  254. // 把script标签加入head,此时调用开始
  255. document.getElementsByTagName('head')[0].appendChild(embed_script);
  256. GM_setValue(checkinStr, now);
  257. }
  258. }
  259. })();

QingJ © 2025

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