Guest User

qtcrawler

a guest
May 16th, 2017
8,414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.25 KB | None | 0 0
  1. // ==UserScript==
  2. // @name QtCrawler
  3. // @namespace com.yellowfever.qtcrawler
  4. // @version 0.3.2
  5. // @description Taiwan is not a part of China
  6. // @author (You)
  7. // @match http://www.interpals.net/*
  8. // @match https://www.interpals.net/*
  9. // @include http://www.interpals.net/*
  10. // @include https://www.interpals.net/*
  11. // @grant none
  12. // ==/UserScript==
  13. var Qt = function() {
  14. if (window.location.hash == '#qtcontinue') {
  15. new Qt.OnlineVisitor();
  16. }
  17. else {
  18. var intf = new Qt.Interface();
  19. intf.run();
  20. }
  21. };
  22.  
  23. Qt.Popup = function(content, closebutton) {
  24. var that = this;
  25.  
  26. // credits: http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
  27. that.guid = function() {
  28. function s4() {
  29. return Math.floor((1 + Math.random()) * 0x10000)
  30. .toString(16)
  31. .substring(1);
  32. }
  33.  
  34. return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  35. s4() + '-' + s4() + s4() + s4();
  36. };
  37.  
  38. that.id = that.guid();
  39.  
  40. that.css = {
  41. 'display' : 'none',
  42. 'height' : '130px',
  43. 'width' : '330px',
  44. 'position' : 'fixed',
  45. 'left' : '50%',
  46. 'margin-left' : '-150px',
  47. 'z-index' : '99999',
  48. 'background-color' : '#ccc',
  49. 'top' : '10px',
  50. 'padding' : '5px'
  51. };
  52.  
  53. that.closeButton = closebutton || false;
  54. that.content = content || "";
  55.  
  56. that.buildTemplate = function() {
  57. var popupOutter = document.createElement('div');
  58.  
  59. $(popupOutter).css(that.css);
  60. $(popupOutter).attr('id', that.id);
  61. $(popupOutter).addClass('qt-popup');
  62.  
  63. var popupHeader = document.createElement('div');
  64. $(popupHeader).addClass('qt-header');
  65.  
  66. if(that.closeButton) {
  67. var closeButton = document.createElement('a');
  68. $(closeButton).addClass('qt-close');
  69. $(closeButton).attr('qt-remove', that.id);
  70. $(closeButton).html('[X]');
  71. $(closeButton).attr('href', 'javascript:void(0)');
  72. $(popupHeader).append(closeButton);
  73. }
  74.  
  75. $(popupOutter).append(popupHeader);
  76. return popupOutter;
  77. }
  78.  
  79. that.show = function() {
  80. var popupHtml = that.buildTemplate();
  81. var popupBody = document.createElement('div');
  82.  
  83.  
  84.  
  85. $(popupBody).addClass('qt-body');
  86.  
  87. if(typeof that.content != typeof "") {
  88. that.content = that.content.outerHTML;
  89. }
  90.  
  91. console.log("content: "+that.content);
  92.  
  93. $(popupBody).html(that.content);
  94. $(popupHtml).append(popupBody);
  95.  
  96. $('body').append(popupHtml);
  97. $('#'+that.id).show();
  98.  
  99. Qt.Popup.refreshListener();
  100. }
  101.  
  102. that.getSelector = function() {
  103. return $('#'+that.id);
  104. }
  105. };
  106.  
  107. Qt.Popup.refreshListener = function() {
  108. $('.qt-close').off('click');
  109. $('.qt-close').on('click', function() {
  110. Qt.Popup.remove($(this).attr('qt-remove'));
  111. });
  112. }
  113.  
  114. Qt.Popup.remove = function (popupId) {
  115. $('#'+popupId).remove();
  116. };
  117.  
  118. Qt.Registry = {
  119. get : function() {
  120. this._init();
  121. return JSON.parse(localStorage.getItem("qts"));
  122. },
  123.  
  124. set: function(qtList) {
  125. localStorage.setItem("qts", JSON.stringify(qtList));
  126. },
  127.  
  128. reset: function() {
  129. localStorage.setItem("qts", JSON.stringify({}));
  130. },
  131.  
  132. _init: function() {
  133. if(localStorage.getItem("qts") === null) {
  134. Qt.Registry.reset();
  135. }
  136. }
  137. };
  138.  
  139. Qt.EnumeratorOnlinePage = {
  140. count : function() {
  141. return $('.online_prof a').length;
  142. },
  143. enumerate : function(callback) {
  144. $('.online_prof a').each(function() {
  145. if($(this).attr('href').indexOf('country') === -1) {
  146. callback( $(this).attr('href').replace('/',''), $(this) );
  147. }
  148. });
  149. }
  150. };
  151.  
  152. Qt.EnumeratorSearchPage = {
  153. count : function() {
  154. return $('.sResThumb').length;
  155. },
  156. enumerate : function(callback) {
  157. $('.sResThumb').each(function() {
  158. callback( $(this).attr('href').split('?')[0].replace('/','') , $(this) );
  159. });
  160. }
  161. };
  162.  
  163. Qt.MaybeHeadToNextPage = function() {
  164. var href = $('.cur_page').next().attr('href');
  165.  
  166. if (href) {
  167. var url = 'https://www.interpals.net' + href + '#qtcontinue'
  168. window.location.href = url;
  169. }
  170. };
  171.  
  172. Qt.OnlineVisitor = function() {
  173. var that = this;
  174.  
  175. that.popup = null;
  176.  
  177. that.buildInterface = function() {
  178. // Headline
  179. var popupHeadline = document.createElement('h1');
  180. $(popupHeadline).html('QtCrawler');
  181.  
  182. // Popup info
  183. var popupInfo = document.createElement('div');
  184. $(popupInfo).attr('id', 'qtpopupinfo');
  185. $(popupInfo).html('currently visiting qts... ');
  186.  
  187. // Pointer
  188. var popupContent = document.createElement('span');
  189. $(popupContent).attr('id', 'qtpopupcontent');
  190.  
  191. var pp = document.createElement('div');
  192. $(pp).append(popupHeadline);
  193. $(pp).append(popupInfo);
  194. $(pp).append(popupContent);
  195.  
  196. that.popup = new Qt.Popup(pp, true);
  197. };
  198.  
  199. that.runBot = function() {
  200. that.buildInterface();
  201.  
  202. // choose correct enumerator
  203. var qtEnumerator = Qt.EnumeratorOnlinePage.count() > Qt.EnumeratorSearchPage.count() ?
  204. Qt.EnumeratorOnlinePage : Qt.EnumeratorSearchPage;
  205.  
  206. var visitedQts = Qt.Registry.get();
  207. var unfilteredTotal = qtEnumerator.count();
  208. var doneVisited = 0;
  209. var currentCounter = 0;
  210.  
  211. that.popup.show();
  212.  
  213. qtEnumerator.enumerate(function(userName, element) {
  214.  
  215. if(typeof visitedQts[userName] !== typeof undefined) {
  216. return;
  217. }
  218.  
  219. currentCounter++;
  220.  
  221. $.get('//www.interpals.net/'+userName).done(function() {
  222. visitedQts[userName] = true;
  223. doneVisited ++;
  224. element.parent().parent().parent().css({'background-color': '#000'});
  225.  
  226. var percentDone = doneVisited / currentCounter * 100;
  227. $('#qtpopupinfo').html('visiting: '+doneVisited+' of '+currentCounter);
  228. $('#qtpopupcontent').html("<div style='width: "+percentDone+"%; background: #000; text-align: center; color: red'>&nbsp;</div>");
  229.  
  230. // finished
  231. if(doneVisited === currentCounter) {
  232. Qt.Registry.set(visitedQts);
  233.  
  234. var popupText = 'Finished visiting Qts ('+doneVisited+')';
  235.  
  236. if(unfilteredTotal - doneVisited !== 0) {
  237. popupText += '<br />';
  238. popupText += 'A total of '+(unfilteredTotal - currentCounter)+' QTs have been skipped ';
  239. popupText += 'because you already visited them before. <br />';
  240. popupText += '<a href="#" id="clearqtlist">Clear visited QT List</a> ';
  241. popupText += '(click requires no further confirmation)';
  242. }
  243.  
  244. // If on search page
  245. Qt.MaybeHeadToNextPage();
  246.  
  247. $('#qtpopupinfo').html(popupText);
  248. that.refreshListener();
  249. }
  250. });
  251. });
  252.  
  253. // all were already visited, head to next search page
  254. if (currentCounter == 0) {
  255. Qt.MaybeHeadToNextPage();
  256. }
  257. };
  258.  
  259. that.refreshListener = function() {
  260. $('#clearqtlist').off('click');
  261. $('#clearqtlist').on('click',function(ev) {
  262. ev.preventDefault();
  263. Qt.Registry.reset();
  264. $('#clearqtlist').replaceWith('<strong>Visited QTs resetted</strong>');
  265. ev.stopPropagation();
  266. });
  267. }
  268.  
  269. that.runBot();
  270. };
  271.  
  272. Qt.Messenger = function () {
  273. var that = this;
  274.  
  275. that.popup = null;
  276.  
  277. that.buildInterface = function() {
  278. // Headline
  279. var popupHeadline = document.createElement('h1');
  280. $(popupHeadline).html('QtCrawler');
  281.  
  282. // Popup info
  283. var popupInfo = document.createElement('div');
  284. $(popupInfo).attr('id', 'messagepopup');
  285. $(popupInfo).html('Type in your message. Use {username}, {city} and {country} as placeholders. <br />');
  286.  
  287. // Pointer
  288. var popupContent = document.createElement('span');
  289. $(popupContent).attr('id', 'messagepopupcontent');
  290.  
  291. $(popupContent).html('<textarea style="width: 310px; height: 40px" id="messagetext"></textarea>')
  292. $(popupContent).append('<br /><a href="#" id="sendMessages">Message all</a>')
  293. var pp = document.createElement('div');
  294. $(pp).append(popupHeadline);
  295. $(pp).append(popupInfo);
  296. $(pp).append(popupContent);
  297.  
  298. that.popup = new Qt.Popup(pp, true);
  299. };
  300.  
  301. that.showPopup = function() {
  302. that.buildInterface();
  303. that.popup.show();
  304. $('#sendMessages').off('click');
  305. $('#sendMessages').on('click', function() {
  306. that.runBot();
  307. });
  308. }
  309.  
  310. that.runBot = function() {
  311. var visitedQts = Qt.Registry.get();
  312. var unfilteredTotal = $('.online_prof a').length;
  313. var doneVisited = 0;
  314. var currentCounter = 0;
  315.  
  316. that.popup.show();
  317.  
  318. $('.online_prof a').each(function() {
  319.  
  320.  
  321. if($(this).attr('href').indexOf('country') === -1) {
  322. var userName = $(this).attr('href').replace('/','');
  323. var el = $(this);
  324.  
  325. $.ajax('/'+userName).done(function(html) {
  326.  
  327. // COLLECT DATA
  328. var visitedSite = document.createElement('div');
  329. $(visitedSite).html(html);
  330. var pmLink = $(visitedSite).find('#prof-action-links a').first().attr('href');
  331. var pmCity = $(visitedSite).find('.profDataTopData div a').first().text().trim();
  332. var pmCountry = $(visitedSite).find('.profDataTopData div a').first().next().text().trim();
  333.  
  334. // Call PM link
  335. $.get('//www.interpals.net/'+pmLink).done(function(response, _, header) {
  336. console.log("CALL PM LINK: "+'//www.interpals.net/'+pmLink);
  337. // found thread
  338. var thread = document.createElement('div');
  339. $(thread).html(response);
  340. if(typeof $(thread).find('.pm_thread').first().attr('id') !== typeof undefined) {
  341.  
  342. if($(thread).find(".msg_user").length > 0) {
  343. console.log("cant contact user");
  344. // user does not like being contacted
  345. el.parent().parent().parent().css({'background-color': '#0f0'});
  346. } else {
  347. var threadUrl = header.getResponseHeader("TM-finalURLdhdg");
  348. var chunks = $(thread).find('.pm_thread').first().attr('id').split('thread_');
  349. console.log(chunks);
  350. if(chunks.length === 2) {
  351. var thradId = chunks[1];
  352. var sMessage = $('#messagetext').val();
  353. sMessage = sMessage.replace("{username}", userName);
  354. sMessage = sMessage.replace("{city}", pmCity);
  355. sMessage = sMessage.replace("{country}", pmCountry);
  356. $.ajax({type:"POST",url:"https://www.interpals.net/pm.php",data:{action:"send_message",thread:thradId,message: sMessage},dataType:"json"}).done(function() {
  357. el.parent().parent().parent().css({'background-color': '#000'});
  358. });
  359. } else {
  360. console.log("cant contact user (2)");
  361. el.parent().parent().parent().css({'background-color': '#f00'});
  362. }
  363. }
  364. }
  365. });
  366. });
  367. }
  368. });
  369. };
  370.  
  371. that.showPopup();
  372. }
  373.  
  374. Qt.Interface = function() {
  375. var that = this;
  376.  
  377. that.build = function() {
  378. // Create container
  379. var fLinkAuto = document.createElement('div');
  380. $(fLinkAuto).addClass('filterLinks');
  381.  
  382. // Create headline for container
  383. var fLinkHeadline = document.createElement('h1');
  384. $(fLinkHeadline).html('Auto:');
  385. $(fLinkHeadline).css({
  386. 'margin' : '5px 0 5px 25px',
  387. 'float' : 'left'
  388. });
  389.  
  390. // Create link "view all"
  391. var fLinkViewAll = document.createElement('a');
  392. $(fLinkViewAll).attr('href', '#');
  393. $(fLinkViewAll).attr('id', 'autoView');
  394. $(fLinkViewAll).html('view all');
  395.  
  396. // Create link "view all"
  397. var fLinkMessage = document.createElement('a');
  398. $(fLinkMessage).attr('href', '#');
  399. $(fLinkMessage).attr('id', 'autoMessage');
  400. $(fLinkMessage).html('message all');
  401.  
  402. // Append link to box
  403. $(fLinkAuto).append(fLinkHeadline);
  404. $(fLinkAuto).append(fLinkViewAll);
  405. $(fLinkAuto).append(fLinkMessage);
  406.  
  407. // Add box to headmenu
  408. $('form[name="onlineForm"]').append(fLinkAuto);
  409.  
  410. // Add to search box on search page
  411. $('form[name="sCForm"]').append(fLinkAuto);
  412. };
  413.  
  414. that.run = function() {
  415. that.build();
  416.  
  417. $('#autoView').off('click');
  418. $('#autoView').on('click', function () {
  419. new Qt.OnlineVisitor();
  420. });
  421.  
  422. $('#autoMessage').off('click');
  423. $('#autoMessage').on('click', function () {
  424. new Qt.Messenger();
  425. });
  426. }
  427. };
  428.  
  429. $(document).ready(function() {
  430. new Qt();
  431. })
Add Comment
Please, Sign In to add comment