Gamersky comments photo save

Gamersky comments photo save!

  1. // ==UserScript==
  2. // @name Gamersky comments photo save
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Gamersky comments photo save!
  6. // @author Andiest ziu
  7. // @match *.gamersky.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. if(location.href == 'https://www.gamersky.com/ent/qw/'){
  14. setInterval(function(){
  15. let now_time = (new Date()).valueOf();
  16. let url = 'https://db2.gamersky.com/LabelJsonpAjax.aspx?jsondata={"type":"updatenodelabel","isCache":false,"nodeId":"20113","isNodeId":"true","page":1}&_=' + now_time;
  17. fetch(encodeURI(url)).then(function(response) {
  18. return response.text();
  19. }).then(function(myJson) {
  20. var load_data = eval(myJson);
  21. document.getElementsByClassName("contentpaging")[0].innerHTML = load_data.body;
  22. });
  23. },2000);
  24. }
  25. function insertAfter(newElement,targetElement){
  26. var parent = targetElement.parentNode;
  27. // 如果最后的节点是目标元素,则直接添加
  28. if(parent.lastChild == targetElement){
  29. parent.appendChild(newElement)
  30. }else{
  31. //如果不是,则插入在目标元素的下一个兄弟节点 的前面
  32. parent.insertBefore(newElement,targetElement.nextSibling)
  33. }
  34. }
  35. var start_btn = document.createElement("a");
  36. start_btn.setAttribute("id","btn_start_haha");
  37. start_btn.setAttribute("href","javascript:;");
  38. start_btn.innerHTML = '开始';
  39.  
  40.  
  41. var hahadiv = document.createElement("div");
  42. hahadiv.setAttribute("id","hahadiv");
  43. var commentsCount = 0;
  44. var result = location.pathname.match(/\/(\d*)\./);
  45. var article_num = result[1];
  46. var handle_result = function(photo_list){
  47. let html = '';
  48. for(var haha in photo_list){
  49. if( String(photo_list[haha].img_url).indexOf("http") != -1 ) html += '<div><img src="' + photo_list[haha].img_url + '" title="' + photo_list[haha].title + '" width="100%"/></div>';
  50. }
  51. if( have_load == 0 ){
  52. document.getElementById("hahadiv").innerHTML = html + document.getElementById("hahadiv").innerHTML;
  53. }else{
  54. hahadiv.innerHTML += html;
  55. insertAfter(hahadiv, document.getElementById("SOHUCS"));
  56. }
  57. };
  58. var commit_list = localStorage.getItem('commit_list' + article_num);
  59. var init_count = 0;
  60. var total_photo_list = [];
  61. var photo_list = [];
  62. var pageIndex = 1;
  63. var max_comment_id = 0;
  64. var have_load = 1;
  65.  
  66. var settime_ajax = function(){
  67. setTimeout(function(){
  68. have_load = 0
  69. var now_time = (new Date()).valueOf();
  70. var request = {
  71. "articleId":article_num,
  72. "minPraisesCount":0,
  73. "repliesMaxCount":10,
  74. "pageIndex":1,
  75. "pageSize":10,
  76. "order":
  77. "createTimeDESC"
  78. };
  79. var url = encodeURI('https://cm.gamersky.com/appapi/GetArticleCommentWithClubStyle?request=' + JSON.stringify(request) + '&_=' + now_time);
  80. load_data(url);
  81. },1000);
  82. }
  83. if(commit_list != null ){
  84. commit_list = JSON.parse(commit_list);
  85. console.log(commit_list);
  86. init_count = commit_list.commentsCount;
  87. total_photo_list = commit_list.photo_list;
  88. max_comment_id = commit_list.max_comment_id;
  89. pageIndex = Math.ceil(init_count / 10);
  90. insertAfter(start_btn,document.getElementById("SOHUCS"));
  91. start_btn.onclick = function(){
  92. this.remove();
  93. handle_result(total_photo_list);
  94. settime_ajax();
  95. }
  96. }else{
  97. commit_list = {};
  98. insertAfter(start_btn,document.getElementById("SOHUCS"));
  99. let now_time = (new Date()).valueOf();
  100. let num = '18308087865817357132';
  101. let callback = 'jQuery' + num + '_' + now_time++;
  102.  
  103. var request = {
  104. "articleId":article_num,
  105. "minPraisesCount":0,
  106. "repliesMaxCount":10,
  107. "pageIndex":1,
  108. "pageSize":10,
  109. "order":
  110. "createTimeDESC"
  111. };
  112. let url = encodeURI('https://cm.gamersky.com/appapi/GetArticleCommentWithClubStyle?request=' + JSON.stringify(request) + '&_=' + now_time);
  113. start_btn.onclick = function(){
  114. this.remove();
  115. load_data(url);
  116. }
  117. }
  118.  
  119. var load_data = function(url){
  120. fetch(url).then(function(response) {
  121. return response.json();
  122. }).then(function(myJson) {
  123. photo_list = [];
  124. let list = myJson.result.comments;
  125. for(var l_i in list){
  126. if( typeof list[l_i].comment_id == 'undefined' ) continue;
  127. if( have_load == 0 && max_comment_id >= Number(list[l_i].comment_id)) continue;
  128. if( Number(list[l_i].comment_id) > max_comment_id) max_comment_id = Number(list[l_i].comment_id);
  129. let img_list = list[l_i].imageInfes;
  130. if(typeof img_list == 'undefined'){
  131. continue;
  132. }
  133. if(img_list.length == 0){
  134. continue;
  135. }
  136. for(var i in img_list){
  137. if(typeof img_list[i].origin != 'undefined'){
  138. var tmp = {
  139. "title":list[l_i].content,
  140. "img_url":img_list[i].origin
  141. };
  142. photo_list.push(tmp);
  143. total_photo_list.unshift(tmp);
  144. }
  145. }
  146. }
  147. //console.log(photo_list);
  148. // 加载下一页
  149. commentsCount = Number(myJson.result.commentsCount);
  150. if(photo_list.length > 0) {
  151. handle_result(photo_list);
  152. //保存数据
  153. commit_list.commentsCount = commentsCount;
  154. commit_list.photo_list = total_photo_list;
  155. commit_list.max_comment_id = max_comment_id;
  156. localStorage.setItem('commit_list' + article_num, JSON.stringify(commit_list));
  157. }
  158. //开始下一轮
  159. if( have_load == 1){
  160. let page_num = Math.ceil(commentsCount / 10);
  161.  
  162. //console.log(commentsCount,page_num,pageIndex);
  163. if(pageIndex <= page_num){
  164. pageIndex++;
  165. }else{
  166. pageIndex = 1;
  167. have_load = 0;
  168. }
  169. var now_time = (new Date()).valueOf();
  170. var request = {
  171. "articleId":article_num,
  172. "minPraisesCount":0,
  173. "repliesMaxCount":10,
  174. "pageIndex":pageIndex,
  175. "pageSize":10,
  176. "order":
  177. "createTimeDESC"
  178. };
  179. var url = encodeURI('https://cm.gamersky.com/appapi/GetArticleCommentWithClubStyle?request=' + JSON.stringify(request) + '&_=' + now_time);
  180. load_data(url);
  181. }else{
  182. settime_ajax();
  183. }
  184. });
  185. };
  186.  
  187.  
  188. })();

QingJ © 2025

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