Advertisement
Guest User

Untitled

a guest
Aug 6th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.04 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 if (window.location.hash == '#qtcontinuemega') {
  18. new Qt.OnlineVisitorMEGA();
  19. }
  20. else {
  21. var intf = new Qt.Interface();
  22. intf.run();
  23. }
  24. };
  25.  
  26. Qt.Popup = function(content, closebutton) {
  27. var that = this;
  28.  
  29. // credits: http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
  30. that.guid = function() {
  31. function s4() {
  32. return Math.floor((1 + Math.random()) * 0x10000)
  33. .toString(16)
  34. .substring(1);
  35. }
  36.  
  37. return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
  38. s4() + '-' + s4() + s4() + s4();
  39. };
  40.  
  41. that.id = that.guid();
  42.  
  43. that.css = {
  44. 'display' : 'none',
  45. 'height' : '130px',
  46. 'width' : '330px',
  47. 'position' : 'fixed',
  48. 'left' : '50%',
  49. 'margin-left' : '-150px',
  50. 'z-index' : '99999',
  51. 'background-color' : '#ccc',
  52. 'top' : '10px',
  53. 'padding' : '5px'
  54. };
  55.  
  56. that.closeButton = closebutton || false;
  57. that.content = content || "";
  58.  
  59. that.buildTemplate = function() {
  60. var popupOutter = document.createElement('div');
  61.  
  62. $(popupOutter).css(that.css);
  63. $(popupOutter).attr('id', that.id);
  64. $(popupOutter).addClass('qt-popup');
  65.  
  66. var popupHeader = document.createElement('div');
  67. $(popupHeader).addClass('qt-header');
  68.  
  69. if(that.closeButton) {
  70. var closeButton = document.createElement('a');
  71. $(closeButton).addClass('qt-close');
  72. $(closeButton).attr('qt-remove', that.id);
  73. $(closeButton).html('[X]');
  74. $(closeButton).attr('href', 'javascript:void(0)');
  75. $(popupHeader).append(closeButton);
  76. }
  77.  
  78. $(popupOutter).append(popupHeader);
  79. return popupOutter;
  80. }
  81.  
  82. that.show = function() {
  83. var popupHtml = that.buildTemplate();
  84. var popupBody = document.createElement('div');
  85.  
  86.  
  87.  
  88. $(popupBody).addClass('qt-body');
  89.  
  90. if(typeof that.content != typeof "") {
  91. that.content = that.content.outerHTML;
  92. }
  93.  
  94. console.log("content: "+that.content);
  95.  
  96. $(popupBody).html(that.content);
  97. $(popupHtml).append(popupBody);
  98.  
  99. $('body').append(popupHtml);
  100. $('#'+that.id).show();
  101.  
  102. Qt.Popup.refreshListener();
  103. }
  104.  
  105. that.getSelector = function() {
  106. return $('#'+that.id);
  107. }
  108. };
  109.  
  110. Qt.Popup.refreshListener = function() {
  111. $('.qt-close').off('click');
  112. $('.qt-close').on('click', function() {
  113. Qt.Popup.remove($(this).attr('qt-remove'));
  114. });
  115. }
  116.  
  117. Qt.Popup.remove = function (popupId) {
  118. $('#'+popupId).remove();
  119. };
  120.  
  121. Qt.Registry = {
  122. get : function() {
  123. this._init();
  124. return JSON.parse(localStorage.getItem("qts"));
  125. },
  126.  
  127. set: function(qtList) {
  128. localStorage.setItem("qts", JSON.stringify(qtList));
  129. },
  130.  
  131. reset: function() {
  132. localStorage.setItem("qts", JSON.stringify({}));
  133. },
  134.  
  135. _init: function() {
  136. if(localStorage.getItem("qts") === null) {
  137. Qt.Registry.reset();
  138. }
  139. }
  140. };
  141.  
  142. Qt.EnumeratorOnlinePage = {
  143. count : function() {
  144. return $('.online_prof a.female').length;
  145. },
  146. enumerate : function(callback) {
  147. $('.online_prof a.female').each(function() {
  148. if($(this).attr('href').indexOf('country') === -1) {
  149. callback( $(this).attr('href').replace('/',''), $(this) );
  150. }
  151. });
  152. }
  153. };
  154.  
  155. Qt.EnumeratorSearchPage = {
  156. count : function() {
  157. return $('.sResThumb').length;
  158. },
  159. enumerate : function(callback) {
  160. $('.sResThumb').each(function() {
  161. callback( $(this).attr('href').split('?')[0].replace('/','') , $(this) );
  162. });
  163. }
  164. };
  165.  
  166. Qt.MaybeHeadToNextPage = function() {
  167. var href = $('.cur_page').next().attr('href');
  168.  
  169. if (href) {
  170. var url = 'https://www.interpals.net' + href + '#qtcontinue'
  171. window.location.href = url;
  172. }
  173. };
  174.  
  175. Qt.OnlineVisitorMEGA = function() {
  176. var that = this;
  177.  
  178. that.popup = null;
  179.  
  180. if (window.location.hash !== '#qtcontinuemega') {
  181. var age1 = $('select[name=age1]')[0].value;
  182. var age2 = $('select[name=age2]')[0].value;
  183. var newSearch = window.location.search.replace(/age1=\d*/g, 'age1=' + age1).replace(/age2=\d*/g, 'age2=' + age1);
  184. var url = window.location.origin + window.location.pathname + newSearch + '&mega1=' + age1 + '&mega2=' + age2 + '#qtcontinuemega';
  185. console.log(url);
  186. window.location.href = url;
  187. return;
  188. }
  189.  
  190. that.buildInterface = function() {
  191. // Headline
  192. var popupHeadline = document.createElement('h1');
  193. $(popupHeadline).html('QtCrawler MEGA');
  194.  
  195. // Popup info
  196. var popupInfo = document.createElement('div');
  197. $(popupInfo).attr('id', 'qtpopupinfo');
  198. $(popupInfo).html('currently visiting qts... ');
  199.  
  200. // Pointer
  201. var popupContent = document.createElement('span');
  202. $(popupContent).attr('id', 'qtpopupcontent');
  203.  
  204. var pp = document.createElement('div');
  205. $(pp).append(popupHeadline);
  206. $(pp).append(popupInfo);
  207. $(pp).append(popupContent);
  208.  
  209. that.popup = new Qt.Popup(pp, true);
  210. };
  211.  
  212. that.runBot = function() {
  213. that.buildInterface();
  214.  
  215. // choose correct enumerator
  216. var qtEnumerator = Qt.EnumeratorOnlinePage.count() > Qt.EnumeratorSearchPage.count() ?
  217. Qt.EnumeratorOnlinePage : Qt.EnumeratorSearchPage;
  218.  
  219. var visitedQts = Qt.Registry.get();
  220. var unfilteredTotal = qtEnumerator.count();
  221. var doneVisited = 0;
  222. var currentCounter = 0;
  223.  
  224. that.popup.show();
  225.  
  226. qtEnumerator.enumerate(function(userName, element) {
  227.  
  228. if(typeof visitedQts[userName] !== typeof undefined) {
  229. return;
  230. }
  231.  
  232. currentCounter++;
  233.  
  234. $.get('//www.interpals.net/'+userName).done(function() {
  235. visitedQts[userName] = true;
  236. doneVisited ++;
  237. element.parent().parent().parent().css({'background-color': '#000'});
  238.  
  239. var percentDone = doneVisited / currentCounter * 100;
  240. $('#qtpopupinfo').html('visiting: '+doneVisited+' of '+currentCounter);
  241. $('#qtpopupcontent').html("<div style='width: "+percentDone+"%; background: #000; text-align: center; color: red'>&nbsp;</div>");
  242.  
  243. // finished
  244. if(doneVisited === currentCounter) {
  245. Qt.Registry.set(visitedQts);
  246.  
  247. var popupText = 'Finished visiting Qts ('+doneVisited+')';
  248.  
  249. if(unfilteredTotal - doneVisited !== 0) {
  250. popupText += '<br />';
  251. popupText += 'A total of '+(unfilteredTotal - currentCounter)+' QTs have been skipped ';
  252. popupText += 'because you already visited them before. <br />';
  253. popupText += '<a href="#" id="clearqtlist">Clear visited QT List</a> ';
  254. popupText += '(click requires no further confirmation)';
  255. }
  256.  
  257. // If on search page
  258. Qt.MaybeHeadToNextPageMega();
  259.  
  260. $('#qtpopupinfo').html(popupText);
  261. that.refreshListener();
  262. }
  263. });
  264. });
  265.  
  266. // all were already visited, head to next search page
  267. if (currentCounter == 0) {
  268. Qt.MaybeHeadToNextPageMega();
  269. }
  270. };
  271.  
  272. that.refreshListener = function() {
  273. $('#clearqtlist').off('click');
  274. $('#clearqtlist').on('click',function(ev) {
  275. ev.preventDefault();
  276. Qt.Registry.reset();
  277. $('#clearqtlist').replaceWith('<strong>Visited QTs resetted</strong>');
  278. ev.stopPropagation();
  279. });
  280. }
  281.  
  282. that.runBot();
  283. };
  284.  
  285. Qt.MaybeHeadToNextPageMega = function() {
  286. var href = $('.cur_page').next().attr('href');
  287.  
  288. if (href) {
  289. var offset = getParameterByName('offset');
  290. if (!offset) {
  291. offset = 20;
  292. }
  293. else {
  294. offset = parseInt(offset) + 20;
  295. }
  296. var url = window.location.href.replace(/offset=\d*/g, 'offset=' + offset);
  297. window.location.href = url;
  298. }
  299. else {
  300. var age1 = parseInt(getParameterByName('age1')), mega2 = parseInt(getParameterByName('mega2'));
  301. if (age1 < mega2) {
  302. var url = window.location.href.replace(/offset=\d*/g, 'offset=').replace(/age1=\d*/g, 'age1=' + (age1 + 1)).replace(/age2=\d*/g, 'age2=' + (age1 + 1));
  303. window.location.href = url;
  304. }
  305. }
  306. }
  307.  
  308. function getParameterByName(name, url) {
  309. if (!url) url = window.location.href;
  310. name = name.replace(/[\[\]]/g, "\\$&");
  311. var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
  312. results = regex.exec(url);
  313. if (!results) return null;
  314. if (!results[2]) return '';
  315. return decodeURIComponent(results[2].replace(/\+/g, " "));
  316. }
  317.  
  318. Qt.OnlineVisitor = function() {
  319. var that = this;
  320.  
  321. that.popup = null;
  322.  
  323. that.buildInterface = function() {
  324. // Headline
  325. var popupHeadline = document.createElement('h1');
  326. $(popupHeadline).html('QtCrawler');
  327.  
  328. // Popup info
  329. var popupInfo = document.createElement('div');
  330. $(popupInfo).attr('id', 'qtpopupinfo');
  331. $(popupInfo).html('currently visiting qts... ');
  332.  
  333. // Pointer
  334. var popupContent = document.createElement('span');
  335. $(popupContent).attr('id', 'qtpopupcontent');
  336.  
  337. var pp = document.createElement('div');
  338. $(pp).append(popupHeadline);
  339. $(pp).append(popupInfo);
  340. $(pp).append(popupContent);
  341.  
  342. that.popup = new Qt.Popup(pp, true);
  343. };
  344.  
  345. that.runBot = function() {
  346. that.buildInterface();
  347.  
  348. // choose correct enumerator
  349. var qtEnumerator = Qt.EnumeratorOnlinePage.count() > Qt.EnumeratorSearchPage.count() ?
  350. Qt.EnumeratorOnlinePage : Qt.EnumeratorSearchPage;
  351.  
  352. var visitedQts = Qt.Registry.get();
  353. var unfilteredTotal = qtEnumerator.count();
  354. var doneVisited = 0;
  355. var currentCounter = 0;
  356.  
  357. that.popup.show();
  358.  
  359. qtEnumerator.enumerate(function(userName, element) {
  360.  
  361. if(typeof visitedQts[userName] !== typeof undefined) {
  362. return;
  363. }
  364.  
  365. currentCounter++;
  366.  
  367. $.get('//www.interpals.net/'+userName).done(function() {
  368. visitedQts[userName] = true;
  369. doneVisited ++;
  370. element.parent().parent().parent().css({'background-color': '#000'});
  371.  
  372. var percentDone = doneVisited / currentCounter * 100;
  373. $('#qtpopupinfo').html('visiting: '+doneVisited+' of '+currentCounter);
  374. $('#qtpopupcontent').html("<div style='width: "+percentDone+"%; background: #000; text-align: center; color: red'>&nbsp;</div>");
  375.  
  376. // finished
  377. if(doneVisited === currentCounter) {
  378. Qt.Registry.set(visitedQts);
  379.  
  380. var popupText = 'Finished visiting Qts ('+doneVisited+')';
  381.  
  382. if(unfilteredTotal - doneVisited !== 0) {
  383. popupText += '<br />';
  384. popupText += 'A total of '+(unfilteredTotal - currentCounter)+' QTs have been skipped ';
  385. popupText += 'because you already visited them before. <br />';
  386. popupText += '<a href="#" id="clearqtlist">Clear visited QT List</a> ';
  387. popupText += '(click requires no further confirmation)';
  388. }
  389.  
  390. // If on search page
  391. Qt.MaybeHeadToNextPage();
  392.  
  393. $('#qtpopupinfo').html(popupText);
  394. that.refreshListener();
  395. }
  396. });
  397. });
  398.  
  399. // all were already visited, head to next search page
  400. if (currentCounter == 0) {
  401. Qt.MaybeHeadToNextPage();
  402. }
  403. };
  404.  
  405. that.refreshListener = function() {
  406. $('#clearqtlist').off('click');
  407. $('#clearqtlist').on('click',function(ev) {
  408. ev.preventDefault();
  409. Qt.Registry.reset();
  410. $('#clearqtlist').replaceWith('<strong>Visited QTs resetted</strong>');
  411. ev.stopPropagation();
  412. });
  413. }
  414.  
  415. that.runBot();
  416. };
  417.  
  418. Qt.Messenger = function () {
  419. var that = this;
  420.  
  421. that.popup = null;
  422.  
  423. that.buildInterface = function() {
  424. // Headline
  425. var popupHeadline = document.createElement('h1');
  426. $(popupHeadline).html('QtCrawler');
  427.  
  428. // Popup info
  429. var popupInfo = document.createElement('div');
  430. $(popupInfo).attr('id', 'messagepopup');
  431. $(popupInfo).html('Type in your message. Use {username}, {city} and {country} as placeholders. <br />');
  432.  
  433. // Pointer
  434. var popupContent = document.createElement('span');
  435. $(popupContent).attr('id', 'messagepopupcontent');
  436.  
  437. $(popupContent).html('<textarea style="width: 310px; height: 40px" id="messagetext"></textarea>')
  438. $(popupContent).append('<br /><a href="#" id="sendMessages">Message all</a>')
  439. var pp = document.createElement('div');
  440. $(pp).append(popupHeadline);
  441. $(pp).append(popupInfo);
  442. $(pp).append(popupContent);
  443.  
  444. that.popup = new Qt.Popup(pp, true);
  445. };
  446.  
  447. that.showPopup = function() {
  448. that.buildInterface();
  449. that.popup.show();
  450. $('#sendMessages').off('click');
  451. $('#sendMessages').on('click', function() {
  452. that.runBot();
  453. });
  454. }
  455.  
  456. that.runBot = function() {
  457. var visitedQts = Qt.Registry.get();
  458. var unfilteredTotal = $('.online_prof a.female').length;
  459. var doneVisited = 0;
  460. var currentCounter = 0;
  461.  
  462. that.popup.show();
  463.  
  464. $('.online_prof a.female').each(function() {
  465.  
  466.  
  467. if($(this).attr('href').indexOf('country') === -1) {
  468. var userName = $(this).attr('href').replace('/','');
  469. var el = $(this);
  470.  
  471. $.ajax('/'+userName).done(function(html) {
  472.  
  473. // COLLECT DATA
  474. var visitedSite = document.createElement('div');
  475. $(visitedSite).html(html);
  476. var pmLink = $(visitedSite).find('#prof-action-links a').first().attr('href');
  477. var pmCity = $(visitedSite).find('.profDataTopData div a').first().text().trim();
  478. var pmCountry = $(visitedSite).find('.profDataTopData div a').first().next().text().trim();
  479.  
  480. // Call PM link
  481. $.get('//www.interpals.net/'+pmLink).done(function(response, _, header) {
  482. console.log("CALL PM LINK: "+'//www.interpals.net/'+pmLink);
  483. // found thread
  484. var thread = document.createElement('div');
  485. $(thread).html(response);
  486. if(typeof $(thread).find('.pm_thread').first().attr('id') !== typeof undefined) {
  487.  
  488. if($(thread).find(".msg_user").length > 0) {
  489. console.log("cant contact user");
  490. // user does not like being contacted
  491. el.parent().parent().parent().css({'background-color': '#0f0'});
  492. } else {
  493. var threadUrl = header.getResponseHeader("TM-finalURLdhdg");
  494. var chunks = $(thread).find('.pm_thread').first().attr('id').split('thread_');
  495. console.log(chunks);
  496. if(chunks.length === 2) {
  497. var thradId = chunks[1];
  498. var sMessage = $('#messagetext').val();
  499. sMessage = sMessage.replace("{username}", userName);
  500. sMessage = sMessage.replace("{city}", pmCity);
  501. sMessage = sMessage.replace("{country}", pmCountry);
  502. $.ajax({type:"POST",url:"https://www.interpals.net/pm.php",data:{action:"send_message",thread:thradId,message: sMessage},dataType:"json"}).done(function() {
  503. el.parent().parent().parent().css({'background-color': '#000'});
  504. });
  505. } else {
  506. console.log("cant contact user (2)");
  507. el.parent().parent().parent().css({'background-color': '#f00'});
  508. }
  509. }
  510. }
  511. });
  512. });
  513. }
  514. });
  515. };
  516.  
  517. that.showPopup();
  518. }
  519.  
  520. Qt.Interface = function() {
  521. var that = this;
  522.  
  523. that.build = function() {
  524. // Create container
  525. var fLinkAuto = document.createElement('div');
  526. $(fLinkAuto).addClass('filterLinks');
  527. $(fLinkAuto).css({
  528. 'height' : 'auto'
  529. });
  530.  
  531. // Create headline for container
  532. var fLinkHeadline = document.createElement('h1');
  533. $(fLinkHeadline).html('Auto:');
  534. $(fLinkHeadline).css({
  535. 'margin' : '5px 0 5px 25px',
  536. 'float' : 'left'
  537. });
  538.  
  539. // Create link "view all"
  540. var fLinkViewAll = document.createElement('a');
  541. $(fLinkViewAll).attr('href', '#');
  542. $(fLinkViewAll).attr('id', 'autoView');
  543. $(fLinkViewAll).html('view all');
  544.  
  545. // Create link "view all MEGA"
  546. var fLinkViewAllMEGA = document.createElement('a');
  547. $(fLinkViewAllMEGA).attr('href', '#');
  548. $(fLinkViewAllMEGA).attr('id', 'autoViewMEGA');
  549. $(fLinkViewAllMEGA).html('view all MEGA');
  550.  
  551. // Create link "view all"
  552. var fLinkMessage = document.createElement('a');
  553. $(fLinkMessage).attr('href', '#');
  554. $(fLinkMessage).attr('id', 'autoMessage');
  555. $(fLinkMessage).html('message all');
  556.  
  557. // Append link to box
  558. $(fLinkAuto).append(fLinkHeadline);
  559. $(fLinkAuto).append(fLinkViewAll);
  560. $(fLinkAuto).append(fLinkMessage);
  561. $(fLinkAuto).append(fLinkViewAllMEGA);
  562.  
  563. // Add box to headmenu
  564. $('form[name="onlineForm"]').append(fLinkAuto);
  565.  
  566. // Add to search box on search page
  567. $('form[name="sCForm"]').append(fLinkAuto);
  568. };
  569.  
  570. that.run = function() {
  571. that.build();
  572.  
  573. $('#autoView').off('click');
  574. $('#autoView').on('click', function () {
  575. new Qt.OnlineVisitor();
  576. });
  577.  
  578. $('#autoMessage').off('click');
  579. $('#autoMessage').on('click', function () {
  580. new Qt.Messenger();
  581. });
  582.  
  583. $('#autoViewMEGA').off('click');
  584. $('#autoViewMEGA').on('click', function () {
  585. new Qt.OnlineVisitorMEGA();
  586. });
  587. }
  588. };
  589.  
  590. $(document).ready(function() {
  591. new Qt();
  592. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement